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