|
|
|
@ -43,13 +43,46 @@ extern "C" { |
|
|
|
|
|
|
|
|
|
#include "third_party/benchmark/include/benchmark/benchmark.h" |
|
|
|
|
|
|
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
|
|
#ifdef GPR_LOW_LEVEL_COUNTERS |
|
|
|
|
extern "C" gpr_atm gpr_mu_locks; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
static class InitializeStuff { |
|
|
|
|
public: |
|
|
|
|
InitializeStuff() { grpc_init(); } |
|
|
|
|
~InitializeStuff() { grpc_shutdown(); } |
|
|
|
|
} initialize_stuff; |
|
|
|
|
|
|
|
|
|
class TrackCounters { |
|
|
|
|
public: |
|
|
|
|
TrackCounters(benchmark::State& state) : state_(state) {} |
|
|
|
|
|
|
|
|
|
~TrackCounters() { |
|
|
|
|
std::ostringstream out; |
|
|
|
|
#ifdef GPR_LOW_LEVEL_COUNTERS |
|
|
|
|
out << " locks/iter:" << ((double)(gpr_atm_no_barrier_load(&gpr_mu_locks) - |
|
|
|
|
mu_locks_at_start_) / |
|
|
|
|
(double)state_.iterations()) |
|
|
|
|
<< " atm_rmw/iter:" |
|
|
|
|
<< ((double)(gpr_atm_no_barrier_load(&gpr_counter_rmw) - |
|
|
|
|
rmw_at_start_) / |
|
|
|
|
(double)state_.iterations()); |
|
|
|
|
#endif |
|
|
|
|
state_.SetLabel(out.str()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
benchmark::State& state_; |
|
|
|
|
#ifdef GPR_LOW_LEVEL_COUNTERS |
|
|
|
|
const size_t mu_locks_at_start_ = gpr_atm_no_barrier_load(&gpr_mu_locks); |
|
|
|
|
const size_t rmw_at_start_ = gpr_atm_no_barrier_load(&gpr_counter_rmw); |
|
|
|
|
#endif |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void BM_NoOpExecCtx(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
while (state.KeepRunning()) { |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
@ -58,6 +91,7 @@ static void BM_NoOpExecCtx(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_NoOpExecCtx); |
|
|
|
|
|
|
|
|
|
static void BM_WellFlushed(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
while (state.KeepRunning()) { |
|
|
|
|
grpc_exec_ctx_flush(&exec_ctx); |
|
|
|
@ -69,6 +103,7 @@ BENCHMARK(BM_WellFlushed); |
|
|
|
|
static void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} |
|
|
|
|
|
|
|
|
|
static void BM_ClosureInitAgainstExecCtx(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_closure c; |
|
|
|
|
while (state.KeepRunning()) { |
|
|
|
|
benchmark::DoNotOptimize( |
|
|
|
@ -78,6 +113,7 @@ static void BM_ClosureInitAgainstExecCtx(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureInitAgainstExecCtx); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureInitAgainstCombiner(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_combiner* combiner = grpc_combiner_create(NULL); |
|
|
|
|
grpc_closure c; |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
@ -91,6 +127,7 @@ static void BM_ClosureInitAgainstCombiner(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureInitAgainstCombiner); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureRunOnExecCtx(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_closure c; |
|
|
|
|
grpc_closure_init(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
@ -103,6 +140,7 @@ static void BM_ClosureRunOnExecCtx(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureRunOnExecCtx); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureCreateAndRun(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
while (state.KeepRunning()) { |
|
|
|
|
grpc_closure_run(&exec_ctx, grpc_closure_create(DoNothing, NULL, |
|
|
|
@ -114,6 +152,7 @@ static void BM_ClosureCreateAndRun(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureCreateAndRun); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureInitAndRun(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_closure c; |
|
|
|
|
while (state.KeepRunning()) { |
|
|
|
@ -126,6 +165,7 @@ static void BM_ClosureInitAndRun(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureInitAndRun); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureSchedOnExecCtx(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_closure c; |
|
|
|
|
grpc_closure_init(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
@ -138,6 +178,7 @@ static void BM_ClosureSchedOnExecCtx(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureSchedOnExecCtx); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureSched2OnExecCtx(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_closure c1; |
|
|
|
|
grpc_closure c2; |
|
|
|
|
grpc_closure_init(&c1, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
|
|
|
@ -153,6 +194,7 @@ static void BM_ClosureSched2OnExecCtx(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureSched2OnExecCtx); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_closure c1; |
|
|
|
|
grpc_closure c2; |
|
|
|
|
grpc_closure c3; |
|
|
|
@ -171,6 +213,7 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureSched3OnExecCtx); |
|
|
|
|
|
|
|
|
|
static void BM_AcquireMutex(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
// for comparison with the combiner stuff below
|
|
|
|
|
gpr_mu mu; |
|
|
|
|
gpr_mu_init(&mu); |
|
|
|
@ -185,6 +228,7 @@ static void BM_AcquireMutex(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_AcquireMutex); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureSchedOnCombiner(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_combiner* combiner = grpc_combiner_create(NULL); |
|
|
|
|
grpc_closure c; |
|
|
|
|
grpc_closure_init(&c, DoNothing, NULL, |
|
|
|
@ -200,6 +244,7 @@ static void BM_ClosureSchedOnCombiner(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureSchedOnCombiner); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureSched2OnCombiner(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_combiner* combiner = grpc_combiner_create(NULL); |
|
|
|
|
grpc_closure c1; |
|
|
|
|
grpc_closure c2; |
|
|
|
@ -219,6 +264,7 @@ static void BM_ClosureSched2OnCombiner(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureSched2OnCombiner); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureSched3OnCombiner(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_combiner* combiner = grpc_combiner_create(NULL); |
|
|
|
|
grpc_closure c1; |
|
|
|
|
grpc_closure c2; |
|
|
|
@ -242,6 +288,7 @@ static void BM_ClosureSched3OnCombiner(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureSched3OnCombiner); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_combiner* combiner1 = grpc_combiner_create(NULL); |
|
|
|
|
grpc_combiner* combiner2 = grpc_combiner_create(NULL); |
|
|
|
|
grpc_closure c1; |
|
|
|
@ -263,6 +310,7 @@ static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureSched2OnTwoCombiners); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_combiner* combiner1 = grpc_combiner_create(NULL); |
|
|
|
|
grpc_combiner* combiner2 = grpc_combiner_create(NULL); |
|
|
|
|
grpc_closure c1; |
|
|
|
@ -323,6 +371,7 @@ class Rescheduler { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void BM_ClosureReschedOnExecCtx(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
Rescheduler r(state, grpc_schedule_on_exec_ctx); |
|
|
|
|
r.ScheduleFirst(&exec_ctx); |
|
|
|
@ -331,6 +380,7 @@ static void BM_ClosureReschedOnExecCtx(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureReschedOnExecCtx); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureReschedOnCombiner(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_combiner* combiner = grpc_combiner_create(NULL); |
|
|
|
|
Rescheduler r(state, grpc_combiner_scheduler(combiner, false)); |
|
|
|
@ -342,6 +392,7 @@ static void BM_ClosureReschedOnCombiner(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ClosureReschedOnCombiner); |
|
|
|
|
|
|
|
|
|
static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) { |
|
|
|
|
TrackCounters track_counters(state); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_combiner* combiner = grpc_combiner_create(NULL); |
|
|
|
|
Rescheduler r(state, grpc_combiner_finally_scheduler(combiner, false)); |
|
|
|
|