Launches many clients against a central server and measures client throughput.
| 254 | // Launches many clients against a central server and measures |
| 255 | // client throughput. |
| 256 | TEST(ProcessTest, Process_BENCHMARK_ClientServer) |
| 257 | { |
| 258 | const size_t numRequests = 10000; |
| 259 | const size_t concurrency = 250; |
| 260 | const size_t numClients = 8; |
| 261 | const Bytes messageSize = Bytes(3); |
| 262 | |
| 263 | ServerProcess server; |
| 264 | const UPID serverPid = spawn(&server); |
| 265 | |
| 266 | // Launch the clients. |
| 267 | vector<Owned<ClientProcess>> clients; |
| 268 | for (size_t i = 0; i < numClients; i++) { |
| 269 | clients.push_back(Owned<ClientProcess>(new ClientProcess())); |
| 270 | spawn(clients.back().get()); |
| 271 | } |
| 272 | |
| 273 | // Start the ping / pongs! |
| 274 | const string query = strings::join( |
| 275 | "&", |
| 276 | "server=" + stringify(serverPid), |
| 277 | "requests=" + stringify(numRequests), |
| 278 | "concurrency=" + stringify(concurrency), |
| 279 | "messageSize=" + stringify(messageSize)); |
| 280 | |
| 281 | Stopwatch watch; |
| 282 | watch.start(); |
| 283 | |
| 284 | vector<Future<http::Response>> futures; |
| 285 | foreach (const Owned<ClientProcess>& client, clients) { |
| 286 | futures.push_back(http::get(client->self(), "run", query)); |
| 287 | } |
| 288 | |
| 289 | Future<vector<http::Response>> responses = collect(futures); |
| 290 | AWAIT_READY(responses); |
| 291 | |
| 292 | Duration elapsed = watch.elapsed(); |
| 293 | |
| 294 | // Print the throughput of each client. |
| 295 | size_t i = 0; |
| 296 | foreach (const http::Response& response, responses.get()) { |
| 297 | ASSERT_EQ(http::Status::OK, response.code); |
| 298 | ASSERT_EQ(http::Status::string(http::Status::OK), response.status); |
| 299 | |
| 300 | Try<Duration> elapsed = Duration::parse(response.body); |
| 301 | ASSERT_SOME(elapsed); |
| 302 | double throughput = numRequests / elapsed->secs(); |
| 303 | |
| 304 | cout << "Client " << i << ": " << throughput << " rpcs / sec" << endl; |
| 305 | |
| 306 | i++; |
| 307 | } |
| 308 | |
| 309 | double throughput = (numRequests * numClients) / elapsed.secs(); |
| 310 | cout << "Estimated Total: " << throughput << " rpcs / sec" << endl; |
| 311 | |
| 312 | foreach (const Owned<ClientProcess>& client, clients) { |
| 313 | terminate(*client); |
nothing calls this directly
no test coverage detected