|
|
@ -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) { |
|
|
|