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