From c7609c4f3f5471f87f3aaf66f4328accf29dd33e Mon Sep 17 00:00:00 2001 From: Yuxuan Li Date: Wed, 12 Apr 2017 17:55:31 -0700 Subject: profile cpp overhead for call create --- test/cpp/microbenchmarks/bm_call_create.cc | 79 +++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) (limited to 'test/cpp/microbenchmarks') diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 136b7c0340..2fe4e0f53b 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -166,6 +166,83 @@ static void BM_LameChannelCallCreateCpp(benchmark::State &state) { } BENCHMARK(BM_LameChannelCallCreateCpp); +static void do_nothing(void *ignored) {} + +static void BM_LameChannelCallCreateCore(benchmark::State &state) { + TrackCounters track_counters; + + grpc_channel *channel; + grpc_completion_queue *cq; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_byte_buffer *response_payload_recv = NULL; + grpc_status_code status; + grpc_slice details; + grpc::testing::EchoRequest send_request; + grpc_slice send_request_slice = + grpc_slice_new(&send_request, sizeof(send_request), do_nothing); + grpc_slice host = grpc_slice_from_static_string("localhost"); + + channel = grpc_lame_client_channel_create( + "localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah"); + cq = grpc_completion_queue_create(NULL); + + while (state.KeepRunning()) { + GPR_TIMER_SCOPE("BenchmarkCycle", 0); + grpc_call *call = grpc_channel_create_call( + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + grpc_slice_from_static_string("/EchoTestService/AsyncEcho"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_byte_buffer *request_payload_send = + grpc_raw_byte_buffer_create(&send_request_slice, 1); + + // Fill in call ops + grpc_op ops[6]; + memset(ops, 0, sizeof(ops)); + grpc_op *op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message.send_message = request_payload_send; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = + &initial_metadata_recv; + op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = &response_payload_recv; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op++; + + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops, + (size_t)(op - ops), + (void *)1, NULL)); + grpc_event ev = grpc_completion_queue_next( + cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + GPR_ASSERT(ev.type != GRPC_QUEUE_SHUTDOWN); + GPR_ASSERT(ev.success != 0); + grpc_call_destroy(call); + grpc_byte_buffer_destroy(request_payload_send); + grpc_byte_buffer_destroy(response_payload_recv); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + } + grpc_channel_destroy(channel); + grpc_completion_queue_destroy(cq); + grpc_slice_unref(send_request_slice); + track_counters.Finish(state); +} +BENCHMARK(BM_LameChannelCallCreateCore); + static void FilterDestroy(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { gpr_free(arg); @@ -560,7 +637,7 @@ static const grpc_channel_filter isolated_call_filter = { GetPeer, GetChannelInfo, "isolated_call_filter"}; -} +} // namespace isolated_call_filter class IsolatedCallFixture : public TrackCounters { public: -- cgit v1.2.3 From 784018d8a4ff251a74305406c402d9fa3bb6295b Mon Sep 17 00:00:00 2001 From: Yuxuan Li Date: Thu, 13 Apr 2017 16:17:37 -0700 Subject: use grpc_channel_create_registered_call --- test/cpp/microbenchmarks/bm_call_create.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/cpp/microbenchmarks') diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 2fe4e0f53b..ada732c233 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -181,17 +181,16 @@ static void BM_LameChannelCallCreateCore(benchmark::State &state) { grpc::testing::EchoRequest send_request; grpc_slice send_request_slice = grpc_slice_new(&send_request, sizeof(send_request), do_nothing); - grpc_slice host = grpc_slice_from_static_string("localhost"); channel = grpc_lame_client_channel_create( "localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah"); cq = grpc_completion_queue_create(NULL); - + void *rc = grpc_channel_register_call( + channel, "/grpc.testing.EchoTestService/Echo", NULL, NULL); while (state.KeepRunning()) { GPR_TIMER_SCOPE("BenchmarkCycle", 0); - grpc_call *call = grpc_channel_create_call( - channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/EchoTestService/AsyncEcho"), &host, + grpc_call *call = grpc_channel_create_registered_call( + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, rc, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); -- cgit v1.2.3 From 0bbdb022de0279168523bf3994003b1642ce742e Mon Sep 17 00:00:00 2001 From: Yuxuan Li Date: Fri, 14 Apr 2017 11:47:18 -0700 Subject: adding a benchmark for c core call create that do two separate batches. --- test/cpp/microbenchmarks/bm_call_create.cc | 83 ++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'test/cpp/microbenchmarks') diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index ada732c233..4b99a80427 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -242,6 +242,89 @@ static void BM_LameChannelCallCreateCore(benchmark::State &state) { } BENCHMARK(BM_LameChannelCallCreateCore); +static void BM_LameChannelCallCreateCoreSeparateBatch(benchmark::State &state) { + TrackCounters track_counters; + + grpc_channel *channel; + grpc_completion_queue *cq; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_byte_buffer *response_payload_recv = NULL; + grpc_status_code status; + grpc_slice details; + grpc::testing::EchoRequest send_request; + grpc_slice send_request_slice = + grpc_slice_new(&send_request, sizeof(send_request), do_nothing); + + channel = grpc_lame_client_channel_create( + "localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah"); + cq = grpc_completion_queue_create(NULL); + void *rc = grpc_channel_register_call( + channel, "/grpc.testing.EchoTestService/Echo", NULL, NULL); + while (state.KeepRunning()) { + GPR_TIMER_SCOPE("BenchmarkCycle", 0); + grpc_call *call = grpc_channel_create_registered_call( + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, rc, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_byte_buffer *request_payload_send = + grpc_raw_byte_buffer_create(&send_request_slice, 1); + + // Fill in call ops + grpc_op ops[3]; + memset(ops, 0, sizeof(ops)); + grpc_op *op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message.send_message = request_payload_send; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op++; + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops, + (size_t)(op - ops), + (void *)0, NULL)); + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = + &initial_metadata_recv; + op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = &response_payload_recv; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op++; + + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops, + (size_t)(op - ops), + (void *)1, NULL)); + grpc_event ev = grpc_completion_queue_next( + cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + GPR_ASSERT(ev.type != GRPC_QUEUE_SHUTDOWN); + GPR_ASSERT(ev.success == 0); + ev = grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), + NULL); + GPR_ASSERT(ev.type != GRPC_QUEUE_SHUTDOWN); + GPR_ASSERT(ev.success != 0); + grpc_call_destroy(call); + grpc_byte_buffer_destroy(request_payload_send); + grpc_byte_buffer_destroy(response_payload_recv); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + } + grpc_channel_destroy(channel); + grpc_completion_queue_destroy(cq); + grpc_slice_unref(send_request_slice); + track_counters.Finish(state); +} +BENCHMARK(BM_LameChannelCallCreateCoreSeparateBatch); + static void FilterDestroy(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { gpr_free(arg); -- cgit v1.2.3 From f2af0c3009bc90cee339bfc13f0d0884f35a6854 Mon Sep 17 00:00:00 2001 From: Yuxuan Li Date: Wed, 19 Apr 2017 16:45:38 -0700 Subject: change to new completion queue api --- test/cpp/microbenchmarks/bm_call_create.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/cpp/microbenchmarks') diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 4b99a80427..0aac611d43 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -184,7 +184,7 @@ static void BM_LameChannelCallCreateCore(benchmark::State &state) { channel = grpc_lame_client_channel_create( "localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah"); - cq = grpc_completion_queue_create(NULL); + cq = grpc_completion_queue_create_for_next(NULL); void *rc = grpc_channel_register_call( channel, "/grpc.testing.EchoTestService/Echo", NULL, NULL); while (state.KeepRunning()) { @@ -258,7 +258,7 @@ static void BM_LameChannelCallCreateCoreSeparateBatch(benchmark::State &state) { channel = grpc_lame_client_channel_create( "localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah"); - cq = grpc_completion_queue_create(NULL); + cq = grpc_completion_queue_create_for_next(NULL); void *rc = grpc_channel_register_call( channel, "/grpc.testing.EchoTestService/Echo", NULL, NULL); while (state.KeepRunning()) { -- cgit v1.2.3 From 0bb25f325c8870e2f9b7c4b9fb2b637691da2379 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 20 Apr 2017 14:17:23 -0700 Subject: Build fix --- test/cpp/microbenchmarks/bm_call_create.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/cpp/microbenchmarks') diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 7cd2683c31..18b7566bef 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -229,7 +229,7 @@ static void BM_LameChannelCallCreateCore(benchmark::State &state) { cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(ev.type != GRPC_QUEUE_SHUTDOWN); GPR_ASSERT(ev.success != 0); - grpc_call_destroy(call); + grpc_call_unref(call); grpc_byte_buffer_destroy(request_payload_send); grpc_byte_buffer_destroy(response_payload_recv); grpc_metadata_array_destroy(&initial_metadata_recv); @@ -312,7 +312,7 @@ static void BM_LameChannelCallCreateCoreSeparateBatch(benchmark::State &state) { NULL); GPR_ASSERT(ev.type != GRPC_QUEUE_SHUTDOWN); GPR_ASSERT(ev.success != 0); - grpc_call_destroy(call); + grpc_call_unref(call); grpc_byte_buffer_destroy(request_payload_send); grpc_byte_buffer_destroy(response_payload_recv); grpc_metadata_array_destroy(&initial_metadata_recv); -- cgit v1.2.3