Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Vijay Pai | d02dd30 | 2016-01-27 11:23:34 -0800 | [diff] [blame] | 34 | #include <deque> |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 35 | #include <list> |
| 36 | #include <thread> |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 37 | #include <unordered_map> |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 38 | #include <vector> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 39 | |
David Garcia Quintas | 6a48405 | 2016-01-25 19:12:37 -0800 | [diff] [blame] | 40 | #include <grpc++/channel.h> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 41 | #include <grpc++/client_context.h> |
| 42 | #include <grpc++/create_channel.h> |
Vijay Pai | d02dd30 | 2016-01-27 11:23:34 -0800 | [diff] [blame] | 43 | #include <grpc/support/alloc.h> |
| 44 | #include <grpc/support/host_port.h> |
| 45 | #include <grpc/support/log.h> |
vjpai | 6332628 | 2016-03-14 17:12:52 -0700 | [diff] [blame] | 46 | #include <gtest/gtest.h> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 47 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 48 | #include "src/core/lib/support/env.h" |
Vijay Pai | d02dd30 | 2016-01-27 11:23:34 -0800 | [diff] [blame] | 49 | #include "src/proto/grpc/testing/services.grpc.pb.h" |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 50 | #include "test/core/util/port.h" |
Craig Tiller | 882431f | 2015-05-19 09:25:37 -0700 | [diff] [blame] | 51 | #include "test/core/util/test_config.h" |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 52 | #include "test/cpp/qps/driver.h" |
| 53 | #include "test/cpp/qps/histogram.h" |
| 54 | #include "test/cpp/qps/qps_worker.h" |
Jan Tattermusch | 33c161d | 2016-04-15 14:45:49 -0700 | [diff] [blame] | 55 | #include "test/cpp/qps/stats.h" |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 56 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 57 | using std::list; |
| 58 | using std::thread; |
| 59 | using std::unique_ptr; |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 60 | using std::deque; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 61 | using std::vector; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 62 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 63 | namespace grpc { |
| 64 | namespace testing { |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 65 | static std::string get_host(const std::string& worker) { |
| 66 | char* host; |
| 67 | char* port; |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 68 | |
| 69 | gpr_split_host_port(worker.c_str(), &host, &port); |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 70 | const string s(host); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 71 | |
| 72 | gpr_free(host); |
| 73 | gpr_free(port); |
| 74 | return s; |
| 75 | } |
| 76 | |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 77 | static std::unordered_map<string, std::deque<int>> get_hosts_and_cores( |
| 78 | const deque<string>& workers) { |
| 79 | std::unordered_map<string, std::deque<int>> hosts; |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 80 | for (auto it = workers.begin(); it != workers.end(); it++) { |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 81 | const string host = get_host(*it); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 82 | if (hosts.find(host) == hosts.end()) { |
| 83 | auto stub = WorkerService::NewStub( |
| 84 | CreateChannel(*it, InsecureChannelCredentials())); |
| 85 | grpc::ClientContext ctx; |
| 86 | CoreRequest dummy; |
| 87 | CoreResponse cores; |
| 88 | grpc::Status s = stub->CoreCount(&ctx, dummy, &cores); |
| 89 | assert(s.ok()); |
| 90 | std::deque<int> dq; |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 91 | for (int i = 0; i < cores.cores(); i++) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 92 | dq.push_back(i); |
| 93 | } |
| 94 | hosts[host] = dq; |
| 95 | } |
| 96 | } |
| 97 | return hosts; |
| 98 | } |
| 99 | |
| 100 | static deque<string> get_workers(const string& name) { |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 101 | char* env = gpr_getenv(name.c_str()); |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 102 | if (!env) return deque<string>(); |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 103 | |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 104 | deque<string> out; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 105 | char* p = env; |
| 106 | for (;;) { |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 107 | char* comma = strchr(p, ','); |
| 108 | if (comma) { |
| 109 | out.emplace_back(p, comma); |
| 110 | p = comma + 1; |
| 111 | } else { |
| 112 | out.emplace_back(p); |
| 113 | gpr_free(env); |
| 114 | return out; |
| 115 | } |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
Jan Tattermusch | 33c161d | 2016-04-15 14:45:49 -0700 | [diff] [blame] | 119 | // helpers for postprocess_scenario_result |
| 120 | static double WallTime(ClientStats s) { return s.time_elapsed(); } |
| 121 | static double SystemTime(ClientStats s) { return s.time_system(); } |
| 122 | static double UserTime(ClientStats s) { return s.time_user(); } |
| 123 | static double ServerWallTime(ServerStats s) { return s.time_elapsed(); } |
| 124 | static double ServerSystemTime(ServerStats s) { return s.time_system(); } |
| 125 | static double ServerUserTime(ServerStats s) { return s.time_user(); } |
| 126 | static int Cores(int n) { return n; } |
| 127 | |
| 128 | // Postprocess ScenarioResult and populate result summary. |
| 129 | static void postprocess_scenario_result(ScenarioResult* result) { |
| 130 | Histogram histogram; |
| 131 | histogram.MergeProto(result->latencies()); |
| 132 | |
| 133 | auto qps = histogram.Count() / average(result->client_stats(), WallTime); |
| 134 | auto qps_per_server_core = qps / sum(result->server_cores(), Cores); |
| 135 | |
| 136 | result->mutable_summary()->set_qps(qps); |
| 137 | result->mutable_summary()->set_qps_per_server_core(qps_per_server_core); |
| 138 | result->mutable_summary()->set_latency_50(histogram.Percentile(50)); |
| 139 | result->mutable_summary()->set_latency_90(histogram.Percentile(90)); |
| 140 | result->mutable_summary()->set_latency_95(histogram.Percentile(95)); |
| 141 | result->mutable_summary()->set_latency_99(histogram.Percentile(99)); |
| 142 | result->mutable_summary()->set_latency_999(histogram.Percentile(99.9)); |
| 143 | |
Jan Tattermusch | e9a8d89 | 2016-04-15 15:38:17 -0700 | [diff] [blame] | 144 | auto server_system_time = 100.0 * |
| 145 | sum(result->server_stats(), ServerSystemTime) / |
| 146 | sum(result->server_stats(), ServerWallTime); |
Jan Tattermusch | 33c161d | 2016-04-15 14:45:49 -0700 | [diff] [blame] | 147 | auto server_user_time = 100.0 * sum(result->server_stats(), ServerUserTime) / |
Jan Tattermusch | e9a8d89 | 2016-04-15 15:38:17 -0700 | [diff] [blame] | 148 | sum(result->server_stats(), ServerWallTime); |
Jan Tattermusch | 33c161d | 2016-04-15 14:45:49 -0700 | [diff] [blame] | 149 | auto client_system_time = 100.0 * sum(result->client_stats(), SystemTime) / |
Jan Tattermusch | e9a8d89 | 2016-04-15 15:38:17 -0700 | [diff] [blame] | 150 | sum(result->client_stats(), WallTime); |
Jan Tattermusch | 33c161d | 2016-04-15 14:45:49 -0700 | [diff] [blame] | 151 | auto client_user_time = 100.0 * sum(result->client_stats(), UserTime) / |
Jan Tattermusch | e9a8d89 | 2016-04-15 15:38:17 -0700 | [diff] [blame] | 152 | sum(result->client_stats(), WallTime); |
Jan Tattermusch | 33c161d | 2016-04-15 14:45:49 -0700 | [diff] [blame] | 153 | |
| 154 | result->mutable_summary()->set_server_system_time(server_system_time); |
| 155 | result->mutable_summary()->set_server_user_time(server_user_time); |
| 156 | result->mutable_summary()->set_client_system_time(client_system_time); |
| 157 | result->mutable_summary()->set_client_user_time(client_user_time); |
| 158 | } |
| 159 | |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 160 | // Namespace for classes and functions used only in RunScenario |
| 161 | // Using this rather than local definitions to workaround gcc-4.4 limitations |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 162 | // regarding using templates without linkage |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 163 | namespace runsc { |
| 164 | |
| 165 | // ClientContext allocator |
vjpai | 6332628 | 2016-03-14 17:12:52 -0700 | [diff] [blame] | 166 | static ClientContext* AllocContext(list<ClientContext>* contexts) { |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 167 | contexts->emplace_back(); |
Craig Tiller | b17b7f4 | 2015-10-07 08:48:51 -0700 | [diff] [blame] | 168 | auto context = &contexts->back(); |
Craig Tiller | b17b7f4 | 2015-10-07 08:48:51 -0700 | [diff] [blame] | 169 | return context; |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | struct ServerData { |
vjpai | 119c103 | 2015-10-29 01:21:04 -0700 | [diff] [blame] | 173 | unique_ptr<WorkerService::Stub> stub; |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 174 | unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; |
| 175 | }; |
| 176 | |
| 177 | struct ClientData { |
vjpai | 119c103 | 2015-10-29 01:21:04 -0700 | [diff] [blame] | 178 | unique_ptr<WorkerService::Stub> stub; |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 179 | unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; |
| 180 | }; |
Vijay Pai | 3ae1104 | 2015-08-11 22:43:14 -0700 | [diff] [blame] | 181 | } // namespace runsc |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 182 | |
David Garcia Quintas | 0811650 | 2015-05-20 17:27:23 -0700 | [diff] [blame] | 183 | std::unique_ptr<ScenarioResult> RunScenario( |
| 184 | const ClientConfig& initial_client_config, size_t num_clients, |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 185 | const ServerConfig& initial_server_config, size_t num_servers, |
| 186 | int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count) { |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 187 | // ClientContext allocations (all are destroyed at scope exit) |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 188 | list<ClientContext> contexts; |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 189 | |
David Garcia Quintas | 6ba29ba | 2015-05-19 18:29:35 -0700 | [diff] [blame] | 190 | // To be added to the result, containing the final configuration used for |
Jan Tattermusch | c5ebbd5 | 2015-11-18 16:50:47 -0800 | [diff] [blame] | 191 | // client and config (including host, etc.) |
David Garcia Quintas | 6ba29ba | 2015-05-19 18:29:35 -0700 | [diff] [blame] | 192 | ClientConfig result_client_config; |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 193 | const ServerConfig result_server_config = initial_server_config; |
David Garcia Quintas | 6ba29ba | 2015-05-19 18:29:35 -0700 | [diff] [blame] | 194 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 195 | // Get client, server lists |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 196 | auto workers = get_workers("QPS_WORKERS"); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 197 | ClientConfig client_config = initial_client_config; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 198 | |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 199 | // Spawn some local workers if desired |
| 200 | vector<unique_ptr<QpsWorker>> local_workers; |
| 201 | for (int i = 0; i < abs(spawn_local_worker_count); i++) { |
Craig Tiller | 49c3b01 | 2015-05-19 08:18:02 -0700 | [diff] [blame] | 202 | // act as if we're a new test -- gets a good rng seed |
| 203 | static bool called_init = false; |
| 204 | if (!called_init) { |
Craig Tiller | 882431f | 2015-05-19 09:25:37 -0700 | [diff] [blame] | 205 | char args_buf[100]; |
| 206 | strcpy(args_buf, "some-benchmark"); |
Craig Tiller | 5c8737d | 2015-05-21 11:42:17 -0700 | [diff] [blame] | 207 | char* args[] = {args_buf}; |
Craig Tiller | 49c3b01 | 2015-05-19 08:18:02 -0700 | [diff] [blame] | 208 | grpc_test_init(1, args); |
| 209 | called_init = true; |
| 210 | } |
| 211 | |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 212 | int driver_port = grpc_pick_unused_port_or_die(); |
vjpai | 72a6332 | 2015-10-29 02:23:11 -0700 | [diff] [blame] | 213 | local_workers.emplace_back(new QpsWorker(driver_port)); |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 214 | char addr[256]; |
| 215 | sprintf(addr, "localhost:%d", driver_port); |
| 216 | if (spawn_local_worker_count < 0) { |
| 217 | workers.push_front(addr); |
| 218 | } else { |
| 219 | workers.push_back(addr); |
| 220 | } |
| 221 | } |
| 222 | |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 223 | // Setup the hosts and core counts |
| 224 | auto hosts_cores = get_hosts_and_cores(workers); |
| 225 | |
Vijay Pai | d02dd30 | 2016-01-27 11:23:34 -0800 | [diff] [blame] | 226 | // if num_clients is set to <=0, do dynamic sizing: all workers |
| 227 | // except for servers are clients |
| 228 | if (num_clients <= 0) { |
| 229 | num_clients = workers.size() - num_servers; |
| 230 | } |
| 231 | |
Craig Tiller | 10923c2 | 2015-03-03 14:24:49 -0800 | [diff] [blame] | 232 | // TODO(ctiller): support running multiple configurations, and binpack |
| 233 | // client/server pairs |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 234 | // to available workers |
| 235 | GPR_ASSERT(workers.size() >= num_clients + num_servers); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 236 | |
| 237 | // Trim to just what we need |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 238 | workers.resize(num_clients + num_servers); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 239 | |
| 240 | // Start servers |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 241 | using runsc::ServerData; |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 242 | // servers is array rather than std::vector to avoid gcc-4.4 issues |
| 243 | // where class contained in std::vector must have a copy constructor |
vjpai | b1db869 | 2015-08-11 22:41:02 -0700 | [diff] [blame] | 244 | auto* servers = new ServerData[num_servers]; |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 245 | for (size_t i = 0; i < num_servers; i++) { |
vjpai | 94aada9 | 2016-01-26 18:12:30 -0800 | [diff] [blame] | 246 | gpr_log(GPR_INFO, "Starting server on %s (worker #%d)", workers[i].c_str(), |
vjpai | 0c31b60 | 2016-01-27 09:03:18 -0800 | [diff] [blame] | 247 | i); |
Julien Boeuf | 6049ebd | 2015-11-17 16:53:52 -0800 | [diff] [blame] | 248 | servers[i].stub = WorkerService::NewStub( |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 249 | CreateChannel(workers[i], InsecureChannelCredentials())); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 250 | |
| 251 | ServerConfig server_config = initial_server_config; |
| 252 | char* host; |
| 253 | char* driver_port; |
| 254 | char* cli_target; |
| 255 | gpr_split_host_port(workers[i].c_str(), &host, &driver_port); |
| 256 | string host_str(host); |
| 257 | int server_core_limit = initial_server_config.core_limit(); |
| 258 | int client_core_limit = initial_client_config.core_limit(); |
| 259 | |
| 260 | if (server_core_limit == 0 && client_core_limit > 0) { |
| 261 | // In this case, limit the server cores if it matches the |
| 262 | // same host as one or more clients |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 263 | const auto& dq = hosts_cores.at(host_str); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 264 | bool match = false; |
| 265 | int limit = dq.size(); |
| 266 | for (size_t cli = 0; cli < num_clients; cli++) { |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 267 | if (host_str == get_host(workers[cli + num_servers])) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 268 | limit -= client_core_limit; |
| 269 | match = true; |
| 270 | } |
| 271 | } |
| 272 | if (match) { |
| 273 | GPR_ASSERT(limit > 0); |
| 274 | server_core_limit = limit; |
| 275 | } |
| 276 | } |
| 277 | if (server_core_limit > 0) { |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 278 | auto& dq = hosts_cores.at(host_str); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 279 | GPR_ASSERT(dq.size() >= static_cast<size_t>(server_core_limit)); |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 280 | for (int core = 0; core < server_core_limit; core++) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 281 | server_config.add_core_list(dq.front()); |
| 282 | dq.pop_front(); |
| 283 | } |
| 284 | } |
| 285 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 286 | ServerArgs args; |
| 287 | *args.mutable_setup() = server_config; |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 288 | servers[i].stream = |
vjpai | 6332628 | 2016-03-14 17:12:52 -0700 | [diff] [blame] | 289 | servers[i].stub->RunServer(runsc::AllocContext(&contexts)); |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 290 | GPR_ASSERT(servers[i].stream->Write(args)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 291 | ServerStatus init_status; |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 292 | GPR_ASSERT(servers[i].stream->Read(&init_status)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 293 | gpr_join_host_port(&cli_target, host, init_status.port()); |
| 294 | client_config.add_server_targets(cli_target); |
| 295 | gpr_free(host); |
| 296 | gpr_free(driver_port); |
| 297 | gpr_free(cli_target); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 300 | // Targets are all set by now |
| 301 | result_client_config = client_config; |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 302 | // Start clients |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 303 | using runsc::ClientData; |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 304 | // clients is array rather than std::vector to avoid gcc-4.4 issues |
| 305 | // where class contained in std::vector must have a copy constructor |
vjpai | b1db869 | 2015-08-11 22:41:02 -0700 | [diff] [blame] | 306 | auto* clients = new ClientData[num_clients]; |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 307 | for (size_t i = 0; i < num_clients; i++) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 308 | const auto& worker = workers[i + num_servers]; |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 309 | gpr_log(GPR_INFO, "Starting client on %s (worker #%d)", worker.c_str(), |
| 310 | i + num_servers); |
Julien Boeuf | 6049ebd | 2015-11-17 16:53:52 -0800 | [diff] [blame] | 311 | clients[i].stub = WorkerService::NewStub( |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 312 | CreateChannel(worker, InsecureChannelCredentials())); |
| 313 | ClientConfig per_client_config = client_config; |
| 314 | |
| 315 | int server_core_limit = initial_server_config.core_limit(); |
| 316 | int client_core_limit = initial_client_config.core_limit(); |
| 317 | if ((server_core_limit > 0) || (client_core_limit > 0)) { |
Vijay Pai | daadcc8 | 2016-02-01 16:49:55 -0800 | [diff] [blame] | 318 | auto& dq = hosts_cores.at(get_host(worker)); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 319 | if (client_core_limit == 0) { |
| 320 | // limit client cores if it matches a server host |
| 321 | bool match = false; |
| 322 | int limit = dq.size(); |
| 323 | for (size_t srv = 0; srv < num_servers; srv++) { |
| 324 | if (get_host(worker) == get_host(workers[srv])) { |
| 325 | match = true; |
| 326 | } |
| 327 | } |
| 328 | if (match) { |
Vijay Pai | 6b05639 | 2016-02-01 13:01:34 -0800 | [diff] [blame] | 329 | GPR_ASSERT(limit > 0); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 330 | client_core_limit = limit; |
| 331 | } |
| 332 | } |
| 333 | if (client_core_limit > 0) { |
| 334 | GPR_ASSERT(dq.size() >= static_cast<size_t>(client_core_limit)); |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 335 | for (int core = 0; core < client_core_limit; core++) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 336 | per_client_config.add_core_list(dq.front()); |
| 337 | dq.pop_front(); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 342 | ClientArgs args; |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 343 | *args.mutable_setup() = per_client_config; |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 344 | clients[i].stream = |
vjpai | 6332628 | 2016-03-14 17:12:52 -0700 | [diff] [blame] | 345 | clients[i].stub->RunClient(runsc::AllocContext(&contexts)); |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 346 | GPR_ASSERT(clients[i].stream->Write(args)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 347 | ClientStatus init_status; |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 348 | GPR_ASSERT(clients[i].stream->Read(&init_status)); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 349 | } |
| 350 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 351 | // Let everything warmup |
| 352 | gpr_log(GPR_INFO, "Warming up"); |
Craig Tiller | 20b5fe9 | 2015-07-06 10:43:50 -0700 | [diff] [blame] | 353 | gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); |
Craig Tiller | 677c50c | 2015-07-13 10:49:06 -0700 | [diff] [blame] | 354 | gpr_sleep_until( |
| 355 | gpr_time_add(start, gpr_time_from_seconds(warmup_seconds, GPR_TIMESPAN))); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 356 | |
| 357 | // Start a run |
| 358 | gpr_log(GPR_INFO, "Starting"); |
| 359 | ServerArgs server_mark; |
vjpai | 119c103 | 2015-10-29 01:21:04 -0700 | [diff] [blame] | 360 | server_mark.mutable_mark()->set_reset(true); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 361 | ClientArgs client_mark; |
vjpai | 119c103 | 2015-10-29 01:21:04 -0700 | [diff] [blame] | 362 | client_mark.mutable_mark()->set_reset(true); |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 363 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 364 | GPR_ASSERT(server->stream->Write(server_mark)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 365 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 366 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 367 | GPR_ASSERT(client->stream->Write(client_mark)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 368 | } |
| 369 | ServerStatus server_status; |
| 370 | ClientStatus client_status; |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 371 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 372 | GPR_ASSERT(server->stream->Read(&server_status)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 373 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 374 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 375 | GPR_ASSERT(client->stream->Read(&client_status)); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 378 | // Wait some time |
| 379 | gpr_log(GPR_INFO, "Running"); |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 380 | // Use gpr_sleep_until rather than this_thread::sleep_until to support |
| 381 | // compilers that don't work with this_thread |
Craig Tiller | 677c50c | 2015-07-13 10:49:06 -0700 | [diff] [blame] | 382 | gpr_sleep_until(gpr_time_add( |
Vijay Pai | 847baf6 | 2016-03-14 17:23:50 -0700 | [diff] [blame] | 383 | start, |
| 384 | gpr_time_from_seconds(warmup_seconds + benchmark_seconds, GPR_TIMESPAN))); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 385 | |
| 386 | // Finish a run |
David Garcia Quintas | 0811650 | 2015-05-20 17:27:23 -0700 | [diff] [blame] | 387 | std::unique_ptr<ScenarioResult> result(new ScenarioResult); |
Jan Tattermusch | f2ba7fe | 2016-04-14 12:14:17 -0700 | [diff] [blame] | 388 | Histogram merged_latencies; |
| 389 | |
vjpai | 60a7e33 | 2016-02-26 10:30:17 -0800 | [diff] [blame] | 390 | gpr_log(GPR_INFO, "Finishing clients"); |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 391 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 392 | GPR_ASSERT(client->stream->Write(client_mark)); |
Vijay Pai | 02eda41 | 2016-02-25 19:43:57 -0800 | [diff] [blame] | 393 | GPR_ASSERT(client->stream->WritesDone()); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 394 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 395 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 396 | GPR_ASSERT(client->stream->Read(&client_status)); |
Craig Tiller | f282514 | 2015-03-03 17:15:36 -0800 | [diff] [blame] | 397 | const auto& stats = client_status.stats(); |
Jan Tattermusch | f2ba7fe | 2016-04-14 12:14:17 -0700 | [diff] [blame] | 398 | merged_latencies.MergeProto(stats.latencies()); |
| 399 | result->add_client_stats()->CopyFrom(stats); |
Vijay Pai | 02eda41 | 2016-02-25 19:43:57 -0800 | [diff] [blame] | 400 | GPR_ASSERT(!client->stream->Read(&client_status)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 401 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 402 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 403 | GPR_ASSERT(client->stream->Finish().ok()); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 404 | } |
vjpai | 60a7e33 | 2016-02-26 10:30:17 -0800 | [diff] [blame] | 405 | delete[] clients; |
| 406 | |
Jan Tattermusch | f2ba7fe | 2016-04-14 12:14:17 -0700 | [diff] [blame] | 407 | merged_latencies.FillProto(result->mutable_latencies()); |
| 408 | |
vjpai | 60a7e33 | 2016-02-26 10:30:17 -0800 | [diff] [blame] | 409 | gpr_log(GPR_INFO, "Finishing servers"); |
| 410 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
| 411 | GPR_ASSERT(server->stream->Write(server_mark)); |
| 412 | GPR_ASSERT(server->stream->WritesDone()); |
| 413 | } |
| 414 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
| 415 | GPR_ASSERT(server->stream->Read(&server_status)); |
Jan Tattermusch | f2ba7fe | 2016-04-14 12:14:17 -0700 | [diff] [blame] | 416 | result->add_server_stats()->CopyFrom(server_status.stats()); |
| 417 | result->add_server_cores(server_status.cores()); |
vjpai | 60a7e33 | 2016-02-26 10:30:17 -0800 | [diff] [blame] | 418 | GPR_ASSERT(!server->stream->Read(&server_status)); |
| 419 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 420 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 421 | GPR_ASSERT(server->stream->Finish().ok()); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 422 | } |
vjpai | 60a7e33 | 2016-02-26 10:30:17 -0800 | [diff] [blame] | 423 | |
vjpai | b1db869 | 2015-08-11 22:41:02 -0700 | [diff] [blame] | 424 | delete[] servers; |
Jan Tattermusch | 33c161d | 2016-04-15 14:45:49 -0700 | [diff] [blame] | 425 | |
| 426 | postprocess_scenario_result(result.get()); |
Craig Tiller | f282514 | 2015-03-03 17:15:36 -0800 | [diff] [blame] | 427 | return result; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 428 | } |
vjpai | 21e5d2b | 2016-02-02 09:36:36 -0800 | [diff] [blame] | 429 | |
| 430 | void RunQuit() { |
| 431 | // Get client, server lists |
Vijay Pai | 2066443 | 2016-02-02 11:48:12 -0800 | [diff] [blame] | 432 | auto workers = get_workers("QPS_WORKERS"); |
vjpai | 21e5d2b | 2016-02-02 09:36:36 -0800 | [diff] [blame] | 433 | for (size_t i = 0; i < workers.size(); i++) { |
Vijay Pai | 847baf6 | 2016-03-14 17:23:50 -0700 | [diff] [blame] | 434 | auto stub = WorkerService::NewStub( |
Vijay Pai | 2ed337a | 2016-02-02 09:43:35 -0800 | [diff] [blame] | 435 | CreateChannel(workers[i], InsecureChannelCredentials())); |
vjpai | 21e5d2b | 2016-02-02 09:36:36 -0800 | [diff] [blame] | 436 | Void dummy; |
| 437 | grpc::ClientContext ctx; |
| 438 | GPR_ASSERT(stub->QuitWorker(&ctx, dummy, &dummy).ok()); |
| 439 | } |
| 440 | } |
| 441 | |
Craig Tiller | f282514 | 2015-03-03 17:15:36 -0800 | [diff] [blame] | 442 | } // namespace testing |
| 443 | } // namespace grpc |