| 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/build.h" |
| 22 |
#include "test/core/util/test_config.h" |
| 23 |
#include "test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h" |
| 24 |
#include "test/cpp/util/test_config.h" |
| 25 |
|
| 26 |
namespace grpc { |
| 27 |
namespace testing { |
| 28 |
|
| 29 |
/******************************************************************************* |
| 30 |
* CONFIGURATIONS |
| 31 |
*/ |
| 32 |
|
| 33 |
static const int kMaxMessageSize = [] { |
| 34 |
if (BuiltUnderMsan() || BuiltUnderTsan() || BuiltUnderUbsan()) { |
| 35 |
// Scale down sizes for intensive benchmarks to avoid timeouts. |
| 36 |
return 8 * 1024 * 1024; |
| 37 |
} |
| 38 |
return 128 * 1024 * 1024; |
| 39 |
}(); |
| 40 |
|
| 41 |
// Generate Args for StreamingPingPong benchmarks. Currently generates args for |
| 42 |
// only "small streams" (i.e streams with 0, 1 or 2 messages) |
| 43 |
static void StreamingPingPongArgs(benchmark::internal::Benchmark* b) { |
| 44 |
int msg_size = 0; |
| 45 |
|
| 46 |
b->Args({0, 0}); // spl case: 0 ping-pong msgs (msg_size doesn't matter here) |
| 47 |
|
| 48 |
for (msg_size = 0; msg_size <= kMaxMessageSize; |
| 49 |
msg_size == 0 ? msg_size++ : msg_size *= 8) { |
| 50 |
b->Args({msg_size, 1}); |
| 51 |
b->Args({msg_size, 2}); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
BENCHMARK_TEMPLATE(BM_StreamingPingPong, InProcessCHTTP2, NoOpMutator, |
| 56 |
NoOpMutator) |
| 57 |
->Apply(StreamingPingPongArgs); |
| 58 |
BENCHMARK_TEMPLATE(BM_StreamingPingPong, TCP, NoOpMutator, NoOpMutator) |
| 59 |
->Apply(StreamingPingPongArgs); |
| 60 |
BENCHMARK_TEMPLATE(BM_StreamingPingPong, InProcess, NoOpMutator, NoOpMutator) |
| 61 |
->Apply(StreamingPingPongArgs); |
| 62 |
|
| 63 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, InProcessCHTTP2, NoOpMutator, |
| 64 |
NoOpMutator) |
| 65 |
->Range(0, kMaxMessageSize); |
| 66 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, TCP, NoOpMutator, NoOpMutator) |
| 67 |
->Range(0, kMaxMessageSize); |
| 68 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, InProcess, NoOpMutator, |
| 69 |
NoOpMutator) |
| 70 |
->Range(0, kMaxMessageSize); |
| 71 |
|
| 72 |
BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinInProcessCHTTP2, NoOpMutator, |
| 73 |
NoOpMutator) |
| 74 |
->Apply(StreamingPingPongArgs); |
| 75 |
BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinTCP, NoOpMutator, NoOpMutator) |
| 76 |
->Apply(StreamingPingPongArgs); |
| 77 |
BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinInProcess, NoOpMutator, NoOpMutator) |
| 78 |
->Apply(StreamingPingPongArgs); |
| 79 |
|
| 80 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinInProcessCHTTP2, NoOpMutator, |
| 81 |
NoOpMutator) |
| 82 |
->Range(0, kMaxMessageSize); |
| 83 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinTCP, NoOpMutator, NoOpMutator) |
| 84 |
->Range(0, kMaxMessageSize); |
| 85 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinInProcess, NoOpMutator, |
| 86 |
NoOpMutator) |
| 87 |
->Range(0, kMaxMessageSize); |
| 88 |
|
| 89 |
// Generate Args for StreamingPingPongWithCoalescingApi benchmarks. Currently |
| 90 |
// generates args for only "small streams" (i.e streams with 0, 1 or 2 messages) |
| 91 |
static void StreamingPingPongWithCoalescingApiArgs( |
| 92 |
benchmark::internal::Benchmark* b) { |
| 93 |
int msg_size = 0; |
| 94 |
|
| 95 |
b->Args( |
| 96 |
{0, 0, 0}); // spl case: 0 ping-pong msgs (msg_size doesn't matter here) |
| 97 |
b->Args( |
| 98 |
{0, 0, 1}); // spl case: 0 ping-pong msgs (msg_size doesn't matter here) |
| 99 |
|
| 100 |
for (msg_size = 0; msg_size <= kMaxMessageSize; |
| 101 |
msg_size == 0 ? msg_size++ : msg_size *= 8) { |
| 102 |
b->Args({msg_size, 1, 0}); |
| 103 |
b->Args({msg_size, 2, 0}); |
| 104 |
b->Args({msg_size, 1, 1}); |
| 105 |
b->Args({msg_size, 2, 1}); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, InProcessCHTTP2, |
| 110 |
NoOpMutator, NoOpMutator) |
| 111 |
->Apply(StreamingPingPongWithCoalescingApiArgs); |
| 112 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, MinInProcessCHTTP2, |
| 113 |
NoOpMutator, NoOpMutator) |
| 114 |
->Apply(StreamingPingPongWithCoalescingApiArgs); |
| 115 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, InProcess, |
| 116 |
NoOpMutator, NoOpMutator) |
| 117 |
->Apply(StreamingPingPongWithCoalescingApiArgs); |
| 118 |
BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, MinInProcess, |
| 119 |
NoOpMutator, NoOpMutator) |
| 120 |
->Apply(StreamingPingPongWithCoalescingApiArgs); |
| 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 { |
| 128 |
void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); } |
| 129 |
} // namespace benchmark |
| 130 |
|
| 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 |
} |