Modify unary ping pong to send next rpc in callback function

pull/18881/head
Na-Na Pang 6 years ago
parent 7d3fdec445
commit 25128d18c1
  1. 56
      test/cpp/microbenchmarks/bm_callback_unary_ping_pong.cc
  2. 9
      test/cpp/microbenchmarks/callback_test_service.cc
  3. 7
      test/cpp/microbenchmarks/callback_test_service.h
  4. 63
      test/cpp/microbenchmarks/callback_unary_ping_pong.h

@ -49,12 +49,6 @@ BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, MinInProcess, NoOpMutator,
NoOpMutator)
->Apply(SweepSizesArgs);
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
NoOpMutator)
->Apply(SweepSizesArgs);
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, MinInProcessCHTTP2, NoOpMutator,
NoOpMutator)
->Apply(SweepSizesArgs);
// Client context with different metadata
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
@ -86,35 +80,6 @@ BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2,
Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
->Args({0, 0});
// Server context with different metadata
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
@ -138,27 +103,6 @@ BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
->Args({0, 0});
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
->Args({0, 0});
} // namespace testing
} // namespace grpc

@ -49,6 +49,13 @@ int GetIntValueFromMetadata(
void CallbackStreamingTestService::Echo(
ServerContext* context, const EchoRequest* request, EchoResponse* response,
experimental::ServerCallbackRpcController* controller) {
int response_msgs_size = GetIntValueFromMetadata(kServerMessageSize,
context->client_metadata(), 0);
if (response_msgs_size > 0) {
response->set_message(std::string(response_msgs_size, 'a'));
} else {
response->set_message("");
}
controller->Finish(Status::OK);
}
@ -62,7 +69,7 @@ CallbackStreamingTestService::BidiStream() {
ctx_ = context;
server_write_last_ = GetIntValueFromMetadata(
kServerFinishAfterNReads, context->client_metadata(), 0);
message_size_ = GetIntValueFromMetadata(kServerResponseStreamsToSend,
message_size_ = GetIntValueFromMetadata(kServerMessageSize,
context->client_metadata(), 0);
StartRead(&request_);
on_started_done_ = true;

@ -30,7 +30,7 @@ namespace grpc {
namespace testing {
const char* const kServerFinishAfterNReads = "server_finish_after_n_reads";
const char* const kServerResponseStreamsToSend = "server_responses_to_send";
const char* const kServerMessageSize = "server_message_size";
class CallbackStreamingTestService
: public EchoTestService::ExperimentalCallbackService {
@ -61,7 +61,10 @@ class BidiClient
}
void OnReadDone(bool ok) override {
if (ok && reads_complete_ < msgs_to_send_) {
if (!ok) {
return;
}
if (reads_complete_ < msgs_to_send_) {
reads_complete_++;
StartRead(response_);
}

@ -36,6 +36,32 @@ namespace testing {
* BENCHMARKING KERNELS
*/
// Send next rpc when callback function is evoked.
void SendCallbackUnaryPingPong(benchmark::State& state, 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);
} else {
std::lock_guard<std::mutex> l(mu);
done = true;
cv.notify_one();
}
delete cli_ctx;
});
}
template <class Fixture, class ClientContextMutator, class ServerContextMutator>
static void BM_CallbackUnaryPingPong(benchmark::State& state) {
int request_msgs_size = state.range(0);
@ -47,40 +73,31 @@ static void BM_CallbackUnaryPingPong(benchmark::State& state) {
EchoRequest request;
EchoResponse response;
if (state.range(0) > 0) {
request.set_message(std::string(state.range(0), 'a'));
if (request_msgs_size > 0) {
request.set_message(std::string(request_msgs_size, 'a'));
} else {
request.set_message("");
}
if (state.range(1) > 0) {
response.set_message(std::string(state.range(1), 'a'));
} else {
response.set_message("");
}
while (state.KeepRunning()) {
std::mutex mu;
std::condition_variable cv;
bool done = false;
if (state.KeepRunning()) {
GPR_TIMER_SCOPE("BenchmarkCycle", 0);
ClientContext cli_ctx;
std::mutex mu;
std::condition_variable cv;
bool done = false;
stub_->experimental_async()->Echo(&cli_ctx, &request, &response,
[&done, &mu, &cv](Status s) {
GPR_ASSERT(s.ok());
std::lock_guard<std::mutex> l(mu);
done = true;
cv.notify_one();
});
std::unique_lock<std::mutex> l(mu);
while (!done) {
cv.wait(l);
}
SendCallbackUnaryPingPong(state, &request, &response, stub_.get(),
done, mu, cv);
}
std::unique_lock<std::mutex> l(mu);
while (!done) {
cv.wait(l);
}
fixture->Finish(state);
fixture.reset();
state.SetBytesProcessed(request_msgs_size * state.iterations() +
response_msgs_size * state.iterations());
}
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save