Change format

pull/18881/head
Na-Na Pang 6 years ago
parent 5748665bc5
commit 927c2f2c61
  1. 26
      test/cpp/microbenchmarks/bm_callback_cq.cc
  2. 9
      test/cpp/microbenchmarks/callback_streaming_ping_pong.h
  3. 4
      test/cpp/microbenchmarks/callback_test_service.cc
  4. 39
      test/cpp/microbenchmarks/callback_unary_ping_pong.h

@ -27,10 +27,10 @@
#include "test/cpp/microbenchmarks/helpers.h"
#include "test/cpp/util/test_config.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/surface/completion_queue.h"
namespace grpc {
namespace testing {
@ -43,8 +43,7 @@ class TagCallback : public grpc_experimental_completion_queue_functor {
functor_run = &TagCallback::Run;
}
~TagCallback() {}
static void Run(grpc_experimental_completion_queue_functor* cb,
int ok) {
static void Run(grpc_experimental_completion_queue_functor* cb, int ok) {
GPR_ASSERT(static_cast<bool>(ok));
auto* callback = static_cast<TagCallback*>(cb);
*callback->counter_ += callback->tag_;
@ -104,15 +103,14 @@ static void BM_Callback_CQ_Default_Polling(benchmark::State& state) {
grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
tags[i] =
static_cast<void*>(grpc_core::New<TagCallback>(&counter, i));
tags[i] = static_cast<void*>(grpc_core::New<TagCallback>(&counter, i));
sumtags += i;
}
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]));
grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE,
do_nothing_end_completion, nullptr, &completions[i]);
grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion,
nullptr, &completions[i]);
}
shutdown_and_destroy(cc);
@ -149,15 +147,14 @@ static void BM_Callback_CQ_Non_Listening(benchmark::State& state) {
grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
tags[i] =
static_cast<void*>(grpc_core::New<TagCallback>(&counter, i));
tags[i] = static_cast<void*>(grpc_core::New<TagCallback>(&counter, i));
sumtags += i;
}
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]));
grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE,
do_nothing_end_completion, nullptr, &completions[i]);
grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion,
nullptr, &completions[i]);
}
shutdown_and_destroy(cc);
@ -194,15 +191,14 @@ static void BM_Callback_CQ_Non_Polling(benchmark::State& state) {
grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
tags[i] =
static_cast<void*>(grpc_core::New<TagCallback>(&counter, i));
tags[i] = static_cast<void*>(grpc_core::New<TagCallback>(&counter, i));
sumtags += i;
}
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
GPR_ASSERT(grpc_cq_begin_op(cc, tags[i]));
grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE,
do_nothing_end_completion, nullptr, &completions[i]);
grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion,
nullptr, &completions[i]);
}
shutdown_and_destroy(cc);

@ -53,16 +53,15 @@ static void BM_CallbackBidiStreaming(benchmark::State& state) {
GPR_TIMER_SCOPE("BenchmarkCycle", 0);
ClientContext cli_ctx;
cli_ctx.AddMetadata(kServerFinishAfterNReads,
grpc::to_string(max_ping_pongs));
cli_ctx.AddMetadata(kServerMessageSize,
grpc::to_string(message_size));
grpc::to_string(max_ping_pongs));
cli_ctx.AddMetadata(kServerMessageSize, grpc::to_string(message_size));
BidiClient test{stub_.get(), &request, &response, &cli_ctx, max_ping_pongs};
test.Await();
}
fixture->Finish(state);
fixture.reset();
state.SetBytesProcessed(2 * message_size * max_ping_pongs
* state.iterations());
state.SetBytesProcessed(2 * message_size * max_ping_pongs *
state.iterations());
}
} // namespace testing

@ -49,8 +49,8 @@ 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);
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 {

@ -39,27 +39,25 @@ namespace testing {
// 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) {
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));
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;
});
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>
@ -84,8 +82,8 @@ 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, mu, cv);
SendCallbackUnaryPingPong(state, &request, &response, stub_.get(), done, mu,
cv);
}
std::unique_lock<std::mutex> l(mu);
while (!done) {
@ -97,7 +95,6 @@ static void BM_CallbackUnaryPingPong(benchmark::State& state) {
response_msgs_size * state.iterations());
}
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save