Commit c87cf495 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Allow to specify the repeat for a range of users

parent 35eb6972
...@@ -108,8 +108,15 @@ class PerformanceTester(object): ...@@ -108,8 +108,15 @@ class PerformanceTester(object):
type=ArgumentType.checkIntValueWrapper(minimum=1), type=ArgumentType.checkIntValueWrapper(minimum=1),
default=-1, default=-1,
metavar='N', metavar='N',
help='Repeat the benchmark suite N times ' help='Repeat the benchmark suite N times for a given '
'(default: infinite)') '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', parser.add_argument('--user-index',
type=int, type=int,
...@@ -158,6 +165,10 @@ class PerformanceTester(object): ...@@ -158,6 +165,10 @@ class PerformanceTester(object):
min(len(namespace.benchmark_suite_list) * namespace.repeat, min(len(namespace.benchmark_suite_list) * namespace.repeat,
namespace.max_error_number) 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_name_list = namespace.benchmark_suite_list
namespace.benchmark_suite_list = object_benchmark_suite_list namespace.benchmark_suite_list = object_benchmark_suite_list
...@@ -205,7 +216,7 @@ class PerformanceTester(object): ...@@ -205,7 +216,7 @@ class PerformanceTester(object):
ERP5BenchmarkResult.closeResultDocument(self._argument_namespace.erp5_publish_url, ERP5BenchmarkResult.closeResultDocument(self._argument_namespace.erp5_publish_url,
error_message_set) error_message_set)
def _run_constant(self, nb_users): def _run_constant(self, nb_users, current_repeat_range=None):
process_list = [] process_list = []
exit_msg_queue = multiprocessing.Queue(nb_users) exit_msg_queue = multiprocessing.Queue(nb_users)
...@@ -214,7 +225,8 @@ class PerformanceTester(object): ...@@ -214,7 +225,8 @@ class PerformanceTester(object):
for user_index in range(nb_users): for user_index in range(nb_users):
process = BenchmarkProcess(exit_msg_queue, result_class, process = BenchmarkProcess(exit_msg_queue, result_class,
self._argument_namespace, nb_users, self._argument_namespace, nb_users,
user_index) user_index,
current_repeat_range)
process_list.append(process) process_list.append(process)
...@@ -269,14 +281,31 @@ class PerformanceTester(object): ...@@ -269,14 +281,31 @@ class PerformanceTester(object):
self.preRun() self.preRun()
if isinstance(self._argument_namespace.users, tuple): if isinstance(self._argument_namespace.users, tuple):
nb_users, max_users = self._argument_namespace.users min_user_number, max_user_number = self._argument_namespace.users
while True: repeat_counter = 0
error_message_set, exit_status = self._run_constant(nb_users) exit_with_error = False
if exit_status != 0 or nb_users == max_users:
break while (repeat_counter != self._argument_namespace.repeat_range and
not exit_with_error):
nb_users = min(nb_users + self._argument_namespace.users_range_increment, current_user_number = min_user_number
max_users)
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: else:
error_message_set, exit_status = self._run_constant( error_message_set, exit_status = self._run_constant(
self._argument_namespace.users) self._argument_namespace.users)
......
...@@ -43,12 +43,14 @@ RESULT_NUMBER_BEFORE_FLUSHING = 100 ...@@ -43,12 +43,14 @@ RESULT_NUMBER_BEFORE_FLUSHING = 100
class BenchmarkProcess(multiprocessing.Process): class BenchmarkProcess(multiprocessing.Process):
def __init__(self, exit_msg_queue, result_klass, argument_namespace, 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._exit_msg_queue = exit_msg_queue
self._result_klass = result_klass self._result_klass = result_klass
self._argument_namespace = argument_namespace self._argument_namespace = argument_namespace
self._nb_users = nb_users self._nb_users = nb_users
self._user_index = user_index self._user_index = user_index
self._current_repeat_range = current_repeat_range
self._base_url, self._erp5_site_id = argument_namespace.url self._base_url, self._erp5_site_id = argument_namespace.url
try: try:
...@@ -137,7 +139,8 @@ class BenchmarkProcess(multiprocessing.Process): ...@@ -137,7 +139,8 @@ class BenchmarkProcess(multiprocessing.Process):
def run(self): def run(self):
result_instance = self._result_klass(self._argument_namespace, result_instance = self._result_klass(self._argument_namespace,
self._nb_users, self._nb_users,
self._user_index) self._user_index,
self._current_repeat_range)
self._logger = result_instance.logger self._logger = result_instance.logger
......
...@@ -81,10 +81,13 @@ import abc ...@@ -81,10 +81,13 @@ import abc
class BenchmarkResult(object): class BenchmarkResult(object):
__metaclass__ = abc.ABCMeta __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._argument_namespace = argument_namespace
self._nb_users = nb_users self._nb_users = nb_users
self._user_index = user_index self._user_index = user_index
self._current_repeat_range = current_repeat_range
self._logger = None self._logger = None
self._label_list = None self._label_list = None
...@@ -229,11 +232,18 @@ class CSVBenchmarkResult(BenchmarkResult): ...@@ -229,11 +232,18 @@ class CSVBenchmarkResult(BenchmarkResult):
self.log_file = open(self._log_filename_path, 'w') self.log_file = open(self._log_filename_path, 'w')
def _getFilenamePrefix(self): def _getFilenamePrefix(self):
max_nb_users = isinstance(self._argument_namespace.users, int) and \ if isinstance(self._argument_namespace.users, int):
self._argument_namespace.users or self._argument_namespace.users[1] 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" % \ fmt = "%%s-%%drepeat-%%0%ddusers-process%%0%dd%s" % \
(len(str(max_nb_users)), len(str(self._nb_users))) (len(str(max_nb_users)), len(str(self._nb_users)),
suffix)
return fmt % (self._argument_namespace.filename_prefix, return fmt % (self._argument_namespace.filename_prefix,
self._argument_namespace.repeat, self._argument_namespace.repeat,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment