clang-format qps code - it was getting out of hand

pull/1703/head
Craig Tiller 10 years ago
parent 76e0fb1dc0
commit 5c8737d171
  1. 11
      test/cpp/qps/client.h
  2. 47
      test/cpp/qps/client_async.cc
  3. 8
      test/cpp/qps/client_sync.cc
  4. 3
      test/cpp/qps/driver.cc
  5. 4
      test/cpp/qps/qps_driver.cc
  6. 20
      test/cpp/qps/qps_worker.cc
  7. 12
      test/cpp/qps/report.cc
  8. 34
      test/cpp/qps/server_async.cc
  9. 6
      test/cpp/qps/server_sync.cc

@ -122,7 +122,9 @@ class Client {
gpr_log(GPR_ERROR, "Finishing client thread due to RPC error"); gpr_log(GPR_ERROR, "Finishing client thread due to RPC error");
done_ = true; done_ = true;
} }
if (done_) {return;} if (done_) {
return;
}
// check if we're marking, swap out the histogram if so // check if we're marking, swap out the histogram if so
if (new_) { if (new_) {
new_->Swap(&histogram_); new_->Swap(&histogram_);
@ -168,10 +170,9 @@ class Client {
std::unique_ptr<Timer> timer_; std::unique_ptr<Timer> timer_;
}; };
std::unique_ptr<Client> std::unique_ptr<Client> CreateSynchronousUnaryClient(const ClientConfig& args);
CreateSynchronousUnaryClient(const ClientConfig& args); std::unique_ptr<Client> CreateSynchronousStreamingClient(
std::unique_ptr<Client> const ClientConfig& args);
CreateSynchronousStreamingClient(const ClientConfig& args);
std::unique_ptr<Client> CreateAsyncUnaryClient(const ClientConfig& args); std::unique_ptr<Client> CreateAsyncUnaryClient(const ClientConfig& args);
std::unique_ptr<Client> CreateAsyncStreamingClient(const ClientConfig& args); std::unique_ptr<Client> CreateAsyncStreamingClient(const ClientConfig& args);

@ -129,8 +129,8 @@ class AsyncClient : public Client {
public: public:
explicit AsyncClient(const ClientConfig& config, explicit AsyncClient(const ClientConfig& config,
std::function<void(CompletionQueue*, TestService::Stub*, std::function<void(CompletionQueue*, TestService::Stub*,
const SimpleRequest&)> setup_ctx) : const SimpleRequest&)> setup_ctx)
Client(config) { : Client(config) {
for (int i = 0; i < config.async_client_threads(); i++) { for (int i = 0; i < config.async_client_threads(); i++) {
cli_cqs_.emplace_back(new CompletionQueue); cli_cqs_.emplace_back(new CompletionQueue);
} }
@ -155,16 +155,19 @@ class AsyncClient : public Client {
} }
} }
bool ThreadFunc(Histogram* histogram, size_t thread_idx) bool ThreadFunc(Histogram* histogram,
GRPC_OVERRIDE GRPC_FINAL { size_t thread_idx) GRPC_OVERRIDE GRPC_FINAL {
void* got_tag; void* got_tag;
bool ok; bool ok;
switch (cli_cqs_[thread_idx]->AsyncNext(&got_tag, &ok, switch (cli_cqs_[thread_idx]->AsyncNext(
std::chrono::system_clock::now() + &got_tag, &ok,
std::chrono::seconds(1))) { std::chrono::system_clock::now() + std::chrono::seconds(1))) {
case CompletionQueue::SHUTDOWN: return false; case CompletionQueue::SHUTDOWN:
case CompletionQueue::TIMEOUT: return true; return false;
case CompletionQueue::GOT_EVENT: break; case CompletionQueue::TIMEOUT:
return true;
case CompletionQueue::GOT_EVENT:
break;
} }
ClientRpcContext* ctx = ClientRpcContext::detag(got_tag); ClientRpcContext* ctx = ClientRpcContext::detag(got_tag);
@ -177,17 +180,19 @@ class AsyncClient : public Client {
return true; return true;
} }
private: private:
std::vector<std::unique_ptr<CompletionQueue>> cli_cqs_; std::vector<std::unique_ptr<CompletionQueue>> cli_cqs_;
}; };
class AsyncUnaryClient GRPC_FINAL : public AsyncClient { class AsyncUnaryClient GRPC_FINAL : public AsyncClient {
public: public:
explicit AsyncUnaryClient(const ClientConfig& config) : explicit AsyncUnaryClient(const ClientConfig& config)
AsyncClient(config, SetupCtx) { : AsyncClient(config, SetupCtx) {
StartThreads(config.async_client_threads()); StartThreads(config.async_client_threads());
} }
~AsyncUnaryClient() GRPC_OVERRIDE { EndThreads(); } ~AsyncUnaryClient() GRPC_OVERRIDE { EndThreads(); }
private: private:
static void SetupCtx(CompletionQueue* cq, TestService::Stub* stub, static void SetupCtx(CompletionQueue* cq, TestService::Stub* stub,
const SimpleRequest& req) { const SimpleRequest& req) {
@ -206,9 +211,8 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
public: public:
ClientRpcContextStreamingImpl( ClientRpcContextStreamingImpl(
TestService::Stub* stub, const RequestType& req, TestService::Stub* stub, const RequestType& req,
std::function< std::function<std::unique_ptr<
std::unique_ptr<grpc::ClientAsyncReaderWriter< grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
RequestType,ResponseType>>(
TestService::Stub*, grpc::ClientContext*, void*)> start_req, TestService::Stub*, grpc::ClientContext*, void*)> start_req,
std::function<void(grpc::Status, ResponseType*)> on_done) std::function<void(grpc::Status, ResponseType*)> on_done)
: context_(), : context_(),
@ -229,9 +233,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
} }
private: private:
bool ReqSent(bool ok, Histogram *) { bool ReqSent(bool ok, Histogram*) { return StartWrite(ok); }
return StartWrite(ok);
}
bool StartWrite(bool ok) { bool StartWrite(bool ok) {
if (!ok) { if (!ok) {
return (false); return (false);
@ -259,8 +261,8 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
ResponseType response_; ResponseType response_;
bool (ClientRpcContextStreamingImpl::*next_state_)(bool, Histogram*); bool (ClientRpcContextStreamingImpl::*next_state_)(bool, Histogram*);
std::function<void(grpc::Status, ResponseType*)> callback_; std::function<void(grpc::Status, ResponseType*)> callback_;
std::function<std::unique_ptr<grpc::ClientAsyncReaderWriter< std::function<
RequestType,ResponseType>>( std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
TestService::Stub*, grpc::ClientContext*, void*)> start_req_; TestService::Stub*, grpc::ClientContext*, void*)> start_req_;
grpc::Status status_; grpc::Status status_;
double start_; double start_;
@ -270,12 +272,13 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
class AsyncStreamingClient GRPC_FINAL : public AsyncClient { class AsyncStreamingClient GRPC_FINAL : public AsyncClient {
public: public:
explicit AsyncStreamingClient(const ClientConfig &config) : explicit AsyncStreamingClient(const ClientConfig& config)
AsyncClient(config, SetupCtx) { : AsyncClient(config, SetupCtx) {
StartThreads(config.async_client_threads()); StartThreads(config.async_client_threads());
} }
~AsyncStreamingClient() GRPC_OVERRIDE { EndThreads(); } ~AsyncStreamingClient() GRPC_OVERRIDE { EndThreads(); }
private: private:
static void SetupCtx(CompletionQueue* cq, TestService::Stub* stub, static void SetupCtx(CompletionQueue* cq, TestService::Stub* stub,
const SimpleRequest& req) { const SimpleRequest& req) {

@ -99,7 +99,9 @@ class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient {
class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient { class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
public: public:
SynchronousStreamingClient(const ClientConfig& config) SynchronousStreamingClient(const ClientConfig& config)
: SynchronousClient(config), context_(num_threads_), stream_(num_threads_) { : SynchronousClient(config),
context_(num_threads_),
stream_(num_threads_) {
for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) { for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) {
auto* stub = channels_[thread_idx % channels_.size()].get_stub(); auto* stub = channels_[thread_idx % channels_.size()].get_stub();
stream_[thread_idx] = stub->StreamingCall(&context_[thread_idx]); stream_[thread_idx] = stub->StreamingCall(&context_[thread_idx]);
@ -128,8 +130,8 @@ class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
private: private:
std::vector<grpc::ClientContext> context_; std::vector<grpc::ClientContext> context_;
std::vector<std::unique_ptr<grpc::ClientReaderWriter< std::vector<std::unique_ptr<
SimpleRequest, SimpleResponse>>> stream_; grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>> stream_;
}; };
std::unique_ptr<Client> CreateSynchronousUnaryClient( std::unique_ptr<Client> CreateSynchronousUnaryClient(

@ -211,7 +211,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Wait some time // Wait some time
gpr_log(GPR_INFO, "Running"); gpr_log(GPR_INFO, "Running");
gpr_sleep_until(gpr_time_add(start, gpr_time_from_seconds(benchmark_seconds))); gpr_sleep_until(
gpr_time_add(start, gpr_time_from_seconds(benchmark_seconds)));
// Finish a run // Finish a run
std::unique_ptr<ScenarioResult> result(new ScenarioResult); std::unique_ptr<ScenarioResult> result(new ScenarioResult);

@ -100,8 +100,8 @@ int main(int argc, char** argv) {
// client will deadlock on a timer. // client will deadlock on a timer.
GPR_ASSERT(!(server_type == grpc::testing::SYNCHRONOUS_SERVER && GPR_ASSERT(!(server_type == grpc::testing::SYNCHRONOUS_SERVER &&
rpc_type == grpc::testing::STREAMING && rpc_type == grpc::testing::STREAMING &&
FLAGS_server_threads < FLAGS_client_channels * FLAGS_server_threads <
FLAGS_outstanding_rpcs_per_channel)); FLAGS_client_channels * FLAGS_outstanding_rpcs_per_channel));
const auto result = RunScenario( const auto result = RunScenario(
client_config, FLAGS_num_clients, server_config, FLAGS_num_servers, client_config, FLAGS_num_clients, server_config, FLAGS_num_servers,

@ -64,17 +64,19 @@ namespace testing {
std::unique_ptr<Client> CreateClient(const ClientConfig& config) { std::unique_ptr<Client> CreateClient(const ClientConfig& config) {
switch (config.client_type()) { switch (config.client_type()) {
case ClientType::SYNCHRONOUS_CLIENT: case ClientType::SYNCHRONOUS_CLIENT:
return (config.rpc_type() == RpcType::UNARY) ? return (config.rpc_type() == RpcType::UNARY)
CreateSynchronousUnaryClient(config) : ? CreateSynchronousUnaryClient(config)
CreateSynchronousStreamingClient(config); : CreateSynchronousStreamingClient(config);
case ClientType::ASYNC_CLIENT: case ClientType::ASYNC_CLIENT:
return (config.rpc_type() == RpcType::UNARY) ? return (config.rpc_type() == RpcType::UNARY)
CreateAsyncUnaryClient(config) : CreateAsyncStreamingClient(config); ? CreateAsyncUnaryClient(config)
: CreateAsyncStreamingClient(config);
} }
abort(); abort();
} }
std::unique_ptr<Server> CreateServer(const ServerConfig& config, int server_port) { std::unique_ptr<Server> CreateServer(const ServerConfig& config,
int server_port) {
switch (config.server_type()) { switch (config.server_type()) {
case ServerType::SYNCHRONOUS_SERVER: case ServerType::SYNCHRONOUS_SERVER:
return CreateSynchronousServer(config, server_port); return CreateSynchronousServer(config, server_port);
@ -86,7 +88,8 @@ std::unique_ptr<Server> CreateServer(const ServerConfig& config, int server_port
class WorkerImpl GRPC_FINAL : public Worker::Service { class WorkerImpl GRPC_FINAL : public Worker::Service {
public: public:
explicit WorkerImpl(int server_port) : server_port_(server_port), acquired_(false) {} explicit WorkerImpl(int server_port)
: server_port_(server_port), acquired_(false) {}
Status RunTest(ServerContext* ctx, Status RunTest(ServerContext* ctx,
ServerReaderWriter<ClientStatus, ClientArgs>* stream) ServerReaderWriter<ClientStatus, ClientArgs>* stream)
@ -226,8 +229,7 @@ QpsWorker::QpsWorker(int driver_port, int server_port) {
server_ = std::move(builder.BuildAndStart()); server_ = std::move(builder.BuildAndStart());
} }
QpsWorker::~QpsWorker() { QpsWorker::~QpsWorker() {}
}
} // namespace testing } // namespace testing
} // namespace grpc } // namespace grpc

@ -48,18 +48,20 @@ void ReportQPS(const ScenarioResult& result) {
} }
// QPS: XXX (YYY/server core) // QPS: XXX (YYY/server core)
void ReportQPSPerCore(const ScenarioResult& result, const ServerConfig& server_config) { void ReportQPSPerCore(const ScenarioResult& result,
auto qps = const ServerConfig& server_config) {
result.latencies.Count() / auto qps = result.latencies.Count() /
average(result.client_resources, average(result.client_resources,
[](ResourceUsage u) { return u.wall_time; }); [](ResourceUsage u) { return u.wall_time; });
gpr_log(GPR_INFO, "QPS: %.1f (%.1f/server core)", qps, qps/server_config.threads()); gpr_log(GPR_INFO, "QPS: %.1f (%.1f/server core)", qps,
qps / server_config.threads());
} }
// Latency (50/90/95/99/99.9%-ile): AA/BB/CC/DD/EE us // Latency (50/90/95/99/99.9%-ile): AA/BB/CC/DD/EE us
void ReportLatency(const ScenarioResult& result) { void ReportLatency(const ScenarioResult& result) {
gpr_log(GPR_INFO, "Latencies (50/90/95/99/99.9%%-ile): %.1f/%.1f/%.1f/%.1f/%.1f us", gpr_log(GPR_INFO,
"Latencies (50/90/95/99/99.9%%-ile): %.1f/%.1f/%.1f/%.1f/%.1f us",
result.latencies.Percentile(50) / 1000, result.latencies.Percentile(50) / 1000,
result.latencies.Percentile(90) / 1000, result.latencies.Percentile(90) / 1000,
result.latencies.Percentile(95) / 1000, result.latencies.Percentile(95) / 1000,

@ -159,7 +159,9 @@ class AsyncQpsServerTest : public Server {
AsyncQpsServerTest::tag(this)); AsyncQpsServerTest::tag(this));
} }
~ServerRpcContextUnaryImpl() GRPC_OVERRIDE {} ~ServerRpcContextUnaryImpl() GRPC_OVERRIDE {}
bool RunNextState(bool ok) GRPC_OVERRIDE {return (this->*next_state_)(ok);} bool RunNextState(bool ok) GRPC_OVERRIDE {
return (this->*next_state_)(ok);
}
void Reset() GRPC_OVERRIDE { void Reset() GRPC_OVERRIDE {
srv_ctx_ = ServerContext(); srv_ctx_ = ServerContext();
req_ = RequestType(); req_ = RequestType();
@ -204,9 +206,9 @@ class AsyncQpsServerTest : public Server {
class ServerRpcContextStreamingImpl GRPC_FINAL : public ServerRpcContext { class ServerRpcContextStreamingImpl GRPC_FINAL : public ServerRpcContext {
public: public:
ServerRpcContextStreamingImpl( ServerRpcContextStreamingImpl(
std::function<void(ServerContext *, std::function<void(ServerContext *, grpc::ServerAsyncReaderWriter<
grpc::ServerAsyncReaderWriter<ResponseType, ResponseType, RequestType> *,
RequestType> *, void *)> request_method, void *)> request_method,
std::function<grpc::Status(const RequestType *, ResponseType *)> std::function<grpc::Status(const RequestType *, ResponseType *)>
invoke_method) invoke_method)
: next_state_(&ServerRpcContextStreamingImpl::request_done), : next_state_(&ServerRpcContextStreamingImpl::request_done),
@ -215,14 +217,15 @@ class AsyncQpsServerTest : public Server {
stream_(&srv_ctx_) { stream_(&srv_ctx_) {
request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this)); request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this));
} }
~ServerRpcContextStreamingImpl() GRPC_OVERRIDE { ~ServerRpcContextStreamingImpl() GRPC_OVERRIDE {}
bool RunNextState(bool ok) GRPC_OVERRIDE {
return (this->*next_state_)(ok);
} }
bool RunNextState(bool ok) GRPC_OVERRIDE {return (this->*next_state_)(ok);}
void Reset() GRPC_OVERRIDE { void Reset() GRPC_OVERRIDE {
srv_ctx_ = ServerContext(); srv_ctx_ = ServerContext();
req_ = RequestType(); req_ = RequestType();
stream_ = grpc::ServerAsyncReaderWriter<ResponseType, stream_ =
RequestType>(&srv_ctx_); grpc::ServerAsyncReaderWriter<ResponseType, RequestType>(&srv_ctx_);
// Then request the method // Then request the method
next_state_ = &ServerRpcContextStreamingImpl::request_done; next_state_ = &ServerRpcContextStreamingImpl::request_done;
@ -260,8 +263,7 @@ class AsyncQpsServerTest : public Server {
if (ok) { if (ok) {
stream_.Read(&req_, AsyncQpsServerTest::tag(this)); stream_.Read(&req_, AsyncQpsServerTest::tag(this));
next_state_ = &ServerRpcContextStreamingImpl::read_done; next_state_ = &ServerRpcContextStreamingImpl::read_done;
} } else {
else {
stream_.Finish(Status::OK, AsyncQpsServerTest::tag(this)); stream_.Finish(Status::OK, AsyncQpsServerTest::tag(this));
next_state_ = &ServerRpcContextStreamingImpl::finish_done; next_state_ = &ServerRpcContextStreamingImpl::finish_done;
} }
@ -272,9 +274,10 @@ class AsyncQpsServerTest : public Server {
ServerContext srv_ctx_; ServerContext srv_ctx_;
RequestType req_; RequestType req_;
bool (ServerRpcContextStreamingImpl::*next_state_)(bool); bool (ServerRpcContextStreamingImpl::*next_state_)(bool);
std::function<void(ServerContext *, std::function<void(
grpc::ServerAsyncReaderWriter<ResponseType, ServerContext *,
RequestType> *, void *)> request_method_; grpc::ServerAsyncReaderWriter<ResponseType, RequestType> *, void *)>
request_method_;
std::function<grpc::Status(const RequestType *, ResponseType *)> std::function<grpc::Status(const RequestType *, ResponseType *)>
invoke_method_; invoke_method_;
grpc::ServerAsyncReaderWriter<ResponseType, RequestType> stream_; grpc::ServerAsyncReaderWriter<ResponseType, RequestType> stream_;
@ -297,8 +300,9 @@ class AsyncQpsServerTest : public Server {
std::function<void(ServerContext *, SimpleRequest *, std::function<void(ServerContext *, SimpleRequest *,
grpc::ServerAsyncResponseWriter<SimpleResponse> *, void *)> grpc::ServerAsyncResponseWriter<SimpleResponse> *, void *)>
request_unary_; request_unary_;
std::function<void(ServerContext*, grpc::ServerAsyncReaderWriter< std::function<void(
SimpleResponse,SimpleRequest>*, void*)> ServerContext *,
grpc::ServerAsyncReaderWriter<SimpleResponse, SimpleRequest> *, void *)>
request_streaming_; request_streaming_;
std::forward_list<ServerRpcContext *> contexts_; std::forward_list<ServerRpcContext *> contexts_;

@ -70,9 +70,9 @@ class TestServiceImpl GRPC_FINAL : public TestService::Service {
} }
return Status::OK; return Status::OK;
} }
Status StreamingCall(ServerContext *context, Status StreamingCall(
ServerReaderWriter<SimpleResponse, SimpleRequest>* ServerContext* context,
stream) GRPC_OVERRIDE { ServerReaderWriter<SimpleResponse, SimpleRequest>* stream) GRPC_OVERRIDE {
SimpleRequest request; SimpleRequest request;
while (stream->Read(&request)) { while (stream->Read(&request)) {
SimpleResponse response; SimpleResponse response;

Loading…
Cancel
Save