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_unary_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 // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
33 // internal microbenchmarking tooling
SweepSizesArgs(benchmark::internal::Benchmark * b)34 static void SweepSizesArgs(benchmark::internal::Benchmark* b) {
35 b->Args({0, 0});
36 for (int i = 1; i <= 128 * 1024 * 1024; i *= 8) {
37 b->Args({i, 0});
38 b->Args({0, i});
39 b->Args({i, i});
40 }
41 }
42
43 BENCHMARK_TEMPLATE(BM_UnaryPingPong, TCP, NoOpMutator, NoOpMutator)
44 ->Apply(SweepSizesArgs);
45 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinTCP, NoOpMutator, NoOpMutator)
46 ->Apply(SweepSizesArgs);
47 BENCHMARK_TEMPLATE(BM_UnaryPingPong, UDS, NoOpMutator, NoOpMutator)
48 ->Args({0, 0});
49 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinUDS, NoOpMutator, NoOpMutator)
50 ->Args({0, 0});
51 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, NoOpMutator)
52 ->Apply(SweepSizesArgs);
53 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinInProcess, NoOpMutator, NoOpMutator)
54 ->Apply(SweepSizesArgs);
55 BENCHMARK_TEMPLATE(BM_UnaryPingPong, SockPair, NoOpMutator, NoOpMutator)
56 ->Args({0, 0});
57 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinSockPair, NoOpMutator, NoOpMutator)
58 ->Args({0, 0});
59 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
60 Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
61 ->Args({0, 0});
62 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
63 Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
64 ->Args({0, 0});
65 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
66 Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
67 NoOpMutator)
68 ->Args({0, 0});
69 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
70 Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
71 ->Args({0, 0});
72 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
73 Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
74 ->Args({0, 0});
75 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
76 Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
77 NoOpMutator)
78 ->Args({0, 0});
79 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
80 Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
81 ->Args({0, 0});
82 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
83 Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
84 ->Args({0, 0});
85 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
86 Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
87 ->Args({0, 0});
88 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
89 Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
90 ->Args({0, 0});
91 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
92 Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
93 ->Args({0, 0});
94 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
95 Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
96 ->Args({0, 0});
97 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
98 Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
99 ->Args({0, 0});
100 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
101 Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
102 ->Args({0, 0});
103 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
104 Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
105 ->Args({0, 0});
106 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
107 Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
108 ->Args({0, 0});
109
110 } // namespace testing
111 } // namespace grpc
112
113 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
114 // and others do not. This allows us to support both modes.
115 namespace benchmark {
RunTheBenchmarksNamespaced()116 void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
117 } // namespace benchmark
118
main(int argc,char ** argv)119 int main(int argc, char** argv) {
120 grpc::testing::TestEnvironment env(&argc, argv);
121 LibraryInitializer libInit;
122 ::benchmark::Initialize(&argc, argv);
123 grpc::testing::InitTest(&argc, &argv, false);
124 benchmark::RunTheBenchmarksNamespaced();
125 return 0;
126 }
127