blob: f7646c9188c90534753690c44a5d24621f66a348 [file] [log] [blame]
Jan Tattermuschb2758442016-03-28 09:32:20 -07001#!/usr/bin/env python2.7
2# Copyright 2016, Google Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15# * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31"""Run performance tests locally or remotely."""
32
siddharthshukla0589e532016-07-07 16:08:01 +020033from __future__ import print_function
34
Jan Tattermuschb2758442016-03-28 09:32:20 -070035import argparse
Craig Tilleraccf16b2016-09-15 09:08:32 -070036import collections
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070037import itertools
Jan Tattermuschb2758442016-03-28 09:32:20 -070038import jobset
Craig Tiller0bda0b32016-03-03 12:51:53 -080039import json
Jan Tattermuschb2758442016-03-28 09:32:20 -070040import multiprocessing
41import os
Craig Tilleraccf16b2016-09-15 09:08:32 -070042import performance.scenario_config as scenario_config
Craig Tiller0bda0b32016-03-03 12:51:53 -080043import pipes
Jan Tattermusch38becc22016-04-14 08:00:35 -070044import re
Jan Tattermuschb2758442016-03-28 09:32:20 -070045import subprocess
46import sys
47import tempfile
48import time
Jan Tattermuschee9032c2016-04-14 08:35:51 -070049import traceback
Jan Tattermuschb2758442016-03-28 09:32:20 -070050import uuid
51
52
53_ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..'))
54os.chdir(_ROOT)
55
56
57_REMOTE_HOST_USERNAME = 'jenkins'
58
59
Jan Tattermuschb2758442016-03-28 09:32:20 -070060class QpsWorkerJob:
61 """Encapsulates a qps worker server job."""
62
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070063 def __init__(self, spec, language, host_and_port):
Jan Tattermuschb2758442016-03-28 09:32:20 -070064 self._spec = spec
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070065 self.language = language
Jan Tattermuschb2758442016-03-28 09:32:20 -070066 self.host_and_port = host_and_port
Craig Tillerc1b54f22016-09-15 08:57:14 -070067 self._job = None
68
69 def start(self):
Craig Tillerc197ec12016-09-15 09:19:33 -070070 self._job = jobset.Job(self._spec, newline_on_success=True, travis=True, add_env={})
Jan Tattermuschb2758442016-03-28 09:32:20 -070071
72 def is_running(self):
73 """Polls a job and returns True if given job is still running."""
Craig Tillerc1b54f22016-09-15 08:57:14 -070074 return self._job and self._job.state() == jobset._RUNNING
Jan Tattermuschb2758442016-03-28 09:32:20 -070075
76 def kill(self):
Craig Tillerc1b54f22016-09-15 08:57:14 -070077 if self._job:
78 self._job.kill()
79 self._job = None
Jan Tattermuschb2758442016-03-28 09:32:20 -070080
81
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070082def create_qpsworker_job(language, shortname=None,
83 port=10000, remote_host=None):
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070084 cmdline = language.worker_cmdline() + ['--driver_port=%s' % port]
Jan Tattermuschb2758442016-03-28 09:32:20 -070085 if remote_host:
86 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host)
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070087 cmdline = ['ssh',
88 str(user_at_host),
89 'cd ~/performance_workspace/grpc/ && %s' % ' '.join(cmdline)]
Jan Tattermuschb2758442016-03-28 09:32:20 -070090 host_and_port='%s:%s' % (remote_host, port)
91 else:
92 host_and_port='localhost:%s' % port
93
94 jobspec = jobset.JobSpec(
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070095 cmdline=cmdline,
96 shortname=shortname,
Jan Tattermusch447548b2016-10-17 12:04:56 +020097 timeout_seconds=5*60, # workers get restarted after each scenario
98 verbose_success=True)
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070099 return QpsWorkerJob(jobspec, language, host_and_port)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700100
101
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700102def create_scenario_jobspec(scenario_json, workers, remote_host=None,
103 bq_result_table=None):
Jan Tattermuschb2758442016-03-28 09:32:20 -0700104 """Runs one scenario using QPS driver."""
105 # setting QPS_WORKERS env variable here makes sure it works with SSH too.
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700106 cmd = 'QPS_WORKERS="%s" ' % ','.join(workers)
107 if bq_result_table:
108 cmd += 'BQ_RESULT_TABLE="%s" ' % bq_result_table
109 cmd += 'tools/run_tests/performance/run_qps_driver.sh '
110 cmd += '--scenarios_json=%s ' % pipes.quote(json.dumps({'scenarios': [scenario_json]}))
Vijay Paic23d33b2016-07-19 11:19:12 -0700111 cmd += '--scenario_result_file=scenario_result.json'
Jan Tattermuschb2758442016-03-28 09:32:20 -0700112 if remote_host:
113 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host)
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700114 cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd))
Jan Tattermuschb2758442016-03-28 09:32:20 -0700115
116 return jobset.JobSpec(
117 cmdline=[cmd],
Craig Tiller0bda0b32016-03-03 12:51:53 -0800118 shortname='qps_json_driver.%s' % scenario_json['name'],
119 timeout_seconds=3*60,
120 shell=True,
121 verbose_success=True)
122
123
124def create_quit_jobspec(workers, remote_host=None):
125 """Runs quit using QPS driver."""
126 # setting QPS_WORKERS env variable here makes sure it works with SSH too.
Craig Tiller025972d2016-09-15 09:26:50 -0700127 cmd = 'QPS_WORKERS="%s" bins/opt/qps_json_driver --quit' % ','.join(w.host_and_port for w in workers)
Craig Tiller0bda0b32016-03-03 12:51:53 -0800128 if remote_host:
129 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host)
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700130 cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd))
Craig Tiller0bda0b32016-03-03 12:51:53 -0800131
132 return jobset.JobSpec(
133 cmdline=[cmd],
vjpai29089c72016-04-20 12:38:16 -0700134 shortname='qps_json_driver.quit',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700135 timeout_seconds=3*60,
136 shell=True,
137 verbose_success=True)
138
139
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700140def create_netperf_jobspec(server_host='localhost', client_host=None,
141 bq_result_table=None):
142 """Runs netperf benchmark."""
143 cmd = 'NETPERF_SERVER_HOST="%s" ' % server_host
144 if bq_result_table:
145 cmd += 'BQ_RESULT_TABLE="%s" ' % bq_result_table
Jan Tattermuschad17bf72016-05-11 12:41:37 -0700146 if client_host:
147 # If netperf is running remotely, the env variables populated by Jenkins
148 # won't be available on the client, but we need them for uploading results
149 # to BigQuery.
150 jenkins_job_name = os.getenv('JOB_NAME')
151 if jenkins_job_name:
152 cmd += 'JOB_NAME="%s" ' % jenkins_job_name
153 jenkins_build_number = os.getenv('BUILD_NUMBER')
154 if jenkins_build_number:
155 cmd += 'BUILD_NUMBER="%s" ' % jenkins_build_number
156
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700157 cmd += 'tools/run_tests/performance/run_netperf.sh'
158 if client_host:
159 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, client_host)
160 cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd))
161
162 return jobset.JobSpec(
163 cmdline=[cmd],
164 shortname='netperf',
165 timeout_seconds=60,
166 shell=True,
167 verbose_success=True)
168
169
Jan Tattermuschde874a12016-04-18 09:21:37 -0700170def archive_repo(languages):
Jan Tattermuschb2758442016-03-28 09:32:20 -0700171 """Archives local version of repo including submodules."""
Jan Tattermuschde874a12016-04-18 09:21:37 -0700172 cmdline=['tar', '-cf', '../grpc.tar', '../grpc/']
173 if 'java' in languages:
174 cmdline.append('../grpc-java')
175 if 'go' in languages:
176 cmdline.append('../grpc-go')
177
Jan Tattermuschb2758442016-03-28 09:32:20 -0700178 archive_job = jobset.JobSpec(
Jan Tattermuschde874a12016-04-18 09:21:37 -0700179 cmdline=cmdline,
Jan Tattermuschb2758442016-03-28 09:32:20 -0700180 shortname='archive_repo',
181 timeout_seconds=3*60)
182
183 jobset.message('START', 'Archiving local repository.', do_newline=True)
184 num_failures, _ = jobset.run(
185 [archive_job], newline_on_success=True, maxjobs=1)
186 if num_failures == 0:
187 jobset.message('SUCCESS',
Jan Tattermuschde874a12016-04-18 09:21:37 -0700188 'Archive with local repository created successfully.',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700189 do_newline=True)
190 else:
191 jobset.message('FAILED', 'Failed to archive local repository.',
192 do_newline=True)
193 sys.exit(1)
194
195
Jan Tattermusch14089202016-04-27 17:55:27 -0700196def prepare_remote_hosts(hosts, prepare_local=False):
197 """Prepares remote hosts (and maybe prepare localhost as well)."""
198 prepare_timeout = 5*60
Jan Tattermuschb2758442016-03-28 09:32:20 -0700199 prepare_jobs = []
200 for host in hosts:
201 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, host)
202 prepare_jobs.append(
203 jobset.JobSpec(
204 cmdline=['tools/run_tests/performance/remote_host_prepare.sh'],
205 shortname='remote_host_prepare.%s' % host,
206 environ = {'USER_AT_HOST': user_at_host},
Jan Tattermusch14089202016-04-27 17:55:27 -0700207 timeout_seconds=prepare_timeout))
208 if prepare_local:
209 # Prepare localhost as well
210 prepare_jobs.append(
211 jobset.JobSpec(
212 cmdline=['tools/run_tests/performance/kill_workers.sh'],
213 shortname='local_prepare',
214 timeout_seconds=prepare_timeout))
215 jobset.message('START', 'Preparing hosts.', do_newline=True)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700216 num_failures, _ = jobset.run(
217 prepare_jobs, newline_on_success=True, maxjobs=10)
218 if num_failures == 0:
219 jobset.message('SUCCESS',
Jan Tattermusch14089202016-04-27 17:55:27 -0700220 'Prepare step completed successfully.',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700221 do_newline=True)
222 else:
223 jobset.message('FAILED', 'Failed to prepare remote hosts.',
224 do_newline=True)
225 sys.exit(1)
226
227
Craig Tillerd92d5c52016-04-04 13:49:29 -0700228def build_on_remote_hosts(hosts, languages=scenario_config.LANGUAGES.keys(), build_local=False):
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700229 """Builds performance worker on remote hosts (and maybe also locally)."""
Jan Tattermuschb2758442016-03-28 09:32:20 -0700230 build_timeout = 15*60
231 build_jobs = []
232 for host in hosts:
233 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, host)
234 build_jobs.append(
235 jobset.JobSpec(
Craig Tiller7797e3f2016-04-01 07:41:05 -0700236 cmdline=['tools/run_tests/performance/remote_host_build.sh'] + languages,
Jan Tattermuschb2758442016-03-28 09:32:20 -0700237 shortname='remote_host_build.%s' % host,
238 environ = {'USER_AT_HOST': user_at_host, 'CONFIG': 'opt'},
239 timeout_seconds=build_timeout))
240 if build_local:
241 # Build locally as well
242 build_jobs.append(
243 jobset.JobSpec(
Craig Tiller7797e3f2016-04-01 07:41:05 -0700244 cmdline=['tools/run_tests/performance/build_performance.sh'] + languages,
Jan Tattermuschb2758442016-03-28 09:32:20 -0700245 shortname='local_build',
246 environ = {'CONFIG': 'opt'},
247 timeout_seconds=build_timeout))
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700248 jobset.message('START', 'Building.', do_newline=True)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700249 num_failures, _ = jobset.run(
250 build_jobs, newline_on_success=True, maxjobs=10)
251 if num_failures == 0:
252 jobset.message('SUCCESS',
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700253 'Built successfully.',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700254 do_newline=True)
255 else:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700256 jobset.message('FAILED', 'Build failed.',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700257 do_newline=True)
258 sys.exit(1)
259
260
Craig Tillerc1b54f22016-09-15 08:57:14 -0700261def create_qpsworkers(languages, worker_hosts):
262 """Creates QPS workers (but does not start them)."""
Jan Tattermuschb2758442016-03-28 09:32:20 -0700263 if not worker_hosts:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700264 # run two workers locally (for each language)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700265 workers=[(None, 10000), (None, 10010)]
266 elif len(worker_hosts) == 1:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700267 # run two workers on the remote host (for each language)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700268 workers=[(worker_hosts[0], 10000), (worker_hosts[0], 10010)]
269 else:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700270 # run one worker per each remote host (for each language)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700271 workers=[(worker_host, 10000) for worker_host in worker_hosts]
272
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700273 return [create_qpsworker_job(language,
274 shortname= 'qps_worker_%s_%s' % (language,
275 worker_idx),
276 port=worker[1] + language.worker_port_offset(),
Jan Tattermuschb2758442016-03-28 09:32:20 -0700277 remote_host=worker[0])
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700278 for language in languages
279 for worker_idx, worker in enumerate(workers)]
Jan Tattermuschb2758442016-03-28 09:32:20 -0700280
281
Craig Tiller677966a2016-09-26 07:37:28 -0700282Scenario = collections.namedtuple('Scenario', 'jobspec workers name')
Craig Tillerc1b54f22016-09-15 08:57:14 -0700283
284
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700285def create_scenarios(languages, workers_by_lang, remote_host=None, regex='.*',
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700286 category='all', bq_result_table=None,
287 netperf=False, netperf_hosts=[]):
Jan Tattermuschb2758442016-03-28 09:32:20 -0700288 """Create jobspecs for scenarios to run."""
Ken Payson0482c102016-04-19 12:08:34 -0700289 all_workers = [worker
290 for workers in workers_by_lang.values()
291 for worker in workers]
Jan Tattermuschb2758442016-03-28 09:32:20 -0700292 scenarios = []
Craig Tillerc1b54f22016-09-15 08:57:14 -0700293 _NO_WORKERS = []
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700294
295 if netperf:
296 if not netperf_hosts:
297 netperf_server='localhost'
298 netperf_client=None
299 elif len(netperf_hosts) == 1:
300 netperf_server=netperf_hosts[0]
301 netperf_client=netperf_hosts[0]
302 else:
303 netperf_server=netperf_hosts[0]
304 netperf_client=netperf_hosts[1]
Craig Tillerc1b54f22016-09-15 08:57:14 -0700305 scenarios.append(Scenario(
306 create_netperf_jobspec(server_host=netperf_server,
307 client_host=netperf_client,
308 bq_result_table=bq_result_table),
Craig Tiller677966a2016-09-26 07:37:28 -0700309 _NO_WORKERS, 'netperf'))
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700310
Jan Tattermuschb2758442016-03-28 09:32:20 -0700311 for language in languages:
Craig Tiller0bda0b32016-03-03 12:51:53 -0800312 for scenario_json in language.scenarios():
Jan Tattermusch38becc22016-04-14 08:00:35 -0700313 if re.search(args.regex, scenario_json['name']):
Craig Tillerb6df2472016-09-13 09:41:26 -0700314 categories = scenario_json.get('CATEGORIES', ['scalable', 'smoketest'])
315 if category in categories or category == 'all':
Craig Tillerc1b54f22016-09-15 08:57:14 -0700316 workers = workers_by_lang[str(language)][:]
Jan Tattermusch427699b2016-05-05 18:10:14 -0700317 # 'SERVER_LANGUAGE' is an indicator for this script to pick
318 # a server in different language.
319 custom_server_lang = scenario_json.get('SERVER_LANGUAGE', None)
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700320 custom_client_lang = scenario_json.get('CLIENT_LANGUAGE', None)
Jan Tattermusch427699b2016-05-05 18:10:14 -0700321 scenario_json = scenario_config.remove_nonproto_fields(scenario_json)
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700322 if custom_server_lang and custom_client_lang:
323 raise Exception('Cannot set both custom CLIENT_LANGUAGE and SERVER_LANGUAGE'
324 'in the same scenario')
Jan Tattermusch427699b2016-05-05 18:10:14 -0700325 if custom_server_lang:
326 if not workers_by_lang.get(custom_server_lang, []):
siddharthshukla0589e532016-07-07 16:08:01 +0200327 print('Warning: Skipping scenario %s as' % scenario_json['name'])
Jan Tattermusch427699b2016-05-05 18:10:14 -0700328 print('SERVER_LANGUAGE is set to %s yet the language has '
329 'not been selected with -l' % custom_server_lang)
330 continue
331 for idx in range(0, scenario_json['num_servers']):
332 # replace first X workers by workers of a different language
333 workers[idx] = workers_by_lang[custom_server_lang][idx]
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700334 if custom_client_lang:
335 if not workers_by_lang.get(custom_client_lang, []):
siddharthshukla0589e532016-07-07 16:08:01 +0200336 print('Warning: Skipping scenario %s as' % scenario_json['name'])
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700337 print('CLIENT_LANGUAGE is set to %s yet the language has '
338 'not been selected with -l' % custom_client_lang)
339 continue
340 for idx in range(scenario_json['num_servers'], len(workers)):
341 # replace all client workers by workers of a different language,
342 # leave num_server workers as they are server workers.
343 workers[idx] = workers_by_lang[custom_client_lang][idx]
Craig Tillerc1b54f22016-09-15 08:57:14 -0700344 scenario = Scenario(
345 create_scenario_jobspec(scenario_json,
346 [w.host_and_port for w in workers],
347 remote_host=remote_host,
348 bq_result_table=bq_result_table),
Craig Tiller677966a2016-09-26 07:37:28 -0700349 workers,
350 scenario_json['name'])
Jan Tattermusch427699b2016-05-05 18:10:14 -0700351 scenarios.append(scenario)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700352
Jan Tattermuschb2758442016-03-28 09:32:20 -0700353 return scenarios
354
355
356def finish_qps_workers(jobs):
357 """Waits for given jobs to finish and eventually kills them."""
358 retries = 0
359 while any(job.is_running() for job in jobs):
360 for job in qpsworker_jobs:
361 if job.is_running():
siddharthshukla0589e532016-07-07 16:08:01 +0200362 print('QPS worker "%s" is still running.' % job.host_and_port)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700363 if retries > 10:
siddharthshukla0589e532016-07-07 16:08:01 +0200364 print('Killing all QPS workers.')
Jan Tattermuschb2758442016-03-28 09:32:20 -0700365 for job in jobs:
366 job.kill()
367 retries += 1
368 time.sleep(3)
siddharthshukla0589e532016-07-07 16:08:01 +0200369 print('All QPS workers finished.')
Jan Tattermuschb2758442016-03-28 09:32:20 -0700370
371
372argp = argparse.ArgumentParser(description='Run performance tests.')
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700373argp.add_argument('-l', '--language',
Craig Tillerd92d5c52016-04-04 13:49:29 -0700374 choices=['all'] + sorted(scenario_config.LANGUAGES.keys()),
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700375 nargs='+',
Jan Tattermusch427699b2016-05-05 18:10:14 -0700376 required=True,
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700377 help='Languages to benchmark.')
Jan Tattermuschb2758442016-03-28 09:32:20 -0700378argp.add_argument('--remote_driver_host',
379 default=None,
380 help='Run QPS driver on given host. By default, QPS driver is run locally.')
381argp.add_argument('--remote_worker_host',
382 nargs='+',
383 default=[],
384 help='Worker hosts where to start QPS workers.')
Craig Tiller677966a2016-09-26 07:37:28 -0700385argp.add_argument('--dry_run',
386 default=False,
387 action='store_const',
388 const=True,
389 help='Just list scenarios to be run, but don\'t run them.')
Jan Tattermusch38becc22016-04-14 08:00:35 -0700390argp.add_argument('-r', '--regex', default='.*', type=str,
391 help='Regex to select scenarios to run.')
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700392argp.add_argument('--bq_result_table', default=None, type=str,
393 help='Bigquery "dataset.table" to upload results to.')
Jan Tattermusch427699b2016-05-05 18:10:14 -0700394argp.add_argument('--category',
Craig Tiller6388da52016-09-07 17:06:29 -0700395 choices=['smoketest','all','scalable','sweep'],
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700396 default='all',
397 help='Select a category of tests to run.')
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700398argp.add_argument('--netperf',
399 default=False,
400 action='store_const',
401 const=True,
402 help='Run netperf benchmark as one of the scenarios.')
Jan Tattermuschb2758442016-03-28 09:32:20 -0700403
404args = argp.parse_args()
405
Craig Tillerd92d5c52016-04-04 13:49:29 -0700406languages = set(scenario_config.LANGUAGES[l]
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700407 for l in itertools.chain.from_iterable(
Craig Tillerd92d5c52016-04-04 13:49:29 -0700408 scenario_config.LANGUAGES.iterkeys() if x == 'all' else [x]
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700409 for x in args.language))
410
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700411
Jan Tattermuschb2758442016-03-28 09:32:20 -0700412# Put together set of remote hosts where to run and build
413remote_hosts = set()
414if args.remote_worker_host:
415 for host in args.remote_worker_host:
416 remote_hosts.add(host)
417if args.remote_driver_host:
418 remote_hosts.add(args.remote_driver_host)
419
Craig Tiller677966a2016-09-26 07:37:28 -0700420if not args.dry_run:
421 if remote_hosts:
422 archive_repo(languages=[str(l) for l in languages])
423 prepare_remote_hosts(remote_hosts, prepare_local=True)
424 else:
425 prepare_remote_hosts([], prepare_local=True)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700426
427build_local = False
428if not args.remote_driver_host:
429 build_local = True
Craig Tiller677966a2016-09-26 07:37:28 -0700430if not args.dry_run:
431 build_on_remote_hosts(remote_hosts, languages=[str(l) for l in languages], build_local=build_local)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700432
Craig Tillerc1b54f22016-09-15 08:57:14 -0700433qpsworker_jobs = create_qpsworkers(languages, args.remote_worker_host)
Jan Tattermusch38becc22016-04-14 08:00:35 -0700434
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700435# get list of worker addresses for each language.
Craig Tillerc1b54f22016-09-15 08:57:14 -0700436workers_by_lang = dict([(str(language), []) for language in languages])
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700437for job in qpsworker_jobs:
Craig Tillerc1b54f22016-09-15 08:57:14 -0700438 workers_by_lang[str(job.language)].append(job)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700439
Craig Tillerc1b54f22016-09-15 08:57:14 -0700440scenarios = create_scenarios(languages,
Craig Tillerd82fccc2016-09-15 09:15:23 -0700441 workers_by_lang=workers_by_lang,
Craig Tillerc1b54f22016-09-15 08:57:14 -0700442 remote_host=args.remote_driver_host,
443 regex=args.regex,
444 category=args.category,
445 bq_result_table=args.bq_result_table,
446 netperf=args.netperf,
447 netperf_hosts=args.remote_worker_host)
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700448
Craig Tillerc1b54f22016-09-15 08:57:14 -0700449if not scenarios:
450 raise Exception('No scenarios to run')
Jan Tattermuschb2758442016-03-28 09:32:20 -0700451
Craig Tillerc1b54f22016-09-15 08:57:14 -0700452for scenario in scenarios:
Craig Tiller677966a2016-09-26 07:37:28 -0700453 if args.dry_run:
454 print(scenario.name)
455 else:
456 try:
457 for worker in scenario.workers:
458 worker.start()
459 jobset.run([scenario.jobspec,
460 create_quit_jobspec(scenario.workers, remote_host=args.remote_driver_host)],
461 newline_on_success=True, maxjobs=1)
462 finally:
463 finish_qps_workers(scenario.workers)