Change client context allocation

pull/18881/head
Na-Na Pang 6 years ago
parent a7888f0f1a
commit 762e58b574
  1. 15
      test/cpp/microbenchmarks/callback_unary_ping_pong.h

@ -37,26 +37,26 @@ namespace testing {
*/
// Send next rpc when callback function is evoked.
void SendCallbackUnaryPingPong(benchmark::State* state, EchoRequest* request,
EchoResponse* response,
void SendCallbackUnaryPingPong(benchmark::State* state, ClientContext* cli_ctx,
EchoRequest* request, EchoResponse* response,
EchoTestService::Stub* stub_, bool* done,
std::mutex* mu, std::condition_variable* cv) {
int response_msgs_size = state->range(1);
ClientContext* cli_ctx = new ClientContext();
cli_ctx->AddMetadata(kServerMessageSize, grpc::to_string(response_msgs_size));
stub_->experimental_async()->Echo(
cli_ctx, request, response,
[state, cli_ctx, request, response, stub_, done, mu, cv](Status s) {
GPR_ASSERT(s.ok());
if (state->KeepRunning()) {
SendCallbackUnaryPingPong(state, request, response, stub_, done, mu,
cv);
cli_ctx->~ClientContext();
new (cli_ctx) ClientContext();
SendCallbackUnaryPingPong(state, cli_ctx, request, response, stub_,
done, mu, cv);
} else {
std::lock_guard<std::mutex> l(*mu);
*done = true;
cv->notify_one();
}
delete cli_ctx;
});
};
@ -70,6 +70,7 @@ static void BM_CallbackUnaryPingPong(benchmark::State& state) {
EchoTestService::NewStub(fixture->channel()));
EchoRequest request;
EchoResponse response;
ClientContext cli_ctx;
if (request_msgs_size > 0) {
request.set_message(std::string(request_msgs_size, 'a'));
@ -82,7 +83,7 @@ static void BM_CallbackUnaryPingPong(benchmark::State& state) {
bool done = false;
if (state.KeepRunning()) {
GPR_TIMER_SCOPE("BenchmarkCycle", 0);
SendCallbackUnaryPingPong(&state, &request, &response, stub_.get(), &done,
SendCallbackUnaryPingPong(&state, &cli_ctx, &request, &response, stub_.get(), &done,
&mu, &cv);
}
std::unique_lock<std::mutex> l(mu);

Loading…
Cancel
Save