1 /*
2  *
3  * Copyright 2016 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 /* Benchmark gRPC end2end in various configurations */
20 
21 #include "test/core/util/test_config.h"
22 #include "test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h"
23 #include "test/cpp/util/test_config.h"
24 
25 namespace grpc {
26 namespace testing {
27 
28 /*******************************************************************************
29  * CONFIGURATIONS
30  */
31 
32 // Generate Args for StreamingPingPong benchmarks. Currently generates args for
33 // only "small streams" (i.e streams with 0, 1 or 2 messages)
StreamingPingPongArgs(benchmark::internal::Benchmark * b)34 static void StreamingPingPongArgs(benchmark::internal::Benchmark* b) {
35   int msg_size = 0;
36 
37   b->Args({0, 0});  // spl case: 0 ping-pong msgs (msg_size doesn't matter here)
38 
39   for (msg_size = 0; msg_size <= 128 * 1024 * 1024;
40        msg_size == 0 ? msg_size++ : msg_size *= 8) {
41     b->Args({msg_size, 1});
42     b->Args({msg_size, 2});
43   }
44 }
45 
46 BENCHMARK_TEMPLATE(BM_StreamingPingPong, InProcessCHTTP2, NoOpMutator,
47                    NoOpMutator)
48     ->Apply(StreamingPingPongArgs);
49 BENCHMARK_TEMPLATE(BM_StreamingPingPong, TCP, NoOpMutator, NoOpMutator)
50     ->Apply(StreamingPingPongArgs);
51 BENCHMARK_TEMPLATE(BM_StreamingPingPong, InProcess, NoOpMutator, NoOpMutator)
52     ->Apply(StreamingPingPongArgs);
53 
54 BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, InProcessCHTTP2, NoOpMutator,
55                    NoOpMutator)
56     ->Range(0, 128 * 1024 * 1024);
57 BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, TCP, NoOpMutator, NoOpMutator)
58     ->Range(0, 128 * 1024 * 1024);
59 BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, InProcess, NoOpMutator,
60                    NoOpMutator)
61     ->Range(0, 128 * 1024 * 1024);
62 
63 BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinInProcessCHTTP2, NoOpMutator,
64                    NoOpMutator)
65     ->Apply(StreamingPingPongArgs);
66 BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinTCP, NoOpMutator, NoOpMutator)
67     ->Apply(StreamingPingPongArgs);
68 BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinInProcess, NoOpMutator, NoOpMutator)
69     ->Apply(StreamingPingPongArgs);
70 
71 BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinInProcessCHTTP2, NoOpMutator,
72                    NoOpMutator)
73     ->Range(0, 128 * 1024 * 1024);
74 BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinTCP, NoOpMutator, NoOpMutator)
75     ->Range(0, 128 * 1024 * 1024);
76 BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinInProcess, NoOpMutator,
77                    NoOpMutator)
78     ->Range(0, 128 * 1024 * 1024);
79 
80 // Generate Args for StreamingPingPongWithCoalescingApi benchmarks. Currently
81 // generates args for only "small streams" (i.e streams with 0, 1 or 2 messages)
StreamingPingPongWithCoalescingApiArgs(benchmark::internal::Benchmark * b)82 static void StreamingPingPongWithCoalescingApiArgs(
83     benchmark::internal::Benchmark* b) {
84   int msg_size = 0;
85 
86   b->Args(
87       {0, 0, 0});  // spl case: 0 ping-pong msgs (msg_size doesn't matter here)
88   b->Args(
89       {0, 0, 1});  // spl case: 0 ping-pong msgs (msg_size doesn't matter here)
90 
91   for (msg_size = 0; msg_size <= 128 * 1024 * 1024;
92        msg_size == 0 ? msg_size++ : msg_size *= 8) {
93     b->Args({msg_size, 1, 0});
94     b->Args({msg_size, 2, 0});
95     b->Args({msg_size, 1, 1});
96     b->Args({msg_size, 2, 1});
97   }
98 }
99 
100 BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, InProcessCHTTP2,
101                    NoOpMutator, NoOpMutator)
102     ->Apply(StreamingPingPongWithCoalescingApiArgs);
103 BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, MinInProcessCHTTP2,
104                    NoOpMutator, NoOpMutator)
105     ->Apply(StreamingPingPongWithCoalescingApiArgs);
106 BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, InProcess,
107                    NoOpMutator, NoOpMutator)
108     ->Apply(StreamingPingPongWithCoalescingApiArgs);
109 BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, MinInProcess,
110                    NoOpMutator, NoOpMutator)
111     ->Apply(StreamingPingPongWithCoalescingApiArgs);
112 
113 }  // namespace testing
114 }  // namespace grpc
115 
116 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
117 // and others do not. This allows us to support both modes.
118 namespace benchmark {
RunTheBenchmarksNamespaced()119 void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
120 }  // namespace benchmark
121 
main(int argc,char ** argv)122 int main(int argc, char** argv) {
123   grpc::testing::TestEnvironment env(argc, argv);
124   LibraryInitializer libInit;
125   ::benchmark::Initialize(&argc, argv);
126   ::grpc::testing::InitTest(&argc, &argv, false);
127   benchmark::RunTheBenchmarksNamespaced();
128   return 0;
129 }
130