blob: f531094c7746baceaea66689bba912e1f48d495b [file] [log] [blame]
Craig Tillere4860192015-02-23 17:10:41 -08001/*
2 *
3 * Copyright 2015, Google Inc.
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
34#include <gflags/gflags.h>
Craig Tiller6af9ed02015-03-02 22:42:10 -080035#include <grpc/support/log.h>
Craig Tillere4860192015-02-23 17:10:41 -080036
37#include "test/cpp/qps/driver.h"
Craig Tillerf2825142015-03-03 17:15:36 -080038#include "test/cpp/qps/stats.h"
Craig Tillere4860192015-02-23 17:10:41 -080039
Craig Tiller2d0f36c2015-02-23 23:16:17 -080040DEFINE_int32(num_clients, 1, "Number of client binaries");
41DEFINE_int32(num_servers, 1, "Number of server binaries");
Craig Tillere4860192015-02-23 17:10:41 -080042
Craig Tiller2d0f36c2015-02-23 23:16:17 -080043// Common config
44DEFINE_bool(enable_ssl, false, "Use SSL");
Vijay Paic5b39792015-03-23 10:46:37 -070045DEFINE_string(rpc_type, "UNARY", "Type of RPC: UNARY or STREAMING");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080046
47// Server config
48DEFINE_int32(server_threads, 1, "Number of server threads");
Craig Tiller6af9ed02015-03-02 22:42:10 -080049DEFINE_string(server_type, "SYNCHRONOUS_SERVER", "Server type");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080050
51// Client config
Craig Tiller10923c22015-03-03 14:24:49 -080052DEFINE_int32(outstanding_rpcs_per_channel, 1,
53 "Number of outstanding rpcs per channel");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080054DEFINE_int32(client_channels, 1, "Number of client channels");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080055DEFINE_int32(payload_size, 1, "Payload size");
Craig Tiller6af9ed02015-03-02 22:42:10 -080056DEFINE_string(client_type, "SYNCHRONOUS_CLIENT", "Client type");
Craig Tiller88568752015-03-04 10:50:43 -080057DEFINE_int32(async_client_threads, 1, "Async client threads");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080058
59using grpc::testing::ClientConfig;
60using grpc::testing::ServerConfig;
Craig Tiller6af9ed02015-03-02 22:42:10 -080061using grpc::testing::ClientType;
62using grpc::testing::ServerType;
vjpai653803e2015-03-23 10:19:12 -070063using grpc::testing::RpcType;
Craig Tillerf2825142015-03-03 17:15:36 -080064using grpc::testing::ResourceUsage;
65using grpc::testing::sum;
Craig Tillere4860192015-02-23 17:10:41 -080066
67// In some distros, gflags is in the namespace google, and in some others,
68// in gflags. This hack is enabling us to find both.
Craig Tiller10923c22015-03-03 14:24:49 -080069namespace google {}
70namespace gflags {}
Craig Tillere4860192015-02-23 17:10:41 -080071using namespace google;
72using namespace gflags;
73
74int main(int argc, char **argv) {
75 grpc_init();
76 ParseCommandLineFlags(&argc, &argv, true);
77
vjpai653803e2015-03-23 10:19:12 -070078 RpcType rpc_type;
Vijay Paic5b39792015-03-23 10:46:37 -070079 GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type));
vjpai653803e2015-03-23 10:19:12 -070080
Craig Tiller6af9ed02015-03-02 22:42:10 -080081 ClientType client_type;
82 ServerType server_type;
83 GPR_ASSERT(ClientType_Parse(FLAGS_client_type, &client_type));
84 GPR_ASSERT(ServerType_Parse(FLAGS_server_type, &server_type));
85
Craig Tiller2d0f36c2015-02-23 23:16:17 -080086 ClientConfig client_config;
Craig Tiller6af9ed02015-03-02 22:42:10 -080087 client_config.set_client_type(client_type);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080088 client_config.set_enable_ssl(FLAGS_enable_ssl);
Craig Tiller10923c22015-03-03 14:24:49 -080089 client_config.set_outstanding_rpcs_per_channel(
90 FLAGS_outstanding_rpcs_per_channel);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080091 client_config.set_client_channels(FLAGS_client_channels);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080092 client_config.set_payload_size(FLAGS_payload_size);
Craig Tiller88568752015-03-04 10:50:43 -080093 client_config.set_async_client_threads(FLAGS_async_client_threads);
vjpai653803e2015-03-23 10:19:12 -070094 client_config.set_rpc_type(rpc_type);
Craig Tillere4860192015-02-23 17:10:41 -080095
Craig Tiller2d0f36c2015-02-23 23:16:17 -080096 ServerConfig server_config;
Craig Tiller6af9ed02015-03-02 22:42:10 -080097 server_config.set_server_type(server_type);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080098 server_config.set_threads(FLAGS_server_threads);
99 server_config.set_enable_ssl(FLAGS_enable_ssl);
100
Craig Tillerf2825142015-03-03 17:15:36 -0800101 auto result = RunScenario(client_config, FLAGS_num_clients, server_config,
Craig Tillera182bf12015-03-04 13:54:39 -0800102 FLAGS_num_servers);
Craig Tillere4860192015-02-23 17:10:41 -0800103
Craig Tillera182bf12015-03-04 13:54:39 -0800104 gpr_log(GPR_INFO, "QPS: %.1f",
105 result.latencies.Count() /
106 average(result.client_resources,
107 [](ResourceUsage u) { return u.wall_time; }));
Craig Tiller88568752015-03-04 10:50:43 -0800108
Craig Tillerf2825142015-03-03 17:15:36 -0800109 gpr_log(GPR_INFO, "Latencies (50/95/99/99.9%%-ile): %.1f/%.1f/%.1f/%.1f us",
Craig Tillera182bf12015-03-04 13:54:39 -0800110 result.latencies.Percentile(50) / 1000,
111 result.latencies.Percentile(95) / 1000,
112 result.latencies.Percentile(99) / 1000,
113 result.latencies.Percentile(99.9) / 1000);
Craig Tillerf2825142015-03-03 17:15:36 -0800114
Craig Tillera182bf12015-03-04 13:54:39 -0800115 gpr_log(GPR_INFO, "Server system time: %.2f%%",
116 100.0 * sum(result.server_resources,
117 [](ResourceUsage u) { return u.system_time; }) /
118 sum(result.server_resources,
119 [](ResourceUsage u) { return u.wall_time; }));
120 gpr_log(GPR_INFO, "Server user time: %.2f%%",
121 100.0 * sum(result.server_resources,
122 [](ResourceUsage u) { return u.user_time; }) /
123 sum(result.server_resources,
124 [](ResourceUsage u) { return u.wall_time; }));
125 gpr_log(GPR_INFO, "Client system time: %.2f%%",
126 100.0 * sum(result.client_resources,
127 [](ResourceUsage u) { return u.system_time; }) /
128 sum(result.client_resources,
129 [](ResourceUsage u) { return u.wall_time; }));
130 gpr_log(GPR_INFO, "Client user time: %.2f%%",
131 100.0 * sum(result.client_resources,
132 [](ResourceUsage u) { return u.user_time; }) /
133 sum(result.client_resources,
134 [](ResourceUsage u) { return u.wall_time; }));
Craig Tillerf2825142015-03-03 17:15:36 -0800135
Craig Tillere4860192015-02-23 17:10:41 -0800136 grpc_shutdown();
137 return 0;
138}