bm_fullstack_streaming_ping_pong.cc 4.8 KB

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