Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 1 | #!/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 | |
| 33 | import argparse |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 34 | import itertools |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 35 | import jobset |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 36 | import json |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 37 | import multiprocessing |
| 38 | import os |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 39 | import pipes |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 40 | import re |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 41 | import subprocess |
| 42 | import sys |
| 43 | import tempfile |
| 44 | import time |
Jan Tattermusch | ee9032c | 2016-04-14 08:35:51 -0700 | [diff] [blame] | 45 | import traceback |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 46 | import uuid |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 47 | import performance.scenario_config as scenario_config |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 48 | |
| 49 | |
| 50 | _ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 51 | os.chdir(_ROOT) |
| 52 | |
| 53 | |
| 54 | _REMOTE_HOST_USERNAME = 'jenkins' |
| 55 | |
| 56 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 57 | class QpsWorkerJob: |
| 58 | """Encapsulates a qps worker server job.""" |
| 59 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 60 | def __init__(self, spec, language, host_and_port): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 61 | self._spec = spec |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 62 | self.language = language |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 63 | self.host_and_port = host_and_port |
| 64 | self._job = jobset.Job(spec, bin_hash=None, newline_on_success=True, travis=True, add_env={}) |
| 65 | |
| 66 | def is_running(self): |
| 67 | """Polls a job and returns True if given job is still running.""" |
| 68 | return self._job.state(jobset.NoCache()) == jobset._RUNNING |
| 69 | |
| 70 | def kill(self): |
| 71 | return self._job.kill() |
| 72 | |
| 73 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 74 | def create_qpsworker_job(language, shortname=None, |
| 75 | port=10000, remote_host=None): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 76 | # TODO: support more languages |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 77 | cmdline = language.worker_cmdline() + ['--driver_port=%s' % port] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 78 | if remote_host: |
| 79 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 80 | cmdline = ['ssh', |
| 81 | str(user_at_host), |
| 82 | 'cd ~/performance_workspace/grpc/ && %s' % ' '.join(cmdline)] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 83 | host_and_port='%s:%s' % (remote_host, port) |
| 84 | else: |
| 85 | host_and_port='localhost:%s' % port |
| 86 | |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 87 | # TODO(jtattermusch): with some care, we can calculate the right timeout |
| 88 | # of a worker from the sum of warmup + benchmark times for all the scenarios |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 89 | jobspec = jobset.JobSpec( |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 90 | cmdline=cmdline, |
| 91 | shortname=shortname, |
Jan Tattermusch | 541d5d7 | 2016-05-05 16:08:49 -0700 | [diff] [blame] | 92 | timeout_seconds=2*60*60) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 93 | return QpsWorkerJob(jobspec, language, host_and_port) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 94 | |
| 95 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 96 | def create_scenario_jobspec(scenario_json, workers, remote_host=None, |
| 97 | bq_result_table=None): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 98 | """Runs one scenario using QPS driver.""" |
| 99 | # setting QPS_WORKERS env variable here makes sure it works with SSH too. |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 100 | cmd = 'QPS_WORKERS="%s" ' % ','.join(workers) |
| 101 | if bq_result_table: |
| 102 | cmd += 'BQ_RESULT_TABLE="%s" ' % bq_result_table |
| 103 | cmd += 'tools/run_tests/performance/run_qps_driver.sh ' |
| 104 | cmd += '--scenarios_json=%s ' % pipes.quote(json.dumps({'scenarios': [scenario_json]})) |
| 105 | cmd += '--scenario_result_file=scenario_result.json' |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 106 | if remote_host: |
| 107 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 108 | cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd)) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 109 | |
| 110 | return jobset.JobSpec( |
| 111 | cmdline=[cmd], |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 112 | shortname='qps_json_driver.%s' % scenario_json['name'], |
| 113 | timeout_seconds=3*60, |
| 114 | shell=True, |
| 115 | verbose_success=True) |
| 116 | |
| 117 | |
| 118 | def create_quit_jobspec(workers, remote_host=None): |
| 119 | """Runs quit using QPS driver.""" |
| 120 | # setting QPS_WORKERS env variable here makes sure it works with SSH too. |
vjpai | 29089c7 | 2016-04-20 12:38:16 -0700 | [diff] [blame] | 121 | cmd = 'QPS_WORKERS="%s" bins/opt/qps_json_driver --quit' % ','.join(workers) |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 122 | if remote_host: |
| 123 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 124 | cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd)) |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 125 | |
| 126 | return jobset.JobSpec( |
| 127 | cmdline=[cmd], |
vjpai | 29089c7 | 2016-04-20 12:38:16 -0700 | [diff] [blame] | 128 | shortname='qps_json_driver.quit', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 129 | timeout_seconds=3*60, |
| 130 | shell=True, |
| 131 | verbose_success=True) |
| 132 | |
| 133 | |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 134 | def archive_repo(languages): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 135 | """Archives local version of repo including submodules.""" |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 136 | cmdline=['tar', '-cf', '../grpc.tar', '../grpc/'] |
| 137 | if 'java' in languages: |
| 138 | cmdline.append('../grpc-java') |
| 139 | if 'go' in languages: |
| 140 | cmdline.append('../grpc-go') |
| 141 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 142 | archive_job = jobset.JobSpec( |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 143 | cmdline=cmdline, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 144 | shortname='archive_repo', |
| 145 | timeout_seconds=3*60) |
| 146 | |
| 147 | jobset.message('START', 'Archiving local repository.', do_newline=True) |
| 148 | num_failures, _ = jobset.run( |
| 149 | [archive_job], newline_on_success=True, maxjobs=1) |
| 150 | if num_failures == 0: |
| 151 | jobset.message('SUCCESS', |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 152 | 'Archive with local repository created successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 153 | do_newline=True) |
| 154 | else: |
| 155 | jobset.message('FAILED', 'Failed to archive local repository.', |
| 156 | do_newline=True) |
| 157 | sys.exit(1) |
| 158 | |
| 159 | |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 160 | def prepare_remote_hosts(hosts, prepare_local=False): |
| 161 | """Prepares remote hosts (and maybe prepare localhost as well).""" |
| 162 | prepare_timeout = 5*60 |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 163 | prepare_jobs = [] |
| 164 | for host in hosts: |
| 165 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, host) |
| 166 | prepare_jobs.append( |
| 167 | jobset.JobSpec( |
| 168 | cmdline=['tools/run_tests/performance/remote_host_prepare.sh'], |
| 169 | shortname='remote_host_prepare.%s' % host, |
| 170 | environ = {'USER_AT_HOST': user_at_host}, |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 171 | timeout_seconds=prepare_timeout)) |
| 172 | if prepare_local: |
| 173 | # Prepare localhost as well |
| 174 | prepare_jobs.append( |
| 175 | jobset.JobSpec( |
| 176 | cmdline=['tools/run_tests/performance/kill_workers.sh'], |
| 177 | shortname='local_prepare', |
| 178 | timeout_seconds=prepare_timeout)) |
| 179 | jobset.message('START', 'Preparing hosts.', do_newline=True) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 180 | num_failures, _ = jobset.run( |
| 181 | prepare_jobs, newline_on_success=True, maxjobs=10) |
| 182 | if num_failures == 0: |
| 183 | jobset.message('SUCCESS', |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 184 | 'Prepare step completed successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 185 | do_newline=True) |
| 186 | else: |
| 187 | jobset.message('FAILED', 'Failed to prepare remote hosts.', |
| 188 | do_newline=True) |
| 189 | sys.exit(1) |
| 190 | |
| 191 | |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 192 | def build_on_remote_hosts(hosts, languages=scenario_config.LANGUAGES.keys(), build_local=False): |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 193 | """Builds performance worker on remote hosts (and maybe also locally).""" |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 194 | build_timeout = 15*60 |
| 195 | build_jobs = [] |
| 196 | for host in hosts: |
| 197 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, host) |
| 198 | build_jobs.append( |
| 199 | jobset.JobSpec( |
Craig Tiller | 7797e3f | 2016-04-01 07:41:05 -0700 | [diff] [blame] | 200 | cmdline=['tools/run_tests/performance/remote_host_build.sh'] + languages, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 201 | shortname='remote_host_build.%s' % host, |
| 202 | environ = {'USER_AT_HOST': user_at_host, 'CONFIG': 'opt'}, |
| 203 | timeout_seconds=build_timeout)) |
| 204 | if build_local: |
| 205 | # Build locally as well |
| 206 | build_jobs.append( |
| 207 | jobset.JobSpec( |
Craig Tiller | 7797e3f | 2016-04-01 07:41:05 -0700 | [diff] [blame] | 208 | cmdline=['tools/run_tests/performance/build_performance.sh'] + languages, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 209 | shortname='local_build', |
| 210 | environ = {'CONFIG': 'opt'}, |
| 211 | timeout_seconds=build_timeout)) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 212 | jobset.message('START', 'Building.', do_newline=True) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 213 | num_failures, _ = jobset.run( |
| 214 | build_jobs, newline_on_success=True, maxjobs=10) |
| 215 | if num_failures == 0: |
| 216 | jobset.message('SUCCESS', |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 217 | 'Built successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 218 | do_newline=True) |
| 219 | else: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 220 | jobset.message('FAILED', 'Build failed.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 221 | do_newline=True) |
| 222 | sys.exit(1) |
| 223 | |
| 224 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 225 | def start_qpsworkers(languages, worker_hosts): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 226 | """Starts QPS workers as background jobs.""" |
| 227 | if not worker_hosts: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 228 | # run two workers locally (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 229 | workers=[(None, 10000), (None, 10010)] |
| 230 | elif len(worker_hosts) == 1: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 231 | # run two workers on the remote host (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 232 | workers=[(worker_hosts[0], 10000), (worker_hosts[0], 10010)] |
| 233 | else: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 234 | # run one worker per each remote host (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 235 | workers=[(worker_host, 10000) for worker_host in worker_hosts] |
| 236 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 237 | return [create_qpsworker_job(language, |
| 238 | shortname= 'qps_worker_%s_%s' % (language, |
| 239 | worker_idx), |
| 240 | port=worker[1] + language.worker_port_offset(), |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 241 | remote_host=worker[0]) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 242 | for language in languages |
| 243 | for worker_idx, worker in enumerate(workers)] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 244 | |
| 245 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 246 | def create_scenarios(languages, workers_by_lang, remote_host=None, regex='.*', |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame^] | 247 | category='all', bq_result_table=None): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 248 | """Create jobspecs for scenarios to run.""" |
Ken Payson | 0482c10 | 2016-04-19 12:08:34 -0700 | [diff] [blame] | 249 | all_workers = [worker |
| 250 | for workers in workers_by_lang.values() |
| 251 | for worker in workers] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 252 | scenarios = [] |
| 253 | for language in languages: |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 254 | for scenario_json in language.scenarios(): |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 255 | if re.search(args.regex, scenario_json['name']): |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame^] | 256 | if category in scenario_json.get('CATEGORIES', []) or category == 'all': |
| 257 | workers = workers_by_lang[str(language)] |
| 258 | # 'SERVER_LANGUAGE' is an indicator for this script to pick |
| 259 | # a server in different language. |
| 260 | custom_server_lang = scenario_json.get('SERVER_LANGUAGE', None) |
| 261 | scenario_json = scenario_config.remove_nonproto_fields(scenario_json) |
| 262 | if custom_server_lang: |
| 263 | if not workers_by_lang.get(custom_server_lang, []): |
| 264 | print 'Warning: Skipping scenario %s as' % scenario_json['name'] |
| 265 | print('SERVER_LANGUAGE is set to %s yet the language has ' |
| 266 | 'not been selected with -l' % custom_server_lang) |
| 267 | continue |
| 268 | for idx in range(0, scenario_json['num_servers']): |
| 269 | # replace first X workers by workers of a different language |
| 270 | workers[idx] = workers_by_lang[custom_server_lang][idx] |
| 271 | scenario = create_scenario_jobspec(scenario_json, |
| 272 | workers, |
| 273 | remote_host=remote_host, |
| 274 | bq_result_table=bq_result_table) |
| 275 | scenarios.append(scenario) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 276 | |
| 277 | # the very last scenario requests shutting down the workers. |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 278 | scenarios.append(create_quit_jobspec(all_workers, remote_host=remote_host)) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 279 | return scenarios |
| 280 | |
| 281 | |
| 282 | def finish_qps_workers(jobs): |
| 283 | """Waits for given jobs to finish and eventually kills them.""" |
| 284 | retries = 0 |
| 285 | while any(job.is_running() for job in jobs): |
| 286 | for job in qpsworker_jobs: |
| 287 | if job.is_running(): |
| 288 | print 'QPS worker "%s" is still running.' % job.host_and_port |
| 289 | if retries > 10: |
| 290 | print 'Killing all QPS workers.' |
| 291 | for job in jobs: |
| 292 | job.kill() |
| 293 | retries += 1 |
| 294 | time.sleep(3) |
| 295 | print 'All QPS workers finished.' |
| 296 | |
| 297 | |
| 298 | argp = argparse.ArgumentParser(description='Run performance tests.') |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 299 | argp.add_argument('-l', '--language', |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 300 | choices=['all'] + sorted(scenario_config.LANGUAGES.keys()), |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 301 | nargs='+', |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame^] | 302 | required=True, |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 303 | help='Languages to benchmark.') |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 304 | argp.add_argument('--remote_driver_host', |
| 305 | default=None, |
| 306 | help='Run QPS driver on given host. By default, QPS driver is run locally.') |
| 307 | argp.add_argument('--remote_worker_host', |
| 308 | nargs='+', |
| 309 | default=[], |
| 310 | help='Worker hosts where to start QPS workers.') |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 311 | argp.add_argument('-r', '--regex', default='.*', type=str, |
| 312 | help='Regex to select scenarios to run.') |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 313 | argp.add_argument('--bq_result_table', default=None, type=str, |
| 314 | help='Bigquery "dataset.table" to upload results to.') |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame^] | 315 | argp.add_argument('--category', |
| 316 | choices=['smoketest','all'], |
| 317 | default='smoketest', |
| 318 | help='Select a category of tests to run. Smoketest runs by default.') |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 319 | |
| 320 | args = argp.parse_args() |
| 321 | |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 322 | languages = set(scenario_config.LANGUAGES[l] |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 323 | for l in itertools.chain.from_iterable( |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 324 | scenario_config.LANGUAGES.iterkeys() if x == 'all' else [x] |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 325 | for x in args.language)) |
| 326 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 327 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 328 | # Put together set of remote hosts where to run and build |
| 329 | remote_hosts = set() |
| 330 | if args.remote_worker_host: |
| 331 | for host in args.remote_worker_host: |
| 332 | remote_hosts.add(host) |
| 333 | if args.remote_driver_host: |
| 334 | remote_hosts.add(args.remote_driver_host) |
| 335 | |
| 336 | if remote_hosts: |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 337 | archive_repo(languages=[str(l) for l in languages]) |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 338 | prepare_remote_hosts(remote_hosts, prepare_local=True) |
| 339 | else: |
| 340 | prepare_remote_hosts([], prepare_local=True) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 341 | |
| 342 | build_local = False |
| 343 | if not args.remote_driver_host: |
| 344 | build_local = True |
Craig Tiller | 7797e3f | 2016-04-01 07:41:05 -0700 | [diff] [blame] | 345 | build_on_remote_hosts(remote_hosts, languages=[str(l) for l in languages], build_local=build_local) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 346 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 347 | qpsworker_jobs = start_qpsworkers(languages, args.remote_worker_host) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 348 | |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 349 | # TODO(jtattermusch): see https://github.com/grpc/grpc/issues/6174 |
| 350 | time.sleep(5) |
| 351 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 352 | # get list of worker addresses for each language. |
| 353 | worker_addresses = dict([(str(language), []) for language in languages]) |
| 354 | for job in qpsworker_jobs: |
| 355 | worker_addresses[str(job.language)].append(job.host_and_port) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 356 | |
| 357 | try: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 358 | scenarios = create_scenarios(languages, |
| 359 | workers_by_lang=worker_addresses, |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 360 | remote_host=args.remote_driver_host, |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 361 | regex=args.regex, |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame^] | 362 | category=args.category, |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 363 | bq_result_table=args.bq_result_table) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 364 | if not scenarios: |
| 365 | raise Exception('No scenarios to run') |
| 366 | |
| 367 | jobset.message('START', 'Running scenarios.', do_newline=True) |
| 368 | num_failures, _ = jobset.run( |
| 369 | scenarios, newline_on_success=True, maxjobs=1) |
| 370 | if num_failures == 0: |
| 371 | jobset.message('SUCCESS', |
| 372 | 'All scenarios finished successfully.', |
| 373 | do_newline=True) |
| 374 | else: |
| 375 | jobset.message('FAILED', 'Some of the scenarios failed.', |
| 376 | do_newline=True) |
| 377 | sys.exit(1) |
Jan Tattermusch | ee9032c | 2016-04-14 08:35:51 -0700 | [diff] [blame] | 378 | except: |
| 379 | traceback.print_exc() |
Jan Tattermusch | b688db0 | 2016-04-21 08:53:45 -0700 | [diff] [blame] | 380 | raise |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 381 | finally: |
| 382 | finish_qps_workers(qpsworker_jobs) |