diff --git a/erp5/util/benchmark/performance_tester.py b/erp5/util/benchmark/performance_tester.py index f0dd753ec22e4e0232fa6f6a6cf7d2b7952a01d2..3faa1c051afc55f5f7b4aea91556082394381a07 100755 --- a/erp5/util/benchmark/performance_tester.py +++ b/erp5/util/benchmark/performance_tester.py @@ -108,8 +108,15 @@ class PerformanceTester(object): type=ArgumentType.checkIntValueWrapper(minimum=1), default=-1, metavar='N', - help='Repeat the benchmark suite N times ' - '(default: infinite)') + help='Repeat the benchmark suite N times for a given ' + 'number of users (default: infinite)') + + parser.add_argument('--repeat-range', + type=ArgumentType.checkIntValueWrapper(minimum=1), + default=-1, + metavar='N', + help='Repeat the benchmark suite N times for the whole ' + 'range of users (default: infinite)') parser.add_argument('--user-index', type=int, @@ -158,6 +165,10 @@ class PerformanceTester(object): min(len(namespace.benchmark_suite_list) * namespace.repeat, namespace.max_error_number) + if isinstance(namespace.users, tuple) and namespace.repeat == -1: + raise argparse.ArgumentTypeError("Repeat cannot be infinite for a " + "range of users") + namespace.benchmark_suite_name_list = namespace.benchmark_suite_list namespace.benchmark_suite_list = object_benchmark_suite_list @@ -205,7 +216,7 @@ class PerformanceTester(object): ERP5BenchmarkResult.closeResultDocument(self._argument_namespace.erp5_publish_url, error_message_set) - def _run_constant(self, nb_users): + def _run_constant(self, nb_users, current_repeat_range=None): process_list = [] exit_msg_queue = multiprocessing.Queue(nb_users) @@ -214,7 +225,8 @@ class PerformanceTester(object): for user_index in range(nb_users): process = BenchmarkProcess(exit_msg_queue, result_class, self._argument_namespace, nb_users, - user_index) + user_index, + current_repeat_range) process_list.append(process) @@ -269,14 +281,31 @@ class PerformanceTester(object): self.preRun() if isinstance(self._argument_namespace.users, tuple): - nb_users, max_users = self._argument_namespace.users - while True: - error_message_set, exit_status = self._run_constant(nb_users) - if exit_status != 0 or nb_users == max_users: - break - - nb_users = min(nb_users + self._argument_namespace.users_range_increment, - max_users) + min_user_number, max_user_number = self._argument_namespace.users + repeat_counter = 0 + exit_with_error = False + + while (repeat_counter != self._argument_namespace.repeat_range and + not exit_with_error): + current_user_number = min_user_number + + while True: + error_message_set, exit_status = \ + self._run_constant(current_user_number, repeat_counter) + + if exit_status != 0: + exit_with_error = True + break + elif current_user_number == max_user_number: + break + + current_user_number = \ + min((current_user_number + + self._argument_namespace.users_range_increment), + max_user_number) + + repeat_counter += 1 + else: error_message_set, exit_status = self._run_constant( self._argument_namespace.users) diff --git a/erp5/util/benchmark/process.py b/erp5/util/benchmark/process.py index 193337c0558f732455c624a78649152551f1f1c3..9a8bb354fe861fce036d01ec1e1c7fd2d913a421 100644 --- a/erp5/util/benchmark/process.py +++ b/erp5/util/benchmark/process.py @@ -43,12 +43,14 @@ RESULT_NUMBER_BEFORE_FLUSHING = 100 class BenchmarkProcess(multiprocessing.Process): def __init__(self, exit_msg_queue, result_klass, argument_namespace, - nb_users, user_index, *args, **kwargs): + nb_users, user_index, current_repeat_range, *args, **kwargs): self._exit_msg_queue = exit_msg_queue self._result_klass = result_klass self._argument_namespace = argument_namespace self._nb_users = nb_users self._user_index = user_index + self._current_repeat_range = current_repeat_range + self._base_url, self._erp5_site_id = argument_namespace.url try: @@ -137,7 +139,8 @@ class BenchmarkProcess(multiprocessing.Process): def run(self): result_instance = self._result_klass(self._argument_namespace, self._nb_users, - self._user_index) + self._user_index, + self._current_repeat_range) self._logger = result_instance.logger diff --git a/erp5/util/benchmark/result.py b/erp5/util/benchmark/result.py index 49e20c316cb6b49052fc6cc6525937dbf25ee960..f3399e77d1ba03c1d7b2ff808bc98a2affa6dd66 100644 --- a/erp5/util/benchmark/result.py +++ b/erp5/util/benchmark/result.py @@ -81,10 +81,13 @@ import abc class BenchmarkResult(object): __metaclass__ = abc.ABCMeta - def __init__(self, argument_namespace, nb_users, user_index): + def __init__(self, argument_namespace, nb_users, user_index, + current_repeat_range): self._argument_namespace = argument_namespace self._nb_users = nb_users self._user_index = user_index + self._current_repeat_range = current_repeat_range + self._logger = None self._label_list = None @@ -229,11 +232,18 @@ class CSVBenchmarkResult(BenchmarkResult): self.log_file = open(self._log_filename_path, 'w') def _getFilenamePrefix(self): - max_nb_users = isinstance(self._argument_namespace.users, int) and \ - self._argument_namespace.users or self._argument_namespace.users[1] + if isinstance(self._argument_namespace.users, int): + max_nb_users = self._argument_namespace.users + suffix = '' + else: + max_nb_users = self._argument_namespace.users[1] + suffix = '-rrepeat%%0%dd' % len(str(self._argument_namespace.repeat_range)) + + suffix = suffix % self._current_repeat_range - fmt = "%%s-%%drepeat-%%0%ddusers-process%%0%dd" % \ - (len(str(max_nb_users)), len(str(self._nb_users))) + fmt = "%%s-%%drepeat-%%0%ddusers-process%%0%dd%s" % \ + (len(str(max_nb_users)), len(str(self._nb_users)), + suffix) return fmt % (self._argument_namespace.filename_prefix, self._argument_namespace.repeat,