Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 1 | /* |
| 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 Quintas | 3cc9ec9 | 2015-05-18 22:33:02 -0700 | [diff] [blame^] | 34 | #include <memory> |
David Garcia Quintas | cdbdedb | 2015-05-18 17:28:52 -0700 | [diff] [blame] | 35 | #include <set> |
| 36 | |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 37 | #include <gflags/gflags.h> |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 38 | #include <grpc/support/log.h> |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 39 | |
| 40 | #include "test/cpp/qps/driver.h" |
Craig Tiller | 66048f4 | 2015-04-10 08:23:52 -0700 | [diff] [blame] | 41 | #include "test/cpp/qps/report.h" |
David Garcia Quintas | 3cc9ec9 | 2015-05-18 22:33:02 -0700 | [diff] [blame^] | 42 | #include "test/cpp/util/benchmark_config.h" |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 43 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 44 | DEFINE_int32(num_clients, 1, "Number of client binaries"); |
| 45 | DEFINE_int32(num_servers, 1, "Number of server binaries"); |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 46 | |
Craig Tiller | b9de09f | 2015-04-08 17:08:05 -0700 | [diff] [blame] | 47 | DEFINE_int32(warmup_seconds, 5, "Warmup time (in seconds)"); |
| 48 | DEFINE_int32(benchmark_seconds, 30, "Benchmark time (in seconds)"); |
Craig Tiller | e9a6eb7 | 2015-04-09 15:51:41 -0700 | [diff] [blame] | 49 | DEFINE_int32(local_workers, 0, "Number of local workers to start"); |
Craig Tiller | b9de09f | 2015-04-08 17:08:05 -0700 | [diff] [blame] | 50 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 51 | // Common config |
| 52 | DEFINE_bool(enable_ssl, false, "Use SSL"); |
Vijay Pai | c5b3979 | 2015-03-23 10:46:37 -0700 | [diff] [blame] | 53 | DEFINE_string(rpc_type, "UNARY", "Type of RPC: UNARY or STREAMING"); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 54 | |
| 55 | // Server config |
| 56 | DEFINE_int32(server_threads, 1, "Number of server threads"); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 57 | DEFINE_string(server_type, "SYNCHRONOUS_SERVER", "Server type"); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 58 | |
| 59 | // Client config |
Craig Tiller | 10923c2 | 2015-03-03 14:24:49 -0800 | [diff] [blame] | 60 | DEFINE_int32(outstanding_rpcs_per_channel, 1, |
| 61 | "Number of outstanding rpcs per channel"); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 62 | DEFINE_int32(client_channels, 1, "Number of client channels"); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 63 | DEFINE_int32(payload_size, 1, "Payload size"); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 64 | DEFINE_string(client_type, "SYNCHRONOUS_CLIENT", "Client type"); |
Craig Tiller | 8856875 | 2015-03-04 10:50:43 -0800 | [diff] [blame] | 65 | DEFINE_int32(async_client_threads, 1, "Async client threads"); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 66 | |
| 67 | using grpc::testing::ClientConfig; |
| 68 | using grpc::testing::ServerConfig; |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 69 | using grpc::testing::ClientType; |
| 70 | using grpc::testing::ServerType; |
vjpai | 653803e | 2015-03-23 10:19:12 -0700 | [diff] [blame] | 71 | using grpc::testing::RpcType; |
Craig Tiller | f282514 | 2015-03-03 17:15:36 -0800 | [diff] [blame] | 72 | using grpc::testing::ResourceUsage; |
David Garcia Quintas | cdbdedb | 2015-05-18 17:28:52 -0700 | [diff] [blame] | 73 | using grpc::testing::ReportType; |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 74 | |
David Garcia Quintas | 3cc9ec9 | 2015-05-18 22:33:02 -0700 | [diff] [blame^] | 75 | namespace grpc { |
| 76 | namespace testing { |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 77 | |
David Garcia Quintas | 3cc9ec9 | 2015-05-18 22:33:02 -0700 | [diff] [blame^] | 78 | static void QpsDriver( |
| 79 | const std::vector<std::unique_ptr<Reporter> >& reporters) { |
vjpai | 653803e | 2015-03-23 10:19:12 -0700 | [diff] [blame] | 80 | RpcType rpc_type; |
Vijay Pai | c5b3979 | 2015-03-23 10:46:37 -0700 | [diff] [blame] | 81 | GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type)); |
vjpai | 653803e | 2015-03-23 10:19:12 -0700 | [diff] [blame] | 82 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 83 | ClientType client_type; |
| 84 | ServerType server_type; |
| 85 | GPR_ASSERT(ClientType_Parse(FLAGS_client_type, &client_type)); |
| 86 | GPR_ASSERT(ServerType_Parse(FLAGS_server_type, &server_type)); |
| 87 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 88 | ClientConfig client_config; |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 89 | client_config.set_client_type(client_type); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 90 | client_config.set_enable_ssl(FLAGS_enable_ssl); |
Craig Tiller | 10923c2 | 2015-03-03 14:24:49 -0800 | [diff] [blame] | 91 | client_config.set_outstanding_rpcs_per_channel( |
| 92 | FLAGS_outstanding_rpcs_per_channel); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 93 | client_config.set_client_channels(FLAGS_client_channels); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 94 | client_config.set_payload_size(FLAGS_payload_size); |
Craig Tiller | 8856875 | 2015-03-04 10:50:43 -0800 | [diff] [blame] | 95 | client_config.set_async_client_threads(FLAGS_async_client_threads); |
vjpai | 653803e | 2015-03-23 10:19:12 -0700 | [diff] [blame] | 96 | client_config.set_rpc_type(rpc_type); |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 97 | |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 98 | ServerConfig server_config; |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 99 | server_config.set_server_type(server_type); |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 100 | server_config.set_threads(FLAGS_server_threads); |
| 101 | server_config.set_enable_ssl(FLAGS_enable_ssl); |
| 102 | |
Vijay Pai | dfe83de | 2015-05-05 11:42:54 -0700 | [diff] [blame] | 103 | // If we're running a sync-server streaming test, make sure |
| 104 | // that we have at least as many threads as the active streams |
| 105 | // or else threads will be blocked from forward progress and the |
| 106 | // client will deadlock on a timer. |
| 107 | GPR_ASSERT(!(server_type == grpc::testing::SYNCHRONOUS_SERVER && |
| 108 | rpc_type == grpc::testing::STREAMING && |
| 109 | FLAGS_server_threads < FLAGS_client_channels * |
| 110 | FLAGS_outstanding_rpcs_per_channel)); |
| 111 | |
David Garcia Quintas | cdbdedb | 2015-05-18 17:28:52 -0700 | [diff] [blame] | 112 | const auto result = RunScenario( |
| 113 | client_config, FLAGS_num_clients, server_config, FLAGS_num_servers, |
| 114 | FLAGS_warmup_seconds, FLAGS_benchmark_seconds, FLAGS_local_workers); |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 115 | |
David Garcia Quintas | cdbdedb | 2015-05-18 17:28:52 -0700 | [diff] [blame] | 116 | std::set<ReportType> types; |
| 117 | types.insert(grpc::testing::ReportType::REPORT_ALL); |
David Garcia Quintas | 3cc9ec9 | 2015-05-18 22:33:02 -0700 | [diff] [blame^] | 118 | for (const auto& reporter : reporters) { |
| 119 | reporter->Report({client_config, server_config, result}, types); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | } // namespace testing |
| 124 | } // namespace grpc |
| 125 | |
| 126 | int main(int argc, char** argv) { |
| 127 | grpc::testing::InitBenchmark(&argc, &argv, true); |
| 128 | const auto& reporters = grpc::testing::InitBenchmarkReporters(); |
| 129 | |
| 130 | signal(SIGPIPE, SIG_IGN); |
| 131 | grpc::testing::QpsDriver(reporters); |
Craig Tiller | f282514 | 2015-03-03 17:15:36 -0800 | [diff] [blame] | 132 | |
Craig Tiller | e486019 | 2015-02-23 17:10:41 -0800 | [diff] [blame] | 133 | return 0; |
| 134 | } |