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