aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/microbenchmarks
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp/microbenchmarks')
-rw-r--r--test/cpp/microbenchmarks/BUILD16
-rw-r--r--test/cpp/microbenchmarks/bm_byte_buffer.cc65
-rw-r--r--test/cpp/microbenchmarks/bm_chttp2_transport.cc4
-rw-r--r--test/cpp/microbenchmarks/bm_cq_multiple_threads.cc1
-rw-r--r--test/cpp/microbenchmarks/bm_timer.cc118
-rw-r--r--test/cpp/microbenchmarks/fullstack_fixtures.h2
6 files changed, 203 insertions, 3 deletions
diff --git a/test/cpp/microbenchmarks/BUILD b/test/cpp/microbenchmarks/BUILD
index 097e92f583..a29462f78f 100644
--- a/test/cpp/microbenchmarks/BUILD
+++ b/test/cpp/microbenchmarks/BUILD
@@ -24,7 +24,7 @@ grpc_cc_test(
external_deps = [
"benchmark",
],
- deps = ["//test/core/util:gpr_test_util"],
+ deps = ["//test/core/util:grpc_test_util"],
)
grpc_cc_library(
@@ -62,6 +62,13 @@ grpc_cc_binary(
)
grpc_cc_binary(
+ name = "bm_byte_buffer",
+ testonly = 1,
+ srcs = ["bm_byte_buffer.cc"],
+ deps = [":helpers"],
+)
+
+grpc_cc_binary(
name = "bm_channel",
testonly = 1,
srcs = ["bm_channel.cc"],
@@ -182,3 +189,10 @@ grpc_cc_binary(
"//src/proto/grpc/testing:echo_proto",
],
)
+
+grpc_cc_binary(
+ name = "bm_timer",
+ testonly = 1,
+ srcs = ["bm_timer.cc"],
+ deps = [":helpers"],
+)
diff --git a/test/cpp/microbenchmarks/bm_byte_buffer.cc b/test/cpp/microbenchmarks/bm_byte_buffer.cc
new file mode 100644
index 0000000000..a359e6f621
--- /dev/null
+++ b/test/cpp/microbenchmarks/bm_byte_buffer.cc
@@ -0,0 +1,65 @@
+/*
+ *
+ * Copyright 2015 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* This benchmark exists to show that byte-buffer copy is size-independent */
+
+#include <memory>
+
+#include <benchmark/benchmark.h>
+#include <grpcpp/impl/grpc_library.h>
+#include <grpcpp/support/byte_buffer.h>
+#include "test/cpp/microbenchmarks/helpers.h"
+#include "test/cpp/util/test_config.h"
+
+namespace grpc {
+namespace testing {
+
+auto& force_library_initialization = Library::get();
+
+static void BM_ByteBuffer_Copy(benchmark::State& state) {
+ int num_slices = state.range(0);
+ size_t slice_size = state.range(1);
+ std::vector<grpc::Slice> slices;
+ while (num_slices > 0) {
+ num_slices--;
+ std::unique_ptr<char[]> buf(new char[slice_size]);
+ memset(buf.get(), 0, slice_size);
+ slices.emplace_back(buf.get(), slice_size);
+ }
+ grpc::ByteBuffer bb(slices.data(), num_slices);
+ while (state.KeepRunning()) {
+ grpc::ByteBuffer cc(bb);
+ }
+}
+BENCHMARK(BM_ByteBuffer_Copy)->Ranges({{1, 64}, {1, 1024 * 1024}});
+
+} // namespace testing
+} // namespace grpc
+
+// Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
+// and others do not. This allows us to support both modes.
+namespace benchmark {
+void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
+} // namespace benchmark
+
+int main(int argc, char** argv) {
+ ::benchmark::Initialize(&argc, argv);
+ ::grpc::testing::InitTest(&argc, &argv, false);
+ benchmark::RunTheBenchmarksNamespaced();
+ return 0;
+}
diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc
index f7ae16e61d..650152ecc0 100644
--- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc
+++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc
@@ -54,7 +54,8 @@ class DummyEndpoint : public grpc_endpoint {
destroy,
get_resource_user,
get_peer,
- get_fd};
+ get_fd,
+ can_track_err};
grpc_endpoint::vtable = &my_vtable;
ru_ = grpc_resource_user_create(Library::get().rq(), "dummy_endpoint");
}
@@ -125,6 +126,7 @@ class DummyEndpoint : public grpc_endpoint {
}
static char* get_peer(grpc_endpoint* ep) { return gpr_strdup("test"); }
static int get_fd(grpc_endpoint* ep) { return 0; }
+ static bool can_track_err(grpc_endpoint* ep) { return false; }
};
class Fixture {
diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
index 85767c8758..dca97c85b1 100644
--- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
+++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
@@ -94,6 +94,7 @@ static const grpc_event_engine_vtable* init_engine_vtable(bool) {
g_vtable.pollset_destroy = pollset_destroy;
g_vtable.pollset_work = pollset_work;
g_vtable.pollset_kick = pollset_kick;
+ g_vtable.shutdown_background_closure = [] {};
g_vtable.shutdown_engine = [] {};
return &g_vtable;
diff --git a/test/cpp/microbenchmarks/bm_timer.cc b/test/cpp/microbenchmarks/bm_timer.cc
new file mode 100644
index 0000000000..f5a411251b
--- /dev/null
+++ b/test/cpp/microbenchmarks/bm_timer.cc
@@ -0,0 +1,118 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <benchmark/benchmark.h>
+#include <string.h>
+#include <atomic>
+#include <vector>
+
+#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include "test/cpp/microbenchmarks/helpers.h"
+#include "test/cpp/util/test_config.h"
+
+#include "src/core/lib/iomgr/timer.h"
+
+namespace grpc {
+namespace testing {
+
+auto& force_library_initialization = Library::get();
+
+struct TimerClosure {
+ grpc_timer timer;
+ grpc_closure closure;
+};
+
+static void BM_InitCancelTimer(benchmark::State& state) {
+ constexpr int kTimerCount = 1024;
+ TrackCounters track_counters;
+ grpc_core::ExecCtx exec_ctx;
+ std::vector<TimerClosure> timer_closures(kTimerCount);
+ int i = 0;
+ while (state.KeepRunning()) {
+ TimerClosure* timer_closure = &timer_closures[i++ % kTimerCount];
+ GRPC_CLOSURE_INIT(&timer_closure->closure,
+ [](void* /*args*/, grpc_error* /*err*/) {}, nullptr,
+ grpc_schedule_on_exec_ctx);
+ grpc_timer_init(&timer_closure->timer, GRPC_MILLIS_INF_FUTURE,
+ &timer_closure->closure);
+ grpc_timer_cancel(&timer_closure->timer);
+ exec_ctx.Flush();
+ }
+ track_counters.Finish(state);
+}
+BENCHMARK(BM_InitCancelTimer);
+
+static void BM_TimerBatch(benchmark::State& state) {
+ constexpr int kTimerCount = 1024;
+ const bool check = state.range(0);
+ const bool reverse = state.range(1);
+
+ const grpc_millis start =
+ reverse ? GRPC_MILLIS_INF_FUTURE : GRPC_MILLIS_INF_FUTURE - kTimerCount;
+ const grpc_millis end =
+ reverse ? GRPC_MILLIS_INF_FUTURE - kTimerCount : GRPC_MILLIS_INF_FUTURE;
+ const grpc_millis increment = reverse ? -1 : 1;
+
+ TrackCounters track_counters;
+ grpc_core::ExecCtx exec_ctx;
+ std::vector<TimerClosure> timer_closures(kTimerCount);
+ while (state.KeepRunning()) {
+ for (grpc_millis deadline = start; deadline != end; deadline += increment) {
+ TimerClosure* timer_closure = &timer_closures[deadline % kTimerCount];
+ GRPC_CLOSURE_INIT(&timer_closure->closure,
+ [](void* /*args*/, grpc_error* /*err*/) {}, nullptr,
+ grpc_schedule_on_exec_ctx);
+
+ grpc_timer_init(&timer_closure->timer, deadline, &timer_closure->closure);
+ }
+ if (check) {
+ grpc_millis next;
+ grpc_timer_check(&next);
+ }
+ for (grpc_millis deadline = start; deadline != end; deadline += increment) {
+ TimerClosure* timer_closure = &timer_closures[deadline % kTimerCount];
+ grpc_timer_cancel(&timer_closure->timer);
+ }
+ exec_ctx.Flush();
+ }
+ track_counters.Finish(state);
+}
+BENCHMARK(BM_TimerBatch)
+ ->Args({/*check=*/false, /*reverse=*/false})
+ ->Args({/*check=*/false, /*reverse=*/true})
+ ->Args({/*check=*/true, /*reverse=*/false})
+ ->Args({/*check=*/true, /*reverse=*/true})
+ ->ThreadRange(1, 128);
+
+} // namespace testing
+} // namespace grpc
+
+// Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
+// and others do not. This allows us to support both modes.
+namespace benchmark {
+void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
+} // namespace benchmark
+
+int main(int argc, char** argv) {
+ ::benchmark::Initialize(&argc, argv);
+ ::grpc::testing::InitTest(&argc, &argv, false);
+ benchmark::RunTheBenchmarksNamespaced();
+ return 0;
+}
diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h
index 71e8d9972b..6bbf553bbd 100644
--- a/test/cpp/microbenchmarks/fullstack_fixtures.h
+++ b/test/cpp/microbenchmarks/fullstack_fixtures.h
@@ -200,7 +200,7 @@ class EndpointPairFixture : public BaseFixture {
}
grpc_server_setup_transport(server_->c_server(), server_transport_,
- nullptr, server_args, 0);
+ nullptr, server_args, nullptr);
grpc_chttp2_transport_start_reading(server_transport_, nullptr, nullptr);
}