• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include <grpc/grpc.h>
20 #include <grpc/support/alloc.h>
21 
22 #include <memory>
23 #include <thread>
24 
25 #include "absl/flags/flag.h"
26 #include "absl/log/check.h"
27 #include "absl/log/log.h"
28 #include "absl/strings/str_split.h"
29 #include "src/core/util/string.h"
30 #include "test/core/test_util/test_config.h"
31 #include "test/cpp/interop/client_helper.h"
32 #include "test/cpp/interop/interop_client.h"
33 #include "test/cpp/util/create_test_channel.h"
34 #include "test/cpp/util/test_config.h"
35 
36 ABSL_FLAG(std::string, server_uris, "",
37           "Comma-separated list of sever URIs to make RPCs to");
38 ABSL_FLAG(std::string, credentials_types, "",
39           "Comma-separated list of credentials, each entry is used for the "
40           "server of the corresponding index in server_uris. Supported values: "
41           "compute_engine_channel_creds, INSECURE_CREDENTIALS");
42 ABSL_FLAG(int32_t, soak_iterations, 10,
43           "The number of iterations to use for the two soak tests: rpc_soak "
44           "and channel_soak");
45 ABSL_FLAG(int32_t, soak_max_failures, 0,
46           "The number of iterations in soak tests that are allowed to fail "
47           "(either due to non-OK status code or exceeding the per-iteration "
48           "max acceptable latency).");
49 ABSL_FLAG(int32_t, soak_per_iteration_max_acceptable_latency_ms, 1000,
50           "The number of milliseconds a single iteration in the two soak tests "
51           "(rpc_soak and channel_soak) should take.");
52 ABSL_FLAG(
53     int32_t, soak_overall_timeout_seconds, 10,
54     "The overall number of seconds after which a soak test should stop and "
55     "fail, if the desired number of iterations have not yet completed.");
56 ABSL_FLAG(int32_t, soak_min_time_ms_between_rpcs, 0,
57           "The minimum time in milliseconds between consecutive RPCs in a soak "
58           "test (rpc_soak or channel_soak), useful for limiting QPS");
59 ABSL_FLAG(
60     int32_t, soak_request_size, 271828,
61     "The request size in a soak RPC. "
62     "The default value is set based on the interop large unary test case.");
63 ABSL_FLAG(
64     int32_t, soak_response_size, 314159,
65     "The response size in a soak RPCi. "
66     "The default value is set based on the interop large unary test case.");
67 ABSL_FLAG(std::string, test_case, "rpc_soak",
68           "Configure different test cases. Valid options are: "
69           "rpc_soak: sends --soak_iterations large_unary RPCs; "
70           "channel_soak: sends --soak_iterations RPCs, rebuilding the channel "
71           "each time");
72 
main(int argc,char ** argv)73 int main(int argc, char** argv) {
74   grpc::testing::TestEnvironment env(&argc, argv);
75   grpc::testing::InitTest(&argc, &argv, true);
76   LOG(INFO) << "Testing these cases: " << absl::GetFlag(FLAGS_test_case);
77   std::string test_case = absl::GetFlag(FLAGS_test_case);
78   // validate flags
79   std::vector<std::string> uris =
80       absl::StrSplit(absl::GetFlag(FLAGS_server_uris), ',');
81   std::vector<std::string> creds =
82       absl::StrSplit(absl::GetFlag(FLAGS_credentials_types), ',');
83   if (uris.size() != creds.size()) {
84     LOG(ERROR) << "Number of entries in --server_uris " << uris.size()
85                << " != number of entries in --credentials_types "
86                << creds.size();
87     CHECK(0);
88   }
89   if (uris.empty()) {
90     LOG(ERROR) << "--server_uris has zero entries";
91     CHECK(0);
92   }
93   // construct and start clients
94   std::vector<std::thread> threads;
95   for (size_t i = 0; i < uris.size(); i++) {
96     threads.push_back(std::thread([uris, creds, i, test_case]() {
97       auto channel_creation_func = [uris, creds, i](grpc::ChannelArguments) {
98         return grpc::CreateTestChannel(uris[i], creds[i],
99                                        nullptr /* call creds */);
100       };
101       grpc::testing::InteropClient client(channel_creation_func, true, false);
102       if (test_case == "rpc_soak") {
103         client.DoRpcSoakTest(
104             uris[i], absl::GetFlag(FLAGS_soak_iterations),
105             absl::GetFlag(FLAGS_soak_max_failures),
106             absl::GetFlag(FLAGS_soak_per_iteration_max_acceptable_latency_ms),
107             absl::GetFlag(FLAGS_soak_min_time_ms_between_rpcs),
108             absl::GetFlag(FLAGS_soak_overall_timeout_seconds),
109             absl::GetFlag(FLAGS_soak_request_size),
110             absl::GetFlag(FLAGS_soak_response_size));
111       } else if (test_case == "channel_soak") {
112         client.DoChannelSoakTest(
113             uris[i], absl::GetFlag(FLAGS_soak_iterations),
114             absl::GetFlag(FLAGS_soak_max_failures),
115             absl::GetFlag(FLAGS_soak_per_iteration_max_acceptable_latency_ms),
116             absl::GetFlag(FLAGS_soak_min_time_ms_between_rpcs),
117             absl::GetFlag(FLAGS_soak_overall_timeout_seconds),
118             absl::GetFlag(FLAGS_soak_request_size),
119             absl::GetFlag(FLAGS_soak_response_size));
120       } else {
121         LOG(ERROR)
122             << "Invalid test case, must be either rpc_soak or channel_soak";
123         CHECK(0);
124       }
125     }));
126   }
127   for (auto& thd : threads) {
128     thd.join();
129   }
130   LOG(INFO) << "All clients done!";
131   return 0;
132 }
133