blob: d5348463650cda64b5dfcb927d21b682b0471f99 [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
David Garcia Quintas3cc9ec92015-05-18 22:33:02 -070034#include <memory>
David Garcia Quintascdbdedb2015-05-18 17:28:52 -070035#include <set>
36
Craig Tillere4860192015-02-23 17:10:41 -080037#include <gflags/gflags.h>
Craig Tiller6af9ed02015-03-02 22:42:10 -080038#include <grpc/support/log.h>
Craig Tillere4860192015-02-23 17:10:41 -080039
40#include "test/cpp/qps/driver.h"
Craig Tiller66048f42015-04-10 08:23:52 -070041#include "test/cpp/qps/report.h"
David Garcia Quintas3cc9ec92015-05-18 22:33:02 -070042#include "test/cpp/util/benchmark_config.h"
Craig Tillere4860192015-02-23 17:10:41 -080043
Craig Tiller2d0f36c2015-02-23 23:16:17 -080044DEFINE_int32(num_clients, 1, "Number of client binaries");
45DEFINE_int32(num_servers, 1, "Number of server binaries");
Craig Tillere4860192015-02-23 17:10:41 -080046
Craig Tillerb9de09f2015-04-08 17:08:05 -070047DEFINE_int32(warmup_seconds, 5, "Warmup time (in seconds)");
48DEFINE_int32(benchmark_seconds, 30, "Benchmark time (in seconds)");
Craig Tillere9a6eb72015-04-09 15:51:41 -070049DEFINE_int32(local_workers, 0, "Number of local workers to start");
Craig Tillerb9de09f2015-04-08 17:08:05 -070050
Craig Tiller2d0f36c2015-02-23 23:16:17 -080051// Common config
52DEFINE_bool(enable_ssl, false, "Use SSL");
Vijay Paic5b39792015-03-23 10:46:37 -070053DEFINE_string(rpc_type, "UNARY", "Type of RPC: UNARY or STREAMING");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080054
55// Server config
56DEFINE_int32(server_threads, 1, "Number of server threads");
Craig Tiller6af9ed02015-03-02 22:42:10 -080057DEFINE_string(server_type, "SYNCHRONOUS_SERVER", "Server type");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080058
59// Client config
Craig Tiller10923c22015-03-03 14:24:49 -080060DEFINE_int32(outstanding_rpcs_per_channel, 1,
61 "Number of outstanding rpcs per channel");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080062DEFINE_int32(client_channels, 1, "Number of client channels");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080063DEFINE_int32(payload_size, 1, "Payload size");
Craig Tiller6af9ed02015-03-02 22:42:10 -080064DEFINE_string(client_type, "SYNCHRONOUS_CLIENT", "Client type");
Craig Tiller88568752015-03-04 10:50:43 -080065DEFINE_int32(async_client_threads, 1, "Async client threads");
Vijay Pai372fd872015-06-08 13:30:08 -070066DEFINE_string(load_type, "CLOSED_LOOP", "Load type");
67DEFINE_double(load_param_1, 0.0, "Load parameter 1");
68DEFINE_double(load_param_2, 0.0, "Load parameter 2");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080069
70using grpc::testing::ClientConfig;
71using grpc::testing::ServerConfig;
Craig Tiller6af9ed02015-03-02 22:42:10 -080072using grpc::testing::ClientType;
73using grpc::testing::ServerType;
Vijay Pai372fd872015-06-08 13:30:08 -070074using grpc::testing::LoadType;
vjpai653803e2015-03-23 10:19:12 -070075using grpc::testing::RpcType;
Craig Tillerf2825142015-03-03 17:15:36 -080076using grpc::testing::ResourceUsage;
Craig Tillere4860192015-02-23 17:10:41 -080077
David Garcia Quintas3cc9ec92015-05-18 22:33:02 -070078namespace grpc {
79namespace testing {
Craig Tillere4860192015-02-23 17:10:41 -080080
David Garcia Quintasa6b559a2015-05-20 22:08:24 -070081static void QpsDriver() {
vjpai653803e2015-03-23 10:19:12 -070082 RpcType rpc_type;
Vijay Paic5b39792015-03-23 10:46:37 -070083 GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type));
vjpai653803e2015-03-23 10:19:12 -070084
Craig Tiller6af9ed02015-03-02 22:42:10 -080085 ClientType client_type;
86 ServerType server_type;
Vijay Pai372fd872015-06-08 13:30:08 -070087 LoadType load_type;
Craig Tiller6af9ed02015-03-02 22:42:10 -080088 GPR_ASSERT(ClientType_Parse(FLAGS_client_type, &client_type));
89 GPR_ASSERT(ServerType_Parse(FLAGS_server_type, &server_type));
Vijay Pai372fd872015-06-08 13:30:08 -070090 GPR_ASSERT(LoadType_Parse(FLAGS_load_type, &load_type));
Craig Tiller6af9ed02015-03-02 22:42:10 -080091
Craig Tiller2d0f36c2015-02-23 23:16:17 -080092 ClientConfig client_config;
Craig Tiller6af9ed02015-03-02 22:42:10 -080093 client_config.set_client_type(client_type);
Vijay Pai372fd872015-06-08 13:30:08 -070094 client_config.set_load_type(load_type);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080095 client_config.set_enable_ssl(FLAGS_enable_ssl);
Craig Tiller10923c22015-03-03 14:24:49 -080096 client_config.set_outstanding_rpcs_per_channel(
97 FLAGS_outstanding_rpcs_per_channel);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080098 client_config.set_client_channels(FLAGS_client_channels);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080099 client_config.set_payload_size(FLAGS_payload_size);
Craig Tiller88568752015-03-04 10:50:43 -0800100 client_config.set_async_client_threads(FLAGS_async_client_threads);
vjpai653803e2015-03-23 10:19:12 -0700101 client_config.set_rpc_type(rpc_type);
Craig Tillere4860192015-02-23 17:10:41 -0800102
Vijay Pai372fd872015-06-08 13:30:08 -0700103 // set up the load parameters
104 switch (load_type) {
105 case grpc::testing::CLOSED_LOOP:
106 break;
107 case grpc::testing::POISSON: {
108 auto poisson = client_config.mutable_load_params()->mutable_poisson();
109 GPR_ASSERT(FLAGS_load_param_1 != 0.0);
110 poisson->set_offered_load(FLAGS_load_param_1);
111 break;
112 }
113 case grpc::testing::UNIFORM: {
114 auto uniform = client_config.mutable_load_params()->mutable_uniform();
115 GPR_ASSERT(FLAGS_load_param_1 != 0.0);
116 GPR_ASSERT(FLAGS_load_param_2 != 0.0);
117 uniform->set_interarrival_lo(FLAGS_load_param_1 / 1e6);
118 uniform->set_interarrival_hi(FLAGS_load_param_2 / 1e6);
119 break;
120 }
121 case grpc::testing::DETERMINISTIC: {
122 auto determ = client_config.mutable_load_params()->mutable_determ();
123 GPR_ASSERT(FLAGS_load_param_1 != 0.0);
124 determ->set_offered_load(FLAGS_load_param_1);
125 break;
126 }
127 case grpc::testing::PARETO: {
128 auto pareto = client_config.mutable_load_params()->mutable_pareto();
129 GPR_ASSERT(FLAGS_load_param_1 != 0.0);
130 GPR_ASSERT(FLAGS_load_param_2 != 0.0);
131 pareto->set_interarrival_base(FLAGS_load_param_1 / 1e6);
132 pareto->set_alpha(FLAGS_load_param_2);
133 break;
134 }
vjpai2490d9d2015-06-08 14:44:03 -0700135 default:
136 GPR_ASSERT(false);
137 break;
Vijay Pai372fd872015-06-08 13:30:08 -0700138 }
139
Craig Tiller2d0f36c2015-02-23 23:16:17 -0800140 ServerConfig server_config;
Craig Tiller6af9ed02015-03-02 22:42:10 -0800141 server_config.set_server_type(server_type);
Craig Tiller2d0f36c2015-02-23 23:16:17 -0800142 server_config.set_threads(FLAGS_server_threads);
143 server_config.set_enable_ssl(FLAGS_enable_ssl);
144
Vijay Paidfe83de2015-05-05 11:42:54 -0700145 // If we're running a sync-server streaming test, make sure
146 // that we have at least as many threads as the active streams
147 // or else threads will be blocked from forward progress and the
148 // client will deadlock on a timer.
149 GPR_ASSERT(!(server_type == grpc::testing::SYNCHRONOUS_SERVER &&
150 rpc_type == grpc::testing::STREAMING &&
Craig Tiller5c8737d2015-05-21 11:42:17 -0700151 FLAGS_server_threads <
152 FLAGS_client_channels * FLAGS_outstanding_rpcs_per_channel));
Vijay Paidfe83de2015-05-05 11:42:54 -0700153
David Garcia Quintascdbdedb2015-05-18 17:28:52 -0700154 const auto result = RunScenario(
155 client_config, FLAGS_num_clients, server_config, FLAGS_num_servers,
156 FLAGS_warmup_seconds, FLAGS_benchmark_seconds, FLAGS_local_workers);
Craig Tillere4860192015-02-23 17:10:41 -0800157
David Garcia Quintasf526bd42015-05-21 16:49:38 -0700158 GetReporter()->ReportQPS(*result);
David Garcia Quintasbb7370f2015-06-08 13:16:03 -0700159 GetReporter()->ReportQPSPerCore(*result);
David Garcia Quintasf526bd42015-05-21 16:49:38 -0700160 GetReporter()->ReportLatency(*result);
161 GetReporter()->ReportTimes(*result);
David Garcia Quintas3cc9ec92015-05-18 22:33:02 -0700162}
163
164} // namespace testing
165} // namespace grpc
166
167int main(int argc, char** argv) {
168 grpc::testing::InitBenchmark(&argc, &argv, true);
David Garcia Quintas3cc9ec92015-05-18 22:33:02 -0700169
170 signal(SIGPIPE, SIG_IGN);
David Garcia Quintasa6b559a2015-05-20 22:08:24 -0700171 grpc::testing::QpsDriver();
Craig Tillerf2825142015-03-03 17:15:36 -0800172
Craig Tillere4860192015-02-23 17:10:41 -0800173 return 0;
174}