bm_fullstack_unary_ping_pong.cc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_unary_ping_pong.h"
  21. #include "test/cpp/util/test_config.h"
  22. namespace grpc {
  23. namespace testing {
  24. /*******************************************************************************
  25. * CONFIGURATIONS
  26. */
  27. // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
  28. // internal microbenchmarking tooling
  29. static void SweepSizesArgs(benchmark::internal::Benchmark* b) {
  30. b->Args({0, 0});
  31. for (int i = 1; i <= 128 * 1024 * 1024; i *= 8) {
  32. b->Args({i, 0});
  33. b->Args({0, i});
  34. b->Args({i, i});
  35. }
  36. }
  37. BENCHMARK_TEMPLATE(BM_UnaryPingPong, TCP, NoOpMutator, NoOpMutator)
  38. ->Apply(SweepSizesArgs);
  39. BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinTCP, NoOpMutator, NoOpMutator)
  40. ->Apply(SweepSizesArgs);
  41. BENCHMARK_TEMPLATE(BM_UnaryPingPong, UDS, NoOpMutator, NoOpMutator)
  42. ->Args({0, 0});
  43. BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinUDS, NoOpMutator, NoOpMutator)
  44. ->Args({0, 0});
  45. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, NoOpMutator)
  46. ->Apply(SweepSizesArgs);
  47. BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinInProcess, NoOpMutator, NoOpMutator)
  48. ->Apply(SweepSizesArgs);
  49. BENCHMARK_TEMPLATE(BM_UnaryPingPong, SockPair, NoOpMutator, NoOpMutator)
  50. ->Args({0, 0});
  51. BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinSockPair, NoOpMutator, NoOpMutator)
  52. ->Args({0, 0});
  53. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, NoOpMutator)
  54. ->Apply(SweepSizesArgs);
  55. BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinInProcessCHTTP2, NoOpMutator,
  56. NoOpMutator)
  57. ->Apply(SweepSizesArgs);
  58. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  59. Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
  60. ->Args({0, 0});
  61. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  62. Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
  63. ->Args({0, 0});
  64. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  65. Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
  66. NoOpMutator)
  67. ->Args({0, 0});
  68. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  69. Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
  70. ->Args({0, 0});
  71. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  72. Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
  73. ->Args({0, 0});
  74. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  75. Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
  76. NoOpMutator)
  77. ->Args({0, 0});
  78. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
  79. Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
  80. ->Args({0, 0});
  81. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
  82. Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
  83. ->Args({0, 0});
  84. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
  85. Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
  86. ->Args({0, 0});
  87. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  88. Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
  89. ->Args({0, 0});
  90. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  91. Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
  92. ->Args({0, 0});
  93. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
  94. Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
  95. ->Args({0, 0});
  96. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
  97. Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
  98. ->Args({0, 0});
  99. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
  100. Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
  101. ->Args({0, 0});
  102. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
  103. Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
  104. ->Args({0, 0});
  105. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
  106. Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
  107. ->Args({0, 0});
  108. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  109. Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
  110. ->Args({0, 0});
  111. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  112. Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
  113. ->Args({0, 0});
  114. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  115. Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
  116. NoOpMutator)
  117. ->Args({0, 0});
  118. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  119. Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
  120. ->Args({0, 0});
  121. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  122. Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
  123. ->Args({0, 0});
  124. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  125. Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
  126. NoOpMutator)
  127. ->Args({0, 0});
  128. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
  129. Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
  130. ->Args({0, 0});
  131. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
  132. Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
  133. ->Args({0, 0});
  134. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
  135. Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
  136. ->Args({0, 0});
  137. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  138. Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
  139. ->Args({0, 0});
  140. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  141. Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
  142. ->Args({0, 0});
  143. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
  144. Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
  145. ->Args({0, 0});
  146. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
  147. Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
  148. ->Args({0, 0});
  149. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
  150. Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
  151. ->Args({0, 0});
  152. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
  153. Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
  154. ->Args({0, 0});
  155. BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
  156. Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
  157. ->Args({0, 0});
  158. } // namespace testing
  159. } // namespace grpc
  160. // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
  161. // and others do not. This allows us to support both modes.
  162. namespace benchmark {
  163. void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
  164. } // namespace benchmark
  165. int main(int argc, char** argv) {
  166. grpc::testing::TestEnvironment env(argc, argv);
  167. LibraryInitializer libInit;
  168. ::benchmark::Initialize(&argc, argv);
  169. grpc::testing::InitTest(&argc, &argv, false);
  170. benchmark::RunTheBenchmarksNamespaced();
  171. return 0;
  172. }