1 /*
2 *
3 * Copyright 2019 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 "test/core/util/test_config.h"
20 #include "test/cpp/microbenchmarks/callback_streaming_ping_pong.h"
21 #include "test/cpp/util/test_config.h"
22
23 namespace grpc {
24 namespace testing {
25
26 /*******************************************************************************
27 * CONFIGURATIONS
28 */
29
30 // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
31 // internal microbenchmarking tooling
StreamingPingPongMsgSizeArgs(benchmark::internal::Benchmark * b)32 static void StreamingPingPongMsgSizeArgs(benchmark::internal::Benchmark* b) {
33 // base case: 0 byte ping-pong msgs
34 b->Args({0, 1});
35 b->Args({0, 2});
36
37 for (int msg_size = 1; msg_size <= 128 * 1024 * 1024; msg_size *= 8) {
38 b->Args({msg_size, 1});
39 b->Args({msg_size, 2});
40 }
41 }
42
43 // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
44 // internal microbenchmarking tooling
StreamingPingPongMsgsNumberArgs(benchmark::internal::Benchmark * b)45 static void StreamingPingPongMsgsNumberArgs(benchmark::internal::Benchmark* b) {
46 for (int msg_number = 1; msg_number <= 256 * 1024; msg_number *= 8) {
47 b->Args({0, msg_number});
48 b->Args({1024, msg_number});
49 }
50 }
51
52 // Streaming with different message size
53 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
54 NoOpMutator)
55 ->Apply(StreamingPingPongMsgSizeArgs);
56 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, MinInProcess, NoOpMutator,
57 NoOpMutator)
58 ->Apply(StreamingPingPongMsgSizeArgs);
59
60 // Streaming with different message number
61 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
62 NoOpMutator)
63 ->Apply(StreamingPingPongMsgsNumberArgs);
64 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, MinInProcess, NoOpMutator,
65 NoOpMutator)
66 ->Apply(StreamingPingPongMsgsNumberArgs);
67
68 // Client context with different metadata
69 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
70 Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
71 ->Args({0, 1});
72 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
73 Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
74 ->Args({0, 1});
75 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
76 Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
77 NoOpMutator)
78 ->Args({0, 1});
79 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
80 Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
81 ->Args({0, 1});
82 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
83 Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
84 ->Args({0, 1});
85 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
86 Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
87 NoOpMutator)
88 ->Args({0, 1});
89 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
90 Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
91 ->Args({0, 1});
92 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
93 Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
94 ->Args({0, 1});
95 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
96 Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
97 ->Args({0, 1});
98
99 // Server context with different metadata
100 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
101 Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
102 ->Args({0, 1});
103 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
104 Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
105 ->Args({0, 1});
106 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
107 Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
108 ->Args({0, 1});
109 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
110 Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
111 ->Args({0, 1});
112 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
113 Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
114 ->Args({0, 1});
115 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
116 Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
117 ->Args({0, 1});
118 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
119 Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
120 ->Args({0, 1});
121
122 } // namespace testing
123 } // namespace grpc
124
125 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
126 // and others do not. This allows us to support both modes.
127 namespace benchmark {
RunTheBenchmarksNamespaced()128 void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
129 } // namespace benchmark
130
main(int argc,char ** argv)131 int main(int argc, char** argv) {
132 grpc::testing::TestEnvironment env(argc, argv);
133 LibraryInitializer libInit;
134 ::benchmark::Initialize(&argc, argv);
135 ::grpc::testing::InitTest(&argc, &argv, false);
136 benchmark::RunTheBenchmarksNamespaced();
137 return 0;
138 }
139