Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user group processes config entry #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ xml_report = off

[user_group-1]
threads = 3
processes = 4
script = example_mock.py

[user_group-2]
threads = 3
processes = 2
script = example_mock.py
6 changes: 3 additions & 3 deletions multimechanize/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def output_results(results_dir, results_file, run_time, rampup, ts_interval, use
if user_group_configs:
report.write_line('<b>workload configuration:</b><br /><br />')
report.write_line('<table>')
report.write_line('<tr><th>group name</th><th>threads</th><th>script name</th></tr>')
report.write_line('<tr><th>group name</th><th>processes</th><th>threads</th><th>script name</th></tr>')
for user_group_config in user_group_configs:
report.write_line('<tr><td>%s</td><td>%d</td><td>%s</td></tr>' %
(user_group_config.name, user_group_config.num_threads, user_group_config.script_file))
report.write_line('<tr><td>%s</td><td>%d</td><td>%d</td><td>%s</td></tr>' %
(user_group_config.name, user_group_config.num_processes, user_group_config.num_threads, user_group_config.script_file))
report.write_line('</table>')
report.write_line('</div>')

Expand Down
10 changes: 6 additions & 4 deletions multimechanize/resultsloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,19 @@ class UserGroupConfig(Base):
id = Column (Integer, nullable=False, primary_key=True)
mechanize_global_configs_id = Column(Integer, ForeignKey('mechanize_global_configs.id'), nullable=False)
user_group = Column(String(50), nullable=False)
processes = Column(Integer, nullable=False)
threads = Column(Integer, nullable=False)
script = Column(String(50), nullable=False)

def __init__(self, user_group=None, threads=None, script=None):
def __init__(self, user_group=None, processes=None, threads=None, script=None):
self.user_group = str(user_group)
self.processes = int(processes)
self.threads = int(threads)
self.script = str(script)

def __repr__(self):
return "<UserGroupConfig('%s','%s','%s')>" % (
self.user_group, self.threads, self.script)
return "<UserGroupConfig('%s','%i', '%i','%s')>" % (
self.user_group, self.processes, self.threads, self.script)

class ResultRow(Base):
"""class representing a multi-mechanize results.csv row"""
Expand Down Expand Up @@ -157,7 +159,7 @@ def load_results_database(project_name, run_localtime, results_dir,

for i, ug_config in enumerate(user_group_configs):
user_group_config = UserGroupConfig(ug_config.name,
ug_config.num_threads, ug_config.script_file)
ug_config.num_processes, ug_config.num_threads, ug_config.script_file)
global_config.user_group_configs.append(user_group_config)

for line in fileinput.input([results_file]):
Expand Down
2 changes: 2 additions & 0 deletions multimechanize/utilities/newproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

[user_group-1]
threads = 3
processes = 4
script = %s

[user_group-2]
threads = 3
processes = 2
script = %s

""" % (SCRIPT_NAME, SCRIPT_NAME)
Expand Down
26 changes: 17 additions & 9 deletions multimechanize/utilities/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ def run_test(project_name, cmd_opts, remote_starter=None):
script_prefix = os.path.join(cmd_opts.projects_dir, project_name, "test_scripts")
script_prefix = os.path.normpath(script_prefix)

user_groups = []
for i, ug_config in enumerate(user_group_configs):
user_groups, process_num = [], 0
for ug_config in user_group_configs:
script_file = os.path.join(script_prefix, ug_config.script_file)
ug = core.UserGroup(queue, i, ug_config.name, ug_config.num_threads,
script_file, run_time, rampup)
user_groups.append(ug)
for _ in range(ug_config.num_processes):
ug = core.UserGroup(queue, process_num, ug_config.name, ug_config.num_threads,
script_file, run_time, rampup)
user_groups.append(ug)
process_num += 1
for user_group in user_groups:
user_group.start()

Expand All @@ -103,8 +105,9 @@ def run_test(project_name, cmd_opts, remote_starter=None):
for user_group in user_groups:
user_group.join()
else:
print '\n user_groups: %i' % len(user_groups)
print ' threads: %i\n' % (ug_config.num_threads * len(user_groups))
print '\n user_groups: %i' % len(user_group_configs)
print ' processes: %i' % sum(g.num_processes for g in user_group_configs)
print ' threads: %i\n' % sum(g.num_threads * g.num_processes for g in user_group_configs)

if progress_bar:
p = progressbar.ProgressBar(run_time)
Expand Down Expand Up @@ -216,16 +219,21 @@ def configure(project_name, cmd_opts, config_file=None):
else:
threads = config.getint(section, 'threads')
script = config.get(section, 'script')
try:
processes = config.getint(section, 'processes')
except ConfigParser.NoOptionError:
processes = 1
user_group_name = section
ug_config = UserGroupConfig(threads, user_group_name, script)
ug_config = UserGroupConfig(processes, threads, user_group_name, script)
user_group_configs.append(ug_config)

return (run_time, rampup, results_ts_interval, console_logging, progress_bar, results_database, post_run_script, xml_report, user_group_configs)



class UserGroupConfig(object):
def __init__(self, num_threads, name, script_file):
def __init__(self, num_processes, num_threads, name, script_file):
self.num_processes = num_processes
self.num_threads = num_threads
self.name = name
self.script_file = script_file
Expand Down