Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
David Garcia Quintas | 5a94623 | 2016-01-27 19:22:14 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, 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> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 46 | |
| 47 | #include "src/core/support/env.h" |
Vijay Pai | d02dd30 | 2016-01-27 11:23:34 -0800 | [diff] [blame] | 48 | #include "src/proto/grpc/testing/services.grpc.pb.h" |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 49 | #include "test/core/util/port.h" |
Craig Tiller | 882431f | 2015-05-19 09:25:37 -0700 | [diff] [blame] | 50 | #include "test/core/util/test_config.h" |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 51 | #include "test/cpp/qps/driver.h" |
| 52 | #include "test/cpp/qps/histogram.h" |
| 53 | #include "test/cpp/qps/qps_worker.h" |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 54 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 55 | using std::list; |
| 56 | using std::thread; |
| 57 | using std::unique_ptr; |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 58 | using std::deque; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 59 | using std::vector; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 60 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 61 | namespace grpc { |
| 62 | namespace testing { |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 63 | static std::string get_host(const std::string& worker) { |
| 64 | char* host; |
| 65 | char* port; |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 66 | |
| 67 | gpr_split_host_port(worker.c_str(), &host, &port); |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 68 | const string s(host); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 69 | |
| 70 | gpr_free(host); |
| 71 | gpr_free(port); |
| 72 | return s; |
| 73 | } |
| 74 | |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 75 | static std::unordered_map<string, std::deque<int>> get_hosts_and_cores( |
| 76 | const deque<string>& workers) { |
| 77 | std::unordered_map<string, std::deque<int>> hosts; |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 78 | for (auto it = workers.begin(); it != workers.end(); it++) { |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 79 | const string host = get_host(*it); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 80 | if (hosts.find(host) == hosts.end()) { |
| 81 | auto stub = WorkerService::NewStub( |
| 82 | CreateChannel(*it, InsecureChannelCredentials())); |
| 83 | grpc::ClientContext ctx; |
| 84 | CoreRequest dummy; |
| 85 | CoreResponse cores; |
| 86 | grpc::Status s = stub->CoreCount(&ctx, dummy, &cores); |
| 87 | assert(s.ok()); |
| 88 | std::deque<int> dq; |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 89 | for (int i = 0; i < cores.cores(); i++) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 90 | dq.push_back(i); |
| 91 | } |
| 92 | hosts[host] = dq; |
| 93 | } |
| 94 | } |
| 95 | return hosts; |
| 96 | } |
| 97 | |
| 98 | static deque<string> get_workers(const string& name) { |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 99 | char* env = gpr_getenv(name.c_str()); |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 100 | if (!env) return deque<string>(); |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 101 | |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 102 | deque<string> out; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 103 | char* p = env; |
| 104 | for (;;) { |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 105 | char* comma = strchr(p, ','); |
| 106 | if (comma) { |
| 107 | out.emplace_back(p, comma); |
| 108 | p = comma + 1; |
| 109 | } else { |
| 110 | out.emplace_back(p); |
| 111 | gpr_free(env); |
| 112 | return out; |
| 113 | } |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 117 | // Namespace for classes and functions used only in RunScenario |
| 118 | // Using this rather than local definitions to workaround gcc-4.4 limitations |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 119 | // regarding using templates without linkage |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 120 | namespace runsc { |
| 121 | |
| 122 | // ClientContext allocator |
Craig Tiller | b17b7f4 | 2015-10-07 08:48:51 -0700 | [diff] [blame] | 123 | template <class T> |
| 124 | static ClientContext* AllocContext(list<ClientContext>* contexts, T deadline) { |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 125 | contexts->emplace_back(); |
Craig Tiller | b17b7f4 | 2015-10-07 08:48:51 -0700 | [diff] [blame] | 126 | auto context = &contexts->back(); |
| 127 | context->set_deadline(deadline); |
| 128 | return context; |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | struct ServerData { |
vjpai | 119c103 | 2015-10-29 01:21:04 -0700 | [diff] [blame] | 132 | unique_ptr<WorkerService::Stub> stub; |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 133 | unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; |
| 134 | }; |
| 135 | |
| 136 | struct ClientData { |
vjpai | 119c103 | 2015-10-29 01:21:04 -0700 | [diff] [blame] | 137 | unique_ptr<WorkerService::Stub> stub; |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 138 | unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; |
| 139 | }; |
Vijay Pai | 3ae1104 | 2015-08-11 22:43:14 -0700 | [diff] [blame] | 140 | } // namespace runsc |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 141 | |
David Garcia Quintas | 0811650 | 2015-05-20 17:27:23 -0700 | [diff] [blame] | 142 | std::unique_ptr<ScenarioResult> RunScenario( |
| 143 | const ClientConfig& initial_client_config, size_t num_clients, |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 144 | const ServerConfig& initial_server_config, size_t num_servers, |
| 145 | int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count) { |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 146 | // ClientContext allocations (all are destroyed at scope exit) |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 147 | list<ClientContext> contexts; |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 148 | |
David Garcia Quintas | 6ba29ba | 2015-05-19 18:29:35 -0700 | [diff] [blame] | 149 | // To be added to the result, containing the final configuration used for |
Jan Tattermusch | c5ebbd5 | 2015-11-18 16:50:47 -0800 | [diff] [blame] | 150 | // client and config (including host, etc.) |
David Garcia Quintas | 6ba29ba | 2015-05-19 18:29:35 -0700 | [diff] [blame] | 151 | ClientConfig result_client_config; |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 152 | const ServerConfig result_server_config = initial_server_config; |
David Garcia Quintas | 6ba29ba | 2015-05-19 18:29:35 -0700 | [diff] [blame] | 153 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 154 | // Get client, server lists |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 155 | auto workers = get_workers("QPS_WORKERS"); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 156 | ClientConfig client_config = initial_client_config; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 157 | |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 158 | // Spawn some local workers if desired |
| 159 | vector<unique_ptr<QpsWorker>> local_workers; |
| 160 | for (int i = 0; i < abs(spawn_local_worker_count); i++) { |
Craig Tiller | 49c3b01 | 2015-05-19 08:18:02 -0700 | [diff] [blame] | 161 | // act as if we're a new test -- gets a good rng seed |
| 162 | static bool called_init = false; |
| 163 | if (!called_init) { |
Craig Tiller | 882431f | 2015-05-19 09:25:37 -0700 | [diff] [blame] | 164 | char args_buf[100]; |
| 165 | strcpy(args_buf, "some-benchmark"); |
Craig Tiller | 5c8737d | 2015-05-21 11:42:17 -0700 | [diff] [blame] | 166 | char* args[] = {args_buf}; |
Craig Tiller | 49c3b01 | 2015-05-19 08:18:02 -0700 | [diff] [blame] | 167 | grpc_test_init(1, args); |
| 168 | called_init = true; |
| 169 | } |
| 170 | |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 171 | int driver_port = grpc_pick_unused_port_or_die(); |
vjpai | 72a6332 | 2015-10-29 02:23:11 -0700 | [diff] [blame] | 172 | local_workers.emplace_back(new QpsWorker(driver_port)); |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 173 | char addr[256]; |
| 174 | sprintf(addr, "localhost:%d", driver_port); |
| 175 | if (spawn_local_worker_count < 0) { |
| 176 | workers.push_front(addr); |
| 177 | } else { |
| 178 | workers.push_back(addr); |
| 179 | } |
| 180 | } |
| 181 | |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 182 | // Setup the hosts and core counts |
| 183 | auto hosts_cores = get_hosts_and_cores(workers); |
| 184 | |
Vijay Pai | d02dd30 | 2016-01-27 11:23:34 -0800 | [diff] [blame] | 185 | // if num_clients is set to <=0, do dynamic sizing: all workers |
| 186 | // except for servers are clients |
| 187 | if (num_clients <= 0) { |
| 188 | num_clients = workers.size() - num_servers; |
| 189 | } |
| 190 | |
Craig Tiller | 10923c2 | 2015-03-03 14:24:49 -0800 | [diff] [blame] | 191 | // TODO(ctiller): support running multiple configurations, and binpack |
| 192 | // client/server pairs |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 193 | // to available workers |
| 194 | GPR_ASSERT(workers.size() >= num_clients + num_servers); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 195 | |
| 196 | // Trim to just what we need |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 197 | workers.resize(num_clients + num_servers); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 198 | |
Vijay Pai | e40aefb | 2016-02-13 01:25:30 -0800 | [diff] [blame] | 199 | gpr_timespec deadline = |
| 200 | GRPC_TIMEOUT_SECONDS_TO_DEADLINE(warmup_seconds + benchmark_seconds + 20); |
Craig Tiller | b17b7f4 | 2015-10-07 08:48:51 -0700 | [diff] [blame] | 201 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 202 | // Start servers |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 203 | using runsc::ServerData; |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 204 | // servers is array rather than std::vector to avoid gcc-4.4 issues |
| 205 | // where class contained in std::vector must have a copy constructor |
vjpai | b1db869 | 2015-08-11 22:41:02 -0700 | [diff] [blame] | 206 | auto* servers = new ServerData[num_servers]; |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 207 | for (size_t i = 0; i < num_servers; i++) { |
vjpai | 94aada9 | 2016-01-26 18:12:30 -0800 | [diff] [blame] | 208 | 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] | 209 | i); |
Julien Boeuf | 6049ebd | 2015-11-17 16:53:52 -0800 | [diff] [blame] | 210 | servers[i].stub = WorkerService::NewStub( |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 211 | CreateChannel(workers[i], InsecureChannelCredentials())); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 212 | |
| 213 | ServerConfig server_config = initial_server_config; |
| 214 | char* host; |
| 215 | char* driver_port; |
| 216 | char* cli_target; |
| 217 | gpr_split_host_port(workers[i].c_str(), &host, &driver_port); |
| 218 | string host_str(host); |
| 219 | int server_core_limit = initial_server_config.core_limit(); |
| 220 | int client_core_limit = initial_client_config.core_limit(); |
| 221 | |
| 222 | if (server_core_limit == 0 && client_core_limit > 0) { |
| 223 | // In this case, limit the server cores if it matches the |
| 224 | // same host as one or more clients |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 225 | const auto& dq = hosts_cores.at(host_str); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 226 | bool match = false; |
| 227 | int limit = dq.size(); |
| 228 | for (size_t cli = 0; cli < num_clients; cli++) { |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 229 | if (host_str == get_host(workers[cli + num_servers])) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 230 | limit -= client_core_limit; |
| 231 | match = true; |
| 232 | } |
| 233 | } |
| 234 | if (match) { |
| 235 | GPR_ASSERT(limit > 0); |
| 236 | server_core_limit = limit; |
| 237 | } |
| 238 | } |
| 239 | if (server_core_limit > 0) { |
Vijay Pai | 33e5118 | 2016-02-01 16:40:06 -0800 | [diff] [blame] | 240 | auto& dq = hosts_cores.at(host_str); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 241 | GPR_ASSERT(dq.size() >= static_cast<size_t>(server_core_limit)); |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 242 | for (int core = 0; core < server_core_limit; core++) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 243 | server_config.add_core_list(dq.front()); |
| 244 | dq.pop_front(); |
| 245 | } |
| 246 | } |
| 247 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 248 | ServerArgs args; |
| 249 | *args.mutable_setup() = server_config; |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 250 | servers[i].stream = |
Craig Tiller | b17b7f4 | 2015-10-07 08:48:51 -0700 | [diff] [blame] | 251 | servers[i].stub->RunServer(runsc::AllocContext(&contexts, deadline)); |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 252 | GPR_ASSERT(servers[i].stream->Write(args)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 253 | ServerStatus init_status; |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 254 | GPR_ASSERT(servers[i].stream->Read(&init_status)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 255 | gpr_join_host_port(&cli_target, host, init_status.port()); |
| 256 | client_config.add_server_targets(cli_target); |
| 257 | gpr_free(host); |
| 258 | gpr_free(driver_port); |
| 259 | gpr_free(cli_target); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 262 | // Targets are all set by now |
| 263 | result_client_config = client_config; |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 264 | // Start clients |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 265 | using runsc::ClientData; |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 266 | // clients is array rather than std::vector to avoid gcc-4.4 issues |
| 267 | // where class contained in std::vector must have a copy constructor |
vjpai | b1db869 | 2015-08-11 22:41:02 -0700 | [diff] [blame] | 268 | auto* clients = new ClientData[num_clients]; |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 269 | for (size_t i = 0; i < num_clients; i++) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 270 | const auto& worker = workers[i + num_servers]; |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 271 | gpr_log(GPR_INFO, "Starting client on %s (worker #%d)", worker.c_str(), |
| 272 | i + num_servers); |
Julien Boeuf | 6049ebd | 2015-11-17 16:53:52 -0800 | [diff] [blame] | 273 | clients[i].stub = WorkerService::NewStub( |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 274 | CreateChannel(worker, InsecureChannelCredentials())); |
| 275 | ClientConfig per_client_config = client_config; |
| 276 | |
| 277 | int server_core_limit = initial_server_config.core_limit(); |
| 278 | int client_core_limit = initial_client_config.core_limit(); |
| 279 | if ((server_core_limit > 0) || (client_core_limit > 0)) { |
Vijay Pai | daadcc8 | 2016-02-01 16:49:55 -0800 | [diff] [blame] | 280 | auto& dq = hosts_cores.at(get_host(worker)); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 281 | if (client_core_limit == 0) { |
| 282 | // limit client cores if it matches a server host |
| 283 | bool match = false; |
| 284 | int limit = dq.size(); |
| 285 | for (size_t srv = 0; srv < num_servers; srv++) { |
| 286 | if (get_host(worker) == get_host(workers[srv])) { |
| 287 | match = true; |
| 288 | } |
| 289 | } |
| 290 | if (match) { |
Vijay Pai | 6b05639 | 2016-02-01 13:01:34 -0800 | [diff] [blame] | 291 | GPR_ASSERT(limit > 0); |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 292 | client_core_limit = limit; |
| 293 | } |
| 294 | } |
| 295 | if (client_core_limit > 0) { |
| 296 | GPR_ASSERT(dq.size() >= static_cast<size_t>(client_core_limit)); |
Vijay Pai | 5956742 | 2016-02-01 13:28:55 -0800 | [diff] [blame] | 297 | for (int core = 0; core < client_core_limit; core++) { |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 298 | per_client_config.add_core_list(dq.front()); |
| 299 | dq.pop_front(); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 304 | ClientArgs args; |
Vijay Pai | 7d45cdb | 2016-02-01 13:00:19 -0800 | [diff] [blame] | 305 | *args.mutable_setup() = per_client_config; |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 306 | clients[i].stream = |
vjpai | 52bfb25 | 2015-10-21 07:50:49 -0700 | [diff] [blame] | 307 | clients[i].stub->RunClient(runsc::AllocContext(&contexts, deadline)); |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 308 | GPR_ASSERT(clients[i].stream->Write(args)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 309 | ClientStatus init_status; |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 310 | GPR_ASSERT(clients[i].stream->Read(&init_status)); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 313 | // Let everything warmup |
| 314 | gpr_log(GPR_INFO, "Warming up"); |
Craig Tiller | 20b5fe9 | 2015-07-06 10:43:50 -0700 | [diff] [blame] | 315 | gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); |
Craig Tiller | 677c50c | 2015-07-13 10:49:06 -0700 | [diff] [blame] | 316 | gpr_sleep_until( |
| 317 | gpr_time_add(start, gpr_time_from_seconds(warmup_seconds, GPR_TIMESPAN))); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 318 | |
| 319 | // Start a run |
| 320 | gpr_log(GPR_INFO, "Starting"); |
| 321 | ServerArgs server_mark; |
vjpai | 119c103 | 2015-10-29 01:21:04 -0700 | [diff] [blame] | 322 | server_mark.mutable_mark()->set_reset(true); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 323 | ClientArgs client_mark; |
vjpai | 119c103 | 2015-10-29 01:21:04 -0700 | [diff] [blame] | 324 | client_mark.mutable_mark()->set_reset(true); |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 325 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 326 | GPR_ASSERT(server->stream->Write(server_mark)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 327 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 328 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 329 | GPR_ASSERT(client->stream->Write(client_mark)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 330 | } |
| 331 | ServerStatus server_status; |
| 332 | ClientStatus client_status; |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 333 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 334 | GPR_ASSERT(server->stream->Read(&server_status)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 335 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 336 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 337 | GPR_ASSERT(client->stream->Read(&client_status)); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 340 | // Wait some time |
| 341 | gpr_log(GPR_INFO, "Running"); |
Vijay Pai | 90e7369 | 2015-08-05 19:15:36 -0700 | [diff] [blame] | 342 | // Use gpr_sleep_until rather than this_thread::sleep_until to support |
| 343 | // compilers that don't work with this_thread |
Craig Tiller | 677c50c | 2015-07-13 10:49:06 -0700 | [diff] [blame] | 344 | gpr_sleep_until(gpr_time_add( |
| 345 | start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN))); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 346 | |
| 347 | // Finish a run |
David Garcia Quintas | 0811650 | 2015-05-20 17:27:23 -0700 | [diff] [blame] | 348 | std::unique_ptr<ScenarioResult> result(new ScenarioResult); |
| 349 | result->client_config = result_client_config; |
| 350 | result->server_config = result_server_config; |
vjpai | 60a7e33 | 2016-02-26 10:30:17 -0800 | [diff] [blame^] | 351 | gpr_log(GPR_INFO, "Finishing clients"); |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 352 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 353 | GPR_ASSERT(client->stream->Write(client_mark)); |
Vijay Pai | 02eda41 | 2016-02-25 19:43:57 -0800 | [diff] [blame] | 354 | GPR_ASSERT(client->stream->WritesDone()); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 355 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 356 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Vijay Pai | 82dd80a | 2015-03-24 10:36:08 -0700 | [diff] [blame] | 357 | GPR_ASSERT(client->stream->Read(&client_status)); |
Craig Tiller | f282514 | 2015-03-03 17:15:36 -0800 | [diff] [blame] | 358 | const auto& stats = client_status.stats(); |
David Garcia Quintas | 0811650 | 2015-05-20 17:27:23 -0700 | [diff] [blame] | 359 | result->latencies.MergeProto(stats.latencies()); |
Vijay Pai | 4d06e2e | 2015-07-31 10:20:42 -0700 | [diff] [blame] | 360 | result->client_resources.emplace_back( |
Vijay Pai | ce84670 | 2015-11-04 00:30:12 -0800 | [diff] [blame] | 361 | stats.time_elapsed(), stats.time_user(), stats.time_system(), -1); |
Vijay Pai | 02eda41 | 2016-02-25 19:43:57 -0800 | [diff] [blame] | 362 | GPR_ASSERT(!client->stream->Read(&client_status)); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 363 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 364 | for (auto client = &clients[0]; client != &clients[num_clients]; client++) { |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 365 | GPR_ASSERT(client->stream->Finish().ok()); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 366 | } |
vjpai | 60a7e33 | 2016-02-26 10:30:17 -0800 | [diff] [blame^] | 367 | delete[] clients; |
| 368 | |
| 369 | gpr_log(GPR_INFO, "Finishing servers"); |
| 370 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
| 371 | GPR_ASSERT(server->stream->Write(server_mark)); |
| 372 | GPR_ASSERT(server->stream->WritesDone()); |
| 373 | } |
| 374 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
| 375 | GPR_ASSERT(server->stream->Read(&server_status)); |
| 376 | const auto& stats = server_status.stats(); |
| 377 | result->server_resources.emplace_back( |
| 378 | stats.time_elapsed(), stats.time_user(), stats.time_system(), |
| 379 | server_status.cores()); |
| 380 | GPR_ASSERT(!server->stream->Read(&server_status)); |
| 381 | } |
Vijay Pai | eed63fa | 2015-08-05 23:08:34 +0000 | [diff] [blame] | 382 | for (auto server = &servers[0]; server != &servers[num_servers]; server++) { |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 383 | GPR_ASSERT(server->stream->Finish().ok()); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 384 | } |
vjpai | 60a7e33 | 2016-02-26 10:30:17 -0800 | [diff] [blame^] | 385 | |
vjpai | b1db869 | 2015-08-11 22:41:02 -0700 | [diff] [blame] | 386 | delete[] servers; |
Craig Tiller | f282514 | 2015-03-03 17:15:36 -0800 | [diff] [blame] | 387 | return result; |
Craig Tiller | 4ef7a29 | 2015-02-23 17:29:01 -0800 | [diff] [blame] | 388 | } |
vjpai | 21e5d2b | 2016-02-02 09:36:36 -0800 | [diff] [blame] | 389 | |
| 390 | void RunQuit() { |
| 391 | // Get client, server lists |
Vijay Pai | 2066443 | 2016-02-02 11:48:12 -0800 | [diff] [blame] | 392 | auto workers = get_workers("QPS_WORKERS"); |
vjpai | 21e5d2b | 2016-02-02 09:36:36 -0800 | [diff] [blame] | 393 | for (size_t i = 0; i < workers.size(); i++) { |
| 394 | auto stub = WorkerService::NewStub( |
Vijay Pai | 2ed337a | 2016-02-02 09:43:35 -0800 | [diff] [blame] | 395 | CreateChannel(workers[i], InsecureChannelCredentials())); |
vjpai | 21e5d2b | 2016-02-02 09:36:36 -0800 | [diff] [blame] | 396 | Void dummy; |
| 397 | grpc::ClientContext ctx; |
| 398 | GPR_ASSERT(stub->QuitWorker(&ctx, dummy, &dummy).ok()); |
| 399 | } |
| 400 | } |
| 401 | |
Craig Tiller | f282514 | 2015-03-03 17:15:36 -0800 | [diff] [blame] | 402 | } // namespace testing |
| 403 | } // namespace grpc |