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 | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 76 | cmdline = language.worker_cmdline() + ['--driver_port=%s' % port] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 77 | if remote_host: |
| 78 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 79 | cmdline = ['ssh', |
| 80 | str(user_at_host), |
| 81 | 'cd ~/performance_workspace/grpc/ && %s' % ' '.join(cmdline)] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 82 | host_and_port='%s:%s' % (remote_host, port) |
| 83 | else: |
| 84 | host_and_port='localhost:%s' % port |
| 85 | |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 86 | # 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 Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 88 | jobspec = jobset.JobSpec( |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 89 | cmdline=cmdline, |
| 90 | shortname=shortname, |
Jan Tattermusch | 541d5d7 | 2016-05-05 16:08:49 -0700 | [diff] [blame] | 91 | timeout_seconds=2*60*60) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 92 | return QpsWorkerJob(jobspec, language, host_and_port) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 93 | |
| 94 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 95 | def create_scenario_jobspec(scenario_json, workers, remote_host=None, |
| 96 | bq_result_table=None): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 97 | """Runs one scenario using QPS driver.""" |
| 98 | # 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] | 99 | 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 Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 105 | if remote_host: |
| 106 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 107 | 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] | 108 | |
| 109 | return jobset.JobSpec( |
| 110 | cmdline=[cmd], |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 111 | shortname='qps_json_driver.%s' % scenario_json['name'], |
| 112 | timeout_seconds=3*60, |
| 113 | shell=True, |
| 114 | verbose_success=True) |
| 115 | |
| 116 | |
| 117 | def 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. |
vjpai | 29089c7 | 2016-04-20 12:38:16 -0700 | [diff] [blame] | 120 | cmd = 'QPS_WORKERS="%s" bins/opt/qps_json_driver --quit' % ','.join(workers) |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 121 | if remote_host: |
| 122 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 123 | 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] | 124 | |
| 125 | return jobset.JobSpec( |
| 126 | cmdline=[cmd], |
vjpai | 29089c7 | 2016-04-20 12:38:16 -0700 | [diff] [blame] | 127 | shortname='qps_json_driver.quit', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 128 | timeout_seconds=3*60, |
| 129 | shell=True, |
| 130 | verbose_success=True) |
| 131 | |
| 132 | |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 133 | def 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 Tattermusch | ad17bf7 | 2016-05-11 12:41:37 -0700 | [diff] [blame] | 139 | 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 Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 150 | 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 Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 163 | def archive_repo(languages): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 164 | """Archives local version of repo including submodules.""" |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 165 | 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 Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 171 | archive_job = jobset.JobSpec( |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 172 | cmdline=cmdline, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 173 | 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 Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 181 | 'Archive with local repository created successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 182 | 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 Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 189 | def prepare_remote_hosts(hosts, prepare_local=False): |
| 190 | """Prepares remote hosts (and maybe prepare localhost as well).""" |
| 191 | prepare_timeout = 5*60 |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 192 | 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 Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 200 | 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 Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 209 | num_failures, _ = jobset.run( |
| 210 | prepare_jobs, newline_on_success=True, maxjobs=10) |
| 211 | if num_failures == 0: |
| 212 | jobset.message('SUCCESS', |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 213 | 'Prepare step completed successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 214 | 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 Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 221 | 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] | 222 | """Builds performance worker on remote hosts (and maybe also locally).""" |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 223 | 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 Tiller | 7797e3f | 2016-04-01 07:41:05 -0700 | [diff] [blame] | 229 | cmdline=['tools/run_tests/performance/remote_host_build.sh'] + languages, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 230 | 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 Tiller | 7797e3f | 2016-04-01 07:41:05 -0700 | [diff] [blame] | 237 | cmdline=['tools/run_tests/performance/build_performance.sh'] + languages, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 238 | shortname='local_build', |
| 239 | environ = {'CONFIG': 'opt'}, |
| 240 | timeout_seconds=build_timeout)) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 241 | jobset.message('START', 'Building.', do_newline=True) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 242 | num_failures, _ = jobset.run( |
| 243 | build_jobs, newline_on_success=True, maxjobs=10) |
| 244 | if num_failures == 0: |
| 245 | jobset.message('SUCCESS', |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 246 | 'Built successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 247 | do_newline=True) |
| 248 | else: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 249 | jobset.message('FAILED', 'Build failed.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 250 | do_newline=True) |
| 251 | sys.exit(1) |
| 252 | |
| 253 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 254 | def start_qpsworkers(languages, worker_hosts): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 255 | """Starts QPS workers as background jobs.""" |
| 256 | if not worker_hosts: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 257 | # run two workers locally (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 258 | workers=[(None, 10000), (None, 10010)] |
| 259 | elif len(worker_hosts) == 1: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 260 | # run two workers on the remote host (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 261 | workers=[(worker_hosts[0], 10000), (worker_hosts[0], 10010)] |
| 262 | else: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 263 | # run one worker per each remote host (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 264 | workers=[(worker_host, 10000) for worker_host in worker_hosts] |
| 265 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 266 | return [create_qpsworker_job(language, |
| 267 | shortname= 'qps_worker_%s_%s' % (language, |
| 268 | worker_idx), |
| 269 | port=worker[1] + language.worker_port_offset(), |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 270 | remote_host=worker[0]) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 271 | for language in languages |
| 272 | for worker_idx, worker in enumerate(workers)] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 273 | |
| 274 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 275 | def create_scenarios(languages, workers_by_lang, remote_host=None, regex='.*', |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 276 | category='all', bq_result_table=None, |
| 277 | netperf=False, netperf_hosts=[]): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 278 | """Create jobspecs for scenarios to run.""" |
Ken Payson | 0482c10 | 2016-04-19 12:08:34 -0700 | [diff] [blame] | 279 | all_workers = [worker |
| 280 | for workers in workers_by_lang.values() |
| 281 | for worker in workers] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 282 | scenarios = [] |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 283 | |
| 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 Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 298 | for language in languages: |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 299 | for scenario_json in language.scenarios(): |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 300 | if re.search(args.regex, scenario_json['name']): |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 301 | 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 Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 306 | custom_client_lang = scenario_json.get('CLIENT_LANGUAGE', None) |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 307 | scenario_json = scenario_config.remove_nonproto_fields(scenario_json) |
Jan Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 308 | 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 Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 311 | 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 Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 320 | 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 Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 330 | 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 Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 335 | |
| 336 | # the very last scenario requests shutting down the workers. |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 337 | scenarios.append(create_quit_jobspec(all_workers, remote_host=remote_host)) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 338 | return scenarios |
| 339 | |
| 340 | |
| 341 | def 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 | |
| 357 | argp = argparse.ArgumentParser(description='Run performance tests.') |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 358 | argp.add_argument('-l', '--language', |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 359 | choices=['all'] + sorted(scenario_config.LANGUAGES.keys()), |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 360 | nargs='+', |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 361 | required=True, |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 362 | help='Languages to benchmark.') |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 363 | argp.add_argument('--remote_driver_host', |
| 364 | default=None, |
| 365 | help='Run QPS driver on given host. By default, QPS driver is run locally.') |
| 366 | argp.add_argument('--remote_worker_host', |
| 367 | nargs='+', |
| 368 | default=[], |
| 369 | help='Worker hosts where to start QPS workers.') |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 370 | argp.add_argument('-r', '--regex', default='.*', type=str, |
| 371 | help='Regex to select scenarios to run.') |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 372 | argp.add_argument('--bq_result_table', default=None, type=str, |
| 373 | help='Bigquery "dataset.table" to upload results to.') |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 374 | argp.add_argument('--category', |
Jan Tattermusch | d27888b | 2016-05-19 16:11:11 -0700 | [diff] [blame^] | 375 | choices=['smoketest','all','scalable'], |
Jan Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 376 | default='all', |
| 377 | help='Select a category of tests to run.') |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 378 | argp.add_argument('--netperf', |
| 379 | default=False, |
| 380 | action='store_const', |
| 381 | const=True, |
| 382 | help='Run netperf benchmark as one of the scenarios.') |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 383 | |
| 384 | args = argp.parse_args() |
| 385 | |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 386 | languages = set(scenario_config.LANGUAGES[l] |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 387 | for l in itertools.chain.from_iterable( |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 388 | scenario_config.LANGUAGES.iterkeys() if x == 'all' else [x] |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 389 | for x in args.language)) |
| 390 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 391 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 392 | # Put together set of remote hosts where to run and build |
| 393 | remote_hosts = set() |
| 394 | if args.remote_worker_host: |
| 395 | for host in args.remote_worker_host: |
| 396 | remote_hosts.add(host) |
| 397 | if args.remote_driver_host: |
| 398 | remote_hosts.add(args.remote_driver_host) |
| 399 | |
| 400 | if remote_hosts: |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 401 | archive_repo(languages=[str(l) for l in languages]) |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 402 | prepare_remote_hosts(remote_hosts, prepare_local=True) |
| 403 | else: |
| 404 | prepare_remote_hosts([], prepare_local=True) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 405 | |
| 406 | build_local = False |
| 407 | if not args.remote_driver_host: |
| 408 | build_local = True |
Craig Tiller | 7797e3f | 2016-04-01 07:41:05 -0700 | [diff] [blame] | 409 | 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] | 410 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 411 | qpsworker_jobs = start_qpsworkers(languages, args.remote_worker_host) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 412 | |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 413 | # TODO(jtattermusch): see https://github.com/grpc/grpc/issues/6174 |
| 414 | time.sleep(5) |
| 415 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 416 | # get list of worker addresses for each language. |
| 417 | worker_addresses = dict([(str(language), []) for language in languages]) |
| 418 | for job in qpsworker_jobs: |
| 419 | worker_addresses[str(job.language)].append(job.host_and_port) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 420 | |
| 421 | try: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 422 | scenarios = create_scenarios(languages, |
| 423 | workers_by_lang=worker_addresses, |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 424 | remote_host=args.remote_driver_host, |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 425 | regex=args.regex, |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 426 | category=args.category, |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 427 | bq_result_table=args.bq_result_table, |
| 428 | netperf=args.netperf, |
| 429 | netperf_hosts=args.remote_worker_host) |
| 430 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 431 | 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 Tattermusch | ee9032c | 2016-04-14 08:35:51 -0700 | [diff] [blame] | 445 | except: |
| 446 | traceback.print_exc() |
Jan Tattermusch | b688db0 | 2016-04-21 08:53:45 -0700 | [diff] [blame] | 447 | raise |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 448 | finally: |
| 449 | finish_qps_workers(qpsworker_jobs) |