blob: 14901caf07f24c30030568e984c475c8701d1ab8 [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
33import argparse
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070034import itertools
Jan Tattermuschb2758442016-03-28 09:32:20 -070035import jobset
Craig Tiller0bda0b32016-03-03 12:51:53 -080036import json
Jan Tattermuschb2758442016-03-28 09:32:20 -070037import multiprocessing
38import os
Craig Tiller0bda0b32016-03-03 12:51:53 -080039import pipes
Jan Tattermusch38becc22016-04-14 08:00:35 -070040import re
Jan Tattermuschb2758442016-03-28 09:32:20 -070041import subprocess
42import sys
43import tempfile
44import time
Jan Tattermuschee9032c2016-04-14 08:35:51 -070045import traceback
Jan Tattermuschb2758442016-03-28 09:32:20 -070046import uuid
Craig Tillerd92d5c52016-04-04 13:49:29 -070047import performance.scenario_config as scenario_config
Jan Tattermuschb2758442016-03-28 09:32:20 -070048
49
50_ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..'))
51os.chdir(_ROOT)
52
53
54_REMOTE_HOST_USERNAME = 'jenkins'
55
56
Jan Tattermuschb2758442016-03-28 09:32:20 -070057class QpsWorkerJob:
58 """Encapsulates a qps worker server job."""
59
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070060 def __init__(self, spec, language, host_and_port):
Jan Tattermuschb2758442016-03-28 09:32:20 -070061 self._spec = spec
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070062 self.language = language
Jan Tattermuschb2758442016-03-28 09:32:20 -070063 self.host_and_port = host_and_port
Craig Tiller2e1a1fe2016-06-23 16:18:31 -070064 self._job = jobset.Job(spec, newline_on_success=True, travis=True, add_env={})
Jan Tattermuschb2758442016-03-28 09:32:20 -070065
66 def is_running(self):
67 """Polls a job and returns True if given job is still running."""
Craig Tiller2e1a1fe2016-06-23 16:18:31 -070068 return self._job.state() == jobset._RUNNING
Jan Tattermuschb2758442016-03-28 09:32:20 -070069
70 def kill(self):
71 return self._job.kill()
72
73
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070074def create_qpsworker_job(language, shortname=None,
75 port=10000, remote_host=None):
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070076 cmdline = language.worker_cmdline() + ['--driver_port=%s' % port]
Jan Tattermuschb2758442016-03-28 09:32:20 -070077 if remote_host:
78 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host)
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070079 cmdline = ['ssh',
80 str(user_at_host),
81 'cd ~/performance_workspace/grpc/ && %s' % ' '.join(cmdline)]
Jan Tattermuschb2758442016-03-28 09:32:20 -070082 host_and_port='%s:%s' % (remote_host, port)
83 else:
84 host_and_port='localhost:%s' % port
85
Jan Tattermusch38becc22016-04-14 08:00:35 -070086 # TODO(jtattermusch): with some care, we can calculate the right timeout
87 # of a worker from the sum of warmup + benchmark times for all the scenarios
Jan Tattermuschb2758442016-03-28 09:32:20 -070088 jobspec = jobset.JobSpec(
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070089 cmdline=cmdline,
90 shortname=shortname,
Jan Tattermusch541d5d72016-05-05 16:08:49 -070091 timeout_seconds=2*60*60)
Jan Tattermuschbb1a4532016-03-30 18:04:01 -070092 return QpsWorkerJob(jobspec, language, host_and_port)
Jan Tattermuschb2758442016-03-28 09:32:20 -070093
94
Jan Tattermusch6d7fa552016-04-14 17:42:54 -070095def create_scenario_jobspec(scenario_json, workers, remote_host=None,
96 bq_result_table=None):
Jan Tattermuschb2758442016-03-28 09:32:20 -070097 """Runs one scenario using QPS driver."""
98 # setting QPS_WORKERS env variable here makes sure it works with SSH too.
Jan Tattermusch6d7fa552016-04-14 17:42:54 -070099 cmd = 'QPS_WORKERS="%s" ' % ','.join(workers)
100 if bq_result_table:
101 cmd += 'BQ_RESULT_TABLE="%s" ' % bq_result_table
102 cmd += 'tools/run_tests/performance/run_qps_driver.sh '
103 cmd += '--scenarios_json=%s ' % pipes.quote(json.dumps({'scenarios': [scenario_json]}))
104 cmd += '--scenario_result_file=scenario_result.json'
Jan Tattermuschb2758442016-03-28 09:32:20 -0700105 if remote_host:
106 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host)
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700107 cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd))
Jan Tattermuschb2758442016-03-28 09:32:20 -0700108
109 return jobset.JobSpec(
110 cmdline=[cmd],
Craig Tiller0bda0b32016-03-03 12:51:53 -0800111 shortname='qps_json_driver.%s' % scenario_json['name'],
112 timeout_seconds=3*60,
113 shell=True,
114 verbose_success=True)
115
116
117def create_quit_jobspec(workers, remote_host=None):
118 """Runs quit using QPS driver."""
119 # setting QPS_WORKERS env variable here makes sure it works with SSH too.
vjpai29089c72016-04-20 12:38:16 -0700120 cmd = 'QPS_WORKERS="%s" bins/opt/qps_json_driver --quit' % ','.join(workers)
Craig Tiller0bda0b32016-03-03 12:51:53 -0800121 if remote_host:
122 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host)
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700123 cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd))
Craig Tiller0bda0b32016-03-03 12:51:53 -0800124
125 return jobset.JobSpec(
126 cmdline=[cmd],
vjpai29089c72016-04-20 12:38:16 -0700127 shortname='qps_json_driver.quit',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700128 timeout_seconds=3*60,
129 shell=True,
130 verbose_success=True)
131
132
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700133def create_netperf_jobspec(server_host='localhost', client_host=None,
134 bq_result_table=None):
135 """Runs netperf benchmark."""
136 cmd = 'NETPERF_SERVER_HOST="%s" ' % server_host
137 if bq_result_table:
138 cmd += 'BQ_RESULT_TABLE="%s" ' % bq_result_table
Jan Tattermuschad17bf72016-05-11 12:41:37 -0700139 if client_host:
140 # If netperf is running remotely, the env variables populated by Jenkins
141 # won't be available on the client, but we need them for uploading results
142 # to BigQuery.
143 jenkins_job_name = os.getenv('JOB_NAME')
144 if jenkins_job_name:
145 cmd += 'JOB_NAME="%s" ' % jenkins_job_name
146 jenkins_build_number = os.getenv('BUILD_NUMBER')
147 if jenkins_build_number:
148 cmd += 'BUILD_NUMBER="%s" ' % jenkins_build_number
149
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700150 cmd += 'tools/run_tests/performance/run_netperf.sh'
151 if client_host:
152 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, client_host)
153 cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd))
154
155 return jobset.JobSpec(
156 cmdline=[cmd],
157 shortname='netperf',
158 timeout_seconds=60,
159 shell=True,
160 verbose_success=True)
161
162
Jan Tattermuschde874a12016-04-18 09:21:37 -0700163def archive_repo(languages):
Jan Tattermuschb2758442016-03-28 09:32:20 -0700164 """Archives local version of repo including submodules."""
Jan Tattermuschde874a12016-04-18 09:21:37 -0700165 cmdline=['tar', '-cf', '../grpc.tar', '../grpc/']
166 if 'java' in languages:
167 cmdline.append('../grpc-java')
168 if 'go' in languages:
169 cmdline.append('../grpc-go')
170
Jan Tattermuschb2758442016-03-28 09:32:20 -0700171 archive_job = jobset.JobSpec(
Jan Tattermuschde874a12016-04-18 09:21:37 -0700172 cmdline=cmdline,
Jan Tattermuschb2758442016-03-28 09:32:20 -0700173 shortname='archive_repo',
174 timeout_seconds=3*60)
175
176 jobset.message('START', 'Archiving local repository.', do_newline=True)
177 num_failures, _ = jobset.run(
178 [archive_job], newline_on_success=True, maxjobs=1)
179 if num_failures == 0:
180 jobset.message('SUCCESS',
Jan Tattermuschde874a12016-04-18 09:21:37 -0700181 'Archive with local repository created successfully.',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700182 do_newline=True)
183 else:
184 jobset.message('FAILED', 'Failed to archive local repository.',
185 do_newline=True)
186 sys.exit(1)
187
188
Jan Tattermusch14089202016-04-27 17:55:27 -0700189def prepare_remote_hosts(hosts, prepare_local=False):
190 """Prepares remote hosts (and maybe prepare localhost as well)."""
191 prepare_timeout = 5*60
Jan Tattermuschb2758442016-03-28 09:32:20 -0700192 prepare_jobs = []
193 for host in hosts:
194 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, host)
195 prepare_jobs.append(
196 jobset.JobSpec(
197 cmdline=['tools/run_tests/performance/remote_host_prepare.sh'],
198 shortname='remote_host_prepare.%s' % host,
199 environ = {'USER_AT_HOST': user_at_host},
Jan Tattermusch14089202016-04-27 17:55:27 -0700200 timeout_seconds=prepare_timeout))
201 if prepare_local:
202 # Prepare localhost as well
203 prepare_jobs.append(
204 jobset.JobSpec(
205 cmdline=['tools/run_tests/performance/kill_workers.sh'],
206 shortname='local_prepare',
207 timeout_seconds=prepare_timeout))
208 jobset.message('START', 'Preparing hosts.', do_newline=True)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700209 num_failures, _ = jobset.run(
210 prepare_jobs, newline_on_success=True, maxjobs=10)
211 if num_failures == 0:
212 jobset.message('SUCCESS',
Jan Tattermusch14089202016-04-27 17:55:27 -0700213 'Prepare step completed successfully.',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700214 do_newline=True)
215 else:
216 jobset.message('FAILED', 'Failed to prepare remote hosts.',
217 do_newline=True)
218 sys.exit(1)
219
220
Craig Tillerd92d5c52016-04-04 13:49:29 -0700221def build_on_remote_hosts(hosts, languages=scenario_config.LANGUAGES.keys(), build_local=False):
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700222 """Builds performance worker on remote hosts (and maybe also locally)."""
Jan Tattermuschb2758442016-03-28 09:32:20 -0700223 build_timeout = 15*60
224 build_jobs = []
225 for host in hosts:
226 user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, host)
227 build_jobs.append(
228 jobset.JobSpec(
Craig Tiller7797e3f2016-04-01 07:41:05 -0700229 cmdline=['tools/run_tests/performance/remote_host_build.sh'] + languages,
Jan Tattermuschb2758442016-03-28 09:32:20 -0700230 shortname='remote_host_build.%s' % host,
231 environ = {'USER_AT_HOST': user_at_host, 'CONFIG': 'opt'},
232 timeout_seconds=build_timeout))
233 if build_local:
234 # Build locally as well
235 build_jobs.append(
236 jobset.JobSpec(
Craig Tiller7797e3f2016-04-01 07:41:05 -0700237 cmdline=['tools/run_tests/performance/build_performance.sh'] + languages,
Jan Tattermuschb2758442016-03-28 09:32:20 -0700238 shortname='local_build',
239 environ = {'CONFIG': 'opt'},
240 timeout_seconds=build_timeout))
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700241 jobset.message('START', 'Building.', do_newline=True)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700242 num_failures, _ = jobset.run(
243 build_jobs, newline_on_success=True, maxjobs=10)
244 if num_failures == 0:
245 jobset.message('SUCCESS',
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700246 'Built successfully.',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700247 do_newline=True)
248 else:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700249 jobset.message('FAILED', 'Build failed.',
Jan Tattermuschb2758442016-03-28 09:32:20 -0700250 do_newline=True)
251 sys.exit(1)
252
253
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700254def start_qpsworkers(languages, worker_hosts):
Jan Tattermuschb2758442016-03-28 09:32:20 -0700255 """Starts QPS workers as background jobs."""
256 if not worker_hosts:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700257 # run two workers locally (for each language)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700258 workers=[(None, 10000), (None, 10010)]
259 elif len(worker_hosts) == 1:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700260 # run two workers on the remote host (for each language)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700261 workers=[(worker_hosts[0], 10000), (worker_hosts[0], 10010)]
262 else:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700263 # run one worker per each remote host (for each language)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700264 workers=[(worker_host, 10000) for worker_host in worker_hosts]
265
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700266 return [create_qpsworker_job(language,
267 shortname= 'qps_worker_%s_%s' % (language,
268 worker_idx),
269 port=worker[1] + language.worker_port_offset(),
Jan Tattermuschb2758442016-03-28 09:32:20 -0700270 remote_host=worker[0])
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700271 for language in languages
272 for worker_idx, worker in enumerate(workers)]
Jan Tattermuschb2758442016-03-28 09:32:20 -0700273
274
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700275def create_scenarios(languages, workers_by_lang, remote_host=None, regex='.*',
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700276 category='all', bq_result_table=None,
277 netperf=False, netperf_hosts=[]):
Jan Tattermuschb2758442016-03-28 09:32:20 -0700278 """Create jobspecs for scenarios to run."""
Ken Payson0482c102016-04-19 12:08:34 -0700279 all_workers = [worker
280 for workers in workers_by_lang.values()
281 for worker in workers]
Jan Tattermuschb2758442016-03-28 09:32:20 -0700282 scenarios = []
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700283
284 if netperf:
285 if not netperf_hosts:
286 netperf_server='localhost'
287 netperf_client=None
288 elif len(netperf_hosts) == 1:
289 netperf_server=netperf_hosts[0]
290 netperf_client=netperf_hosts[0]
291 else:
292 netperf_server=netperf_hosts[0]
293 netperf_client=netperf_hosts[1]
294 scenarios.append(create_netperf_jobspec(server_host=netperf_server,
295 client_host=netperf_client,
296 bq_result_table=bq_result_table))
297
Jan Tattermuschb2758442016-03-28 09:32:20 -0700298 for language in languages:
Craig Tiller0bda0b32016-03-03 12:51:53 -0800299 for scenario_json in language.scenarios():
Jan Tattermusch38becc22016-04-14 08:00:35 -0700300 if re.search(args.regex, scenario_json['name']):
Jan Tattermusch427699b2016-05-05 18:10:14 -0700301 if category in scenario_json.get('CATEGORIES', []) or category == 'all':
302 workers = workers_by_lang[str(language)]
303 # 'SERVER_LANGUAGE' is an indicator for this script to pick
304 # a server in different language.
305 custom_server_lang = scenario_json.get('SERVER_LANGUAGE', None)
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700306 custom_client_lang = scenario_json.get('CLIENT_LANGUAGE', None)
Jan Tattermusch427699b2016-05-05 18:10:14 -0700307 scenario_json = scenario_config.remove_nonproto_fields(scenario_json)
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700308 if custom_server_lang and custom_client_lang:
309 raise Exception('Cannot set both custom CLIENT_LANGUAGE and SERVER_LANGUAGE'
310 'in the same scenario')
Jan Tattermusch427699b2016-05-05 18:10:14 -0700311 if custom_server_lang:
312 if not workers_by_lang.get(custom_server_lang, []):
313 print 'Warning: Skipping scenario %s as' % scenario_json['name']
314 print('SERVER_LANGUAGE is set to %s yet the language has '
315 'not been selected with -l' % custom_server_lang)
316 continue
317 for idx in range(0, scenario_json['num_servers']):
318 # replace first X workers by workers of a different language
319 workers[idx] = workers_by_lang[custom_server_lang][idx]
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700320 if custom_client_lang:
321 if not workers_by_lang.get(custom_client_lang, []):
322 print 'Warning: Skipping scenario %s as' % scenario_json['name']
323 print('CLIENT_LANGUAGE is set to %s yet the language has '
324 'not been selected with -l' % custom_client_lang)
325 continue
326 for idx in range(scenario_json['num_servers'], len(workers)):
327 # replace all client workers by workers of a different language,
328 # leave num_server workers as they are server workers.
329 workers[idx] = workers_by_lang[custom_client_lang][idx]
Jan Tattermusch427699b2016-05-05 18:10:14 -0700330 scenario = create_scenario_jobspec(scenario_json,
331 workers,
332 remote_host=remote_host,
333 bq_result_table=bq_result_table)
334 scenarios.append(scenario)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700335
336 # the very last scenario requests shutting down the workers.
Craig Tiller0bda0b32016-03-03 12:51:53 -0800337 scenarios.append(create_quit_jobspec(all_workers, remote_host=remote_host))
Jan Tattermuschb2758442016-03-28 09:32:20 -0700338 return scenarios
339
340
341def finish_qps_workers(jobs):
342 """Waits for given jobs to finish and eventually kills them."""
343 retries = 0
344 while any(job.is_running() for job in jobs):
345 for job in qpsworker_jobs:
346 if job.is_running():
347 print 'QPS worker "%s" is still running.' % job.host_and_port
348 if retries > 10:
349 print 'Killing all QPS workers.'
350 for job in jobs:
351 job.kill()
352 retries += 1
353 time.sleep(3)
354 print 'All QPS workers finished.'
355
356
357argp = argparse.ArgumentParser(description='Run performance tests.')
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700358argp.add_argument('-l', '--language',
Craig Tillerd92d5c52016-04-04 13:49:29 -0700359 choices=['all'] + sorted(scenario_config.LANGUAGES.keys()),
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700360 nargs='+',
Jan Tattermusch427699b2016-05-05 18:10:14 -0700361 required=True,
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700362 help='Languages to benchmark.')
Jan Tattermuschb2758442016-03-28 09:32:20 -0700363argp.add_argument('--remote_driver_host',
364 default=None,
365 help='Run QPS driver on given host. By default, QPS driver is run locally.')
366argp.add_argument('--remote_worker_host',
367 nargs='+',
368 default=[],
369 help='Worker hosts where to start QPS workers.')
Jan Tattermusch38becc22016-04-14 08:00:35 -0700370argp.add_argument('-r', '--regex', default='.*', type=str,
371 help='Regex to select scenarios to run.')
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700372argp.add_argument('--bq_result_table', default=None, type=str,
373 help='Bigquery "dataset.table" to upload results to.')
Jan Tattermusch427699b2016-05-05 18:10:14 -0700374argp.add_argument('--category',
Jan Tattermuschd27888b2016-05-19 16:11:11 -0700375 choices=['smoketest','all','scalable'],
Jan Tattermusch37a907e2016-05-13 13:49:43 -0700376 default='all',
377 help='Select a category of tests to run.')
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700378argp.add_argument('--netperf',
379 default=False,
380 action='store_const',
381 const=True,
382 help='Run netperf benchmark as one of the scenarios.')
Jan Tattermuschb2758442016-03-28 09:32:20 -0700383
384args = argp.parse_args()
385
Craig Tillerd92d5c52016-04-04 13:49:29 -0700386languages = set(scenario_config.LANGUAGES[l]
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700387 for l in itertools.chain.from_iterable(
Craig Tillerd92d5c52016-04-04 13:49:29 -0700388 scenario_config.LANGUAGES.iterkeys() if x == 'all' else [x]
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700389 for x in args.language))
390
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700391
Jan Tattermuschb2758442016-03-28 09:32:20 -0700392# Put together set of remote hosts where to run and build
393remote_hosts = set()
394if args.remote_worker_host:
395 for host in args.remote_worker_host:
396 remote_hosts.add(host)
397if args.remote_driver_host:
398 remote_hosts.add(args.remote_driver_host)
399
400if remote_hosts:
Jan Tattermuschde874a12016-04-18 09:21:37 -0700401 archive_repo(languages=[str(l) for l in languages])
Jan Tattermusch14089202016-04-27 17:55:27 -0700402 prepare_remote_hosts(remote_hosts, prepare_local=True)
403else:
404 prepare_remote_hosts([], prepare_local=True)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700405
406build_local = False
407if not args.remote_driver_host:
408 build_local = True
Craig Tiller7797e3f2016-04-01 07:41:05 -0700409build_on_remote_hosts(remote_hosts, languages=[str(l) for l in languages], build_local=build_local)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700410
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700411qpsworker_jobs = start_qpsworkers(languages, args.remote_worker_host)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700412
Jan Tattermusch38becc22016-04-14 08:00:35 -0700413# TODO(jtattermusch): see https://github.com/grpc/grpc/issues/6174
414time.sleep(5)
415
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700416# get list of worker addresses for each language.
417worker_addresses = dict([(str(language), []) for language in languages])
418for job in qpsworker_jobs:
419 worker_addresses[str(job.language)].append(job.host_and_port)
Jan Tattermuschb2758442016-03-28 09:32:20 -0700420
421try:
Jan Tattermuschbb1a4532016-03-30 18:04:01 -0700422 scenarios = create_scenarios(languages,
423 workers_by_lang=worker_addresses,
Jan Tattermusch38becc22016-04-14 08:00:35 -0700424 remote_host=args.remote_driver_host,
Jan Tattermusch6d7fa552016-04-14 17:42:54 -0700425 regex=args.regex,
Jan Tattermusch427699b2016-05-05 18:10:14 -0700426 category=args.category,
Jan Tattermusch4de2c322016-05-10 14:33:07 -0700427 bq_result_table=args.bq_result_table,
428 netperf=args.netperf,
429 netperf_hosts=args.remote_worker_host)
430
Jan Tattermuschb2758442016-03-28 09:32:20 -0700431 if not scenarios:
432 raise Exception('No scenarios to run')
433
434 jobset.message('START', 'Running scenarios.', do_newline=True)
435 num_failures, _ = jobset.run(
436 scenarios, newline_on_success=True, maxjobs=1)
437 if num_failures == 0:
438 jobset.message('SUCCESS',
439 'All scenarios finished successfully.',
440 do_newline=True)
441 else:
442 jobset.message('FAILED', 'Some of the scenarios failed.',
443 do_newline=True)
444 sys.exit(1)
Jan Tattermuschee9032c2016-04-14 08:35:51 -0700445except:
446 traceback.print_exc()
Jan Tattermuschb688db02016-04-21 08:53:45 -0700447 raise
Jan Tattermuschb2758442016-03-28 09:32:20 -0700448finally:
449 finish_qps_workers(qpsworker_jobs)