blob: fc8e04201cd0f62e55e4009d33742cdeda60c0c0 [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 Tiller66048f42015-04-10 08:23:52 -070038#include "test/cpp/qps/report.h"
Yang Gao103837e2015-04-15 15:23:54 -070039#include "test/cpp/util/test_config.h"
Craig Tillere4860192015-02-23 17:10:41 -080040
Craig Tiller2d0f36c2015-02-23 23:16:17 -080041DEFINE_int32(num_clients, 1, "Number of client binaries");
42DEFINE_int32(num_servers, 1, "Number of server binaries");
Craig Tillere4860192015-02-23 17:10:41 -080043
Craig Tillerb9de09f2015-04-08 17:08:05 -070044DEFINE_int32(warmup_seconds, 5, "Warmup time (in seconds)");
45DEFINE_int32(benchmark_seconds, 30, "Benchmark time (in seconds)");
Craig Tillere9a6eb72015-04-09 15:51:41 -070046DEFINE_int32(local_workers, 0, "Number of local workers to start");
Craig Tillerb9de09f2015-04-08 17:08:05 -070047
Craig Tiller2d0f36c2015-02-23 23:16:17 -080048// Common config
49DEFINE_bool(enable_ssl, false, "Use SSL");
Vijay Paic5b39792015-03-23 10:46:37 -070050DEFINE_string(rpc_type, "UNARY", "Type of RPC: UNARY or STREAMING");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080051
52// Server config
53DEFINE_int32(server_threads, 1, "Number of server threads");
Craig Tiller6af9ed02015-03-02 22:42:10 -080054DEFINE_string(server_type, "SYNCHRONOUS_SERVER", "Server type");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080055
56// Client config
Craig Tiller10923c22015-03-03 14:24:49 -080057DEFINE_int32(outstanding_rpcs_per_channel, 1,
58 "Number of outstanding rpcs per channel");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080059DEFINE_int32(client_channels, 1, "Number of client channels");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080060DEFINE_int32(payload_size, 1, "Payload size");
Craig Tiller6af9ed02015-03-02 22:42:10 -080061DEFINE_string(client_type, "SYNCHRONOUS_CLIENT", "Client type");
Craig Tiller88568752015-03-04 10:50:43 -080062DEFINE_int32(async_client_threads, 1, "Async client threads");
Craig Tiller2d0f36c2015-02-23 23:16:17 -080063
64using grpc::testing::ClientConfig;
65using grpc::testing::ServerConfig;
Craig Tiller6af9ed02015-03-02 22:42:10 -080066using grpc::testing::ClientType;
67using grpc::testing::ServerType;
vjpai653803e2015-03-23 10:19:12 -070068using grpc::testing::RpcType;
Craig Tillerf2825142015-03-03 17:15:36 -080069using grpc::testing::ResourceUsage;
Craig Tillere4860192015-02-23 17:10:41 -080070
Yang Gao6baa9b62015-03-17 10:49:39 -070071int main(int argc, char** argv) {
Yang Gao103837e2015-04-15 15:23:54 -070072 grpc::testing::InitTest(&argc, &argv, true);
Craig Tillere4860192015-02-23 17:10:41 -080073
vjpai653803e2015-03-23 10:19:12 -070074 RpcType rpc_type;
Vijay Paic5b39792015-03-23 10:46:37 -070075 GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type));
vjpai653803e2015-03-23 10:19:12 -070076
Craig Tiller6af9ed02015-03-02 22:42:10 -080077 ClientType client_type;
78 ServerType server_type;
79 GPR_ASSERT(ClientType_Parse(FLAGS_client_type, &client_type));
80 GPR_ASSERT(ServerType_Parse(FLAGS_server_type, &server_type));
81
Craig Tiller2d0f36c2015-02-23 23:16:17 -080082 ClientConfig client_config;
Craig Tiller6af9ed02015-03-02 22:42:10 -080083 client_config.set_client_type(client_type);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080084 client_config.set_enable_ssl(FLAGS_enable_ssl);
Craig Tiller10923c22015-03-03 14:24:49 -080085 client_config.set_outstanding_rpcs_per_channel(
86 FLAGS_outstanding_rpcs_per_channel);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080087 client_config.set_client_channels(FLAGS_client_channels);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080088 client_config.set_payload_size(FLAGS_payload_size);
Craig Tiller88568752015-03-04 10:50:43 -080089 client_config.set_async_client_threads(FLAGS_async_client_threads);
vjpai653803e2015-03-23 10:19:12 -070090 client_config.set_rpc_type(rpc_type);
Craig Tillere4860192015-02-23 17:10:41 -080091
Craig Tiller2d0f36c2015-02-23 23:16:17 -080092 ServerConfig server_config;
Craig Tiller6af9ed02015-03-02 22:42:10 -080093 server_config.set_server_type(server_type);
Craig Tiller2d0f36c2015-02-23 23:16:17 -080094 server_config.set_threads(FLAGS_server_threads);
95 server_config.set_enable_ssl(FLAGS_enable_ssl);
96
Vijay Paidfe83de2015-05-05 11:42:54 -070097 // If we're running a sync-server streaming test, make sure
98 // that we have at least as many threads as the active streams
99 // or else threads will be blocked from forward progress and the
100 // client will deadlock on a timer.
101 GPR_ASSERT(!(server_type == grpc::testing::SYNCHRONOUS_SERVER &&
102 rpc_type == grpc::testing::STREAMING &&
103 FLAGS_server_threads < FLAGS_client_channels *
104 FLAGS_outstanding_rpcs_per_channel));
105
Craig Tillerb9de09f2015-04-08 17:08:05 -0700106 auto result = RunScenario(client_config, FLAGS_num_clients,
107 server_config, FLAGS_num_servers,
Craig Tillere9a6eb72015-04-09 15:51:41 -0700108 FLAGS_warmup_seconds, FLAGS_benchmark_seconds,
109 FLAGS_local_workers);
Craig Tillere4860192015-02-23 17:10:41 -0800110
Craig Tiller66048f42015-04-10 08:23:52 -0700111 ReportQPSPerCore(result, server_config);
112 ReportLatency(result);
113 ReportTimes(result);
Craig Tillerf2825142015-03-03 17:15:36 -0800114
Craig Tillere4860192015-02-23 17:10:41 -0800115 return 0;
116}