qps_interarrival_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 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 <chrono>
20 #include <iostream>
21 
22 // Use the C histogram rather than C++ to avoid depending on proto
27 
30 
31 static void RunTest(RandomDistInterface&& r, int threads,
32  const std::string& title) {
34  timer.init(r, threads);
35  grpc_histogram* h(grpc_histogram_create(0.01, 60e9));
36 
37  for (int i = 0; i < 10000000; i++) {
38  for (int j = 0; j < threads; j++) {
39  grpc_histogram_add(h, timer.next(j));
40  }
41  }
42 
43  std::cout << title << " Distribution" << std::endl;
44  std::cout << "Value, Percentile" << std::endl;
45  for (double pct = 0.0; pct < 100.0; pct += 1.0) {
46  std::cout << grpc_histogram_percentile(h, pct) << "," << pct << std::endl;
47  }
48 
50 }
51 
53 
54 int main(int argc, char** argv) {
56  grpc::testing::InitTest(&argc, &argv, true);
57 
58  RunTest(ExpDist(10.0), 5, std::string("Exponential(10)"));
59  return 0;
60 }
grpc::testing::InterarrivalTimer
Definition: interarrival.h:74
grpc::testing::InitTest
void InitTest(int *argc, char ***argv, bool remove_flags)
Definition: test_config_cc.cc:28
generate.env
env
Definition: generate.py:37
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
threads
static uv_thread_t * threads
Definition: threadpool.c:38
interarrival.h
grpc_histogram_destroy
void grpc_histogram_destroy(grpc_histogram *h)
Definition: histogram.cc:99
grpc_histogram
Definition: histogram.cc:37
main
int main(int argc, char **argv)
Definition: qps_interarrival_test.cc:54
grpc_histogram_percentile
double grpc_histogram_percentile(grpc_histogram *h, double percentile)
Definition: histogram.cc:198
grpc::testing::ExpDist
Definition: interarrival.h:57
histogram.h
grpc_histogram_create
grpc_histogram * grpc_histogram_create(double resolution, double max_bucket_start)
Definition: histogram.cc:77
test_config.h
fix_build_deps.r
r
Definition: fix_build_deps.py:491
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
test_config.h
grpc::testing::RandomDistInterface
Definition: interarrival.h:39
grpc_histogram_add
void grpc_histogram_add(grpc_histogram *h, double x)
Definition: histogram.cc:104
RunTest
static void RunTest(RandomDistInterface &&r, int threads, const std::string &title)
Definition: qps_interarrival_test.cc:31
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
timer
static uv_timer_t timer
Definition: test-callback-stack.c:34


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:50