clang-format

pull/2771/head
Vijay Pai 9 years ago
parent 09d0b0cf47
commit ab1dba72dc
  1. 46
      test/cpp/qps/client.h
  2. 45
      test/cpp/qps/client_async.cc
  3. 4
      test/cpp/qps/interarrival.h

@ -71,7 +71,8 @@ class Client {
explicit Client(const ClientConfig& config)
: timer_(new Timer), interarrival_timer_() {
for (int i = 0; i < config.client_channels(); i++) {
channels_.emplace_back(config.server_targets(i % config.server_targets_size()), config);
channels_.emplace_back(
config.server_targets(i % config.server_targets_size()), config);
}
request_.set_response_type(grpc::testing::PayloadType::COMPRESSABLE);
request_.set_response_size(config.payload_size());
@ -188,8 +189,11 @@ class Client {
class Thread {
public:
Thread(Client* client, size_t idx)
: done_(false), new_(nullptr), client_(client), idx_(idx),
impl_(&Thread::ThreadFunc, this) {}
: done_(false),
new_(nullptr),
client_(client),
idx_(idx),
impl_(&Thread::ThreadFunc, this) {}
~Thread() {
{
@ -215,23 +219,23 @@ class Client {
void ThreadFunc() {
for (;;) {
// run the loop body
bool thread_still_ok = client_->ThreadFunc(&histogram_, idx_);
// lock, see if we're done
std::lock_guard<std::mutex> g(mu_);
if (!thread_still_ok) {
gpr_log(GPR_ERROR, "Finishing client thread due to RPC error");
done_ = true;
}
if (done_) {
return;
}
// check if we're marking, swap out the histogram if so
if (new_) {
new_->Swap(&histogram_);
new_ = nullptr;
cv_.notify_one();
}
// run the loop body
bool thread_still_ok = client_->ThreadFunc(&histogram_, idx_);
// lock, see if we're done
std::lock_guard<std::mutex> g(mu_);
if (!thread_still_ok) {
gpr_log(GPR_ERROR, "Finishing client thread due to RPC error");
done_ = true;
}
if (done_) {
return;
}
// check if we're marking, swap out the histogram if so
if (new_) {
new_->Swap(&histogram_);
new_ = nullptr;
cv_.notify_one();
}
}
}
@ -242,7 +246,7 @@ class Client {
bool done_;
Histogram* new_;
Histogram histogram_;
Client *client_;
Client* client_;
size_t idx_;
std::thread impl_;
};

@ -316,21 +316,25 @@ class AsyncClient : public Client {
}
private:
class boolean { // exists only to avoid data-race on vector<bool>
class boolean { // exists only to avoid data-race on vector<bool>
public:
boolean(): val_(false) {}
boolean(bool b): val_(b) {}
operator bool() const {return val_;}
boolean& operator=(bool b) {val_=b; return *this;}
boolean() : val_(false) {}
boolean(bool b) : val_(b) {}
operator bool() const { return val_; }
boolean& operator=(bool b) {
val_ = b;
return *this;
}
private:
bool val_;
};
std::vector<std::unique_ptr<CompletionQueue>> cli_cqs_;
std::vector<deadline_list> rpc_deadlines_; // per thread deadlines
std::vector<int> next_channel_; // per thread round-robin channel ctr
std::vector<boolean> issue_allowed_; // may this thread attempt to issue
std::vector<grpc_time> next_issue_; // when should it issue?
std::vector<int> next_channel_; // per thread round-robin channel ctr
std::vector<boolean> issue_allowed_; // may this thread attempt to issue
std::vector<grpc_time> next_issue_; // when should it issue?
std::vector<std::mutex> channel_lock_;
std::vector<context_list> contexts_; // per-channel list of idle contexts
@ -350,17 +354,15 @@ class AsyncUnaryClient GRPC_FINAL : public AsyncClient {
private:
static void CheckDone(grpc::Status s, SimpleResponse* response) {}
static std::unique_ptr<grpc::ClientAsyncResponseReader<SimpleResponse>>
StartReq(TestService::Stub* stub, grpc::ClientContext* ctx,
const SimpleRequest& request, CompletionQueue* cq) {
StartReq(TestService::Stub* stub, grpc::ClientContext* ctx,
const SimpleRequest& request, CompletionQueue* cq) {
return stub->AsyncUnaryCall(ctx, request, cq);
};
static ClientRpcContext* SetupCtx(int channel_id, TestService::Stub* stub,
const SimpleRequest& req) {
return new
ClientRpcContextUnaryImpl<SimpleRequest,
SimpleResponse>(channel_id, stub, req,
AsyncUnaryClient::StartReq,
AsyncUnaryClient::CheckDone);
return new ClientRpcContextUnaryImpl<SimpleRequest, SimpleResponse>(
channel_id, stub, req, AsyncUnaryClient::StartReq,
AsyncUnaryClient::CheckDone);
}
};
@ -447,19 +449,18 @@ class AsyncStreamingClient GRPC_FINAL : public AsyncClient {
private:
static void CheckDone(grpc::Status s, SimpleResponse* response) {}
static std::unique_ptr<grpc::ClientAsyncReaderWriter<
SimpleRequest,SimpleResponse>>
StartReq(TestService::Stub* stub, grpc::ClientContext* ctx,
CompletionQueue* cq, void* tag) {
static std::unique_ptr<
grpc::ClientAsyncReaderWriter<SimpleRequest, SimpleResponse>>
StartReq(TestService::Stub* stub, grpc::ClientContext* ctx,
CompletionQueue* cq, void* tag) {
auto stream = stub->AsyncStreamingCall(ctx, cq, tag);
return stream;
};
static ClientRpcContext* SetupCtx(int channel_id, TestService::Stub* stub,
const SimpleRequest& req) {
return new ClientRpcContextStreamingImpl<SimpleRequest, SimpleResponse>(
channel_id, stub, req,
AsyncStreamingClient::StartReq,
AsyncStreamingClient::CheckDone);
channel_id, stub, req, AsyncStreamingClient::StartReq,
AsyncStreamingClient::CheckDone);
}
};

@ -150,8 +150,8 @@ class InterarrivalTimer {
// rand is the only choice that is portable across POSIX and Windows
// and that supports new and old compilers
double uniform_0_1 = rand() / RAND_MAX;
random_table_.push_back(std::chrono::nanoseconds(
static_cast<int64_t>(1e9 * r(uniform_0_1))));
random_table_.push_back(
std::chrono::nanoseconds(static_cast<int64_t>(1e9 * r(uniform_0_1))));
}
// Now set up the thread positions
for (int i = 0; i < threads; i++) {

Loading…
Cancel
Save