clang-format

pull/1948/head
Vijay Pai 10 years ago
parent c7de81e57e
commit cf3fb092cc
  1. 16
      include/grpc++/config.h
  2. 10
      include/grpc++/time.h
  3. 37
      test/cpp/qps/client.h
  4. 105
      test/cpp/qps/client_async.cc
  5. 16
      test/cpp/qps/interarrival.h
  6. 3
      test/cpp/qps/qpstest.proto

@ -99,23 +99,27 @@
::google::protobuf::io::ZeroCopyOutputStream
#define GRPC_CUSTOM_ZEROCOPYINPUTSTREAM \
::google::protobuf::io::ZeroCopyInputStream
#define GRPC_CUSTOM_CODEDINPUTSTREAM \
::google::protobuf::io::CodedInputStream
#define GRPC_CUSTOM_CODEDINPUTSTREAM ::google::protobuf::io::CodedInputStream
#endif
#ifdef GRPC_CXX0X_NO_NULLPTR
#include <memory>
const class {
public:
template <class T> operator T*() const {return static_cast<T *>(0);}
template <class T> operator std::unique_ptr<T>() const {
template <class T>
operator T *() const {
return static_cast<T *>(0);
}
template <class T>
operator std::unique_ptr<T>() const {
return std::unique_ptr<T>(static_cast<T *>(0));
}
template <class T> operator std::shared_ptr<T>() const {
template <class T>
operator std::shared_ptr<T>() const {
return std::shared_ptr<T>(static_cast<T *>(0));
}
operator bool() const { return false; }
private:
void operator&() const = delete;
} nullptr = {};

@ -52,13 +52,12 @@ namespace grpc {
template <typename T>
class TimePoint {
public:
TimePoint(const T& time) {
you_need_a_specialization_of_TimePoint();
}
TimePoint(const T& time) { you_need_a_specialization_of_TimePoint(); }
gpr_timespec raw_time() {
gpr_timespec t;
return t;
}
private:
void you_need_a_specialization_of_TimePoint();
};
@ -68,6 +67,7 @@ class TimePoint<gpr_timespec> {
public:
TimePoint(const gpr_timespec& time) : time_(time) {}
gpr_timespec raw_time() { return time_; }
private:
gpr_timespec time_;
};
@ -85,7 +85,8 @@ namespace grpc {
// from and to should be absolute time.
void Timepoint2Timespec(const std::chrono::system_clock::time_point& from,
gpr_timespec* to);
void TimepointHR2Timespec(const std::chrono::high_resolution_clock::time_point& from,
void TimepointHR2Timespec(
const std::chrono::high_resolution_clock::time_point& from,
gpr_timespec* to);
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t);
@ -97,6 +98,7 @@ class TimePoint<std::chrono::system_clock::time_point> {
Timepoint2Timespec(time, &time_);
}
gpr_timespec raw_time() const { return time_; }
private:
gpr_timespec time_;
};

@ -53,6 +53,7 @@ class TimePoint<std::chrono::high_resolution_clock::time_point> {
TimepointHR2Timespec(time, &time_);
}
gpr_timespec raw_time() const { return time_; }
private:
gpr_timespec time_;
};
@ -65,8 +66,8 @@ typedef std::chrono::time_point<grpc_time_source> grpc_time;
class Client {
public:
explicit Client(const ClientConfig& config) : timer_(new Timer),
interarrival_timer_() {
explicit Client(const ClientConfig& config)
: timer_(new Timer), interarrival_timer_() {
for (int i = 0; i < config.client_channels(); i++) {
channels_.push_back(ClientChannelInfo(
config.server_targets(i % config.server_targets_size()), config));
@ -131,29 +132,28 @@ class Client {
// Set up the load distribution based on the number of threads
if (config.load_type() == CLOSED_LOOP) {
closed_loop_ = true;
}
else {
} else {
closed_loop_ = false;
std::unique_ptr<RandomDist> random_dist;
auto& load = config.load_params();
switch (config.load_type()) {
case POISSON:
random_dist.reset
(new ExpDist(load.poisson().offered_load()/num_threads));
random_dist.reset(
new ExpDist(load.poisson().offered_load() / num_threads));
break;
case UNIFORM:
random_dist.reset
(new UniformDist(load.uniform().interarrival_lo()*num_threads,
random_dist.reset(
new UniformDist(load.uniform().interarrival_lo() * num_threads,
load.uniform().interarrival_hi() * num_threads));
break;
case DETERMINISTIC:
random_dist.reset
(new DetDist(num_threads/load.determ().offered_load()));
random_dist.reset(
new DetDist(num_threads / load.determ().offered_load()));
break;
case PARETO:
random_dist.reset
(new ParetoDist(load.pareto().interarrival_base()*num_threads,
random_dist.reset(
new ParetoDist(load.pareto().interarrival_base() * num_threads,
load.pareto().alpha()));
break;
default:
@ -163,18 +163,21 @@ class Client {
interarrival_timer_.init(*random_dist, num_threads);
for (size_t i = 0; i < num_threads; i++) {
next_time_.push_back(grpc_time_source::now() +
std::chrono::duration_cast<grpc_time_source::duration>(interarrival_timer_(i)));
next_time_.push_back(
grpc_time_source::now() +
std::chrono::duration_cast<grpc_time_source::duration>(
interarrival_timer_(i)));
}
}
}
bool NextIssueTime(int thread_idx, grpc_time* time_delay) {
if (closed_loop_) {
return false;
}
else {
} else {
*time_delay = next_time_[thread_idx];
next_time_[thread_idx] += std::chrono::duration_cast<grpc_time_source::duration>(interarrival_timer_(thread_idx));
next_time_[thread_idx] +=
std::chrono::duration_cast<grpc_time_source::duration>(
interarrival_timer_(thread_idx));
return true;
}
}

@ -73,11 +73,15 @@ class ClientRpcContext {
}
deadline_list::iterator deadline_posn() const { return deadline_posn_; }
void set_deadline_posn(const deadline_list::iterator& it) {deadline_posn_ = it;}
void set_deadline_posn(const deadline_list::iterator& it) {
deadline_posn_ = it;
}
virtual void Start(CompletionQueue* cq) = 0;
int channel_id() const { return channel_id_; }
protected:
int channel_id_;
private:
deadline_list::iterator deadline_posn_;
};
@ -85,22 +89,21 @@ class ClientRpcContext {
template <class RequestType, class ResponseType>
class ClientRpcContextUnaryImpl : public ClientRpcContext {
public:
ClientRpcContextUnaryImpl(int channel_id,
TestService::Stub* stub, const RequestType& req,
ClientRpcContextUnaryImpl(
int channel_id, TestService::Stub* stub, const RequestType& req,
std::function<
std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>(
TestService::Stub*, grpc::ClientContext*, const RequestType&,
CompletionQueue*)>
start_req,
CompletionQueue*)> start_req,
std::function<void(grpc::Status, ResponseType*)> on_done)
: ClientRpcContext(channel_id), context_(),
: ClientRpcContext(channel_id),
context_(),
stub_(stub),
req_(req),
response_(),
next_state_(&ClientRpcContextUnaryImpl::RespDone),
callback_(on_done),
start_req_(start_req) {
}
start_req_(start_req) {}
void Start(CompletionQueue* cq) GRPC_OVERRIDE {
start_ = Timer::Now();
response_reader_ = start_req_(stub_, &context_, req_, cq);
@ -116,8 +119,8 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
}
ClientRpcContext* StartNewClone() GRPC_OVERRIDE {
return new ClientRpcContextUnaryImpl(channel_id_,
stub_, req_, start_req_, callback_);
return new ClientRpcContextUnaryImpl(channel_id_, stub_, req_, start_req_,
callback_);
}
private:
@ -136,8 +139,8 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
bool (ClientRpcContextUnaryImpl::*next_state_)(bool);
std::function<void(grpc::Status, ResponseType*)> callback_;
std::function<std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>(
TestService::Stub*, grpc::ClientContext*,
const RequestType&, CompletionQueue *)> start_req_;
TestService::Stub*, grpc::ClientContext*, const RequestType&,
CompletionQueue*)> start_req_;
grpc::Status status_;
double start_;
std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>
@ -148,15 +151,16 @@ typedef std::forward_list<ClientRpcContext *> context_list;
class AsyncClient : public Client {
public:
explicit AsyncClient(const ClientConfig& config,
explicit AsyncClient(
const ClientConfig& config,
std::function<ClientRpcContext*(int, TestService::Stub*,
const SimpleRequest&)> setup_ctx) :
Client(config), channel_lock_(config.client_channels()),
const SimpleRequest&)> setup_ctx)
: Client(config),
channel_lock_(config.client_channels()),
contexts_(config.client_channels()),
max_outstanding_per_channel_(config.outstanding_rpcs_per_channel()),
channel_count_(config.client_channels()),
pref_channel_inc_(config.async_client_threads()) {
SetupLoadTest(config, config.async_client_threads());
for (int i = 0; i < config.async_client_threads(); i++) {
@ -181,8 +185,7 @@ class AsyncClient : public Client {
auto ctx = setup_ctx(ch, channel.get_stub(), request_);
if (closed_loop_) {
ctx->Start(cq);
}
else {
} else {
contexts_[ch].push_front(ctx);
}
}
@ -210,18 +213,18 @@ class AsyncClient : public Client {
} else {
if (rpc_deadlines_[thread_idx].empty()) {
deadline = grpc_time_source::now() + std::chrono::seconds(1);
}
else {
} else {
deadline = *(rpc_deadlines_[thread_idx].begin());
}
short_deadline = issue_allowed_[thread_idx] ?
next_issue_[thread_idx] : deadline;
short_deadline =
issue_allowed_[thread_idx] ? next_issue_[thread_idx] : deadline;
}
bool got_event;
switch (cli_cqs_[thread_idx]->AsyncNext(&got_tag, &ok, short_deadline)) {
case CompletionQueue::SHUTDOWN: return false;
case CompletionQueue::SHUTDOWN:
return false;
case CompletionQueue::TIMEOUT:
got_event = false;
break;
@ -246,8 +249,7 @@ class AsyncClient : public Client {
ClientRpcContext* clone_ctx = ctx->StartNewClone();
if (closed_loop_) {
clone_ctx->Start(cli_cqs_[thread_idx].get());
}
else {
} else {
// Remove the entry from the rpc deadlines list
rpc_deadlines_[thread_idx].erase(ctx->deadline_posn());
// Put the clone_ctx in the list of idle contexts for this channel
@ -260,7 +262,8 @@ class AsyncClient : public Client {
delete ctx;
}
if (!closed_loop_)
issue_allowed_[thread_idx] = true; // may be ok now even if it hadn't been
issue_allowed_[thread_idx] =
true; // may be ok now even if it hadn't been
}
if (!closed_loop_ && issue_allowed_[thread_idx] &&
grpc_time_source::now() >= next_issue_[thread_idx]) {
@ -271,8 +274,7 @@ class AsyncClient : public Client {
bool can_issue = false;
ClientRpcContext* ctx = nullptr;
{
std::lock_guard<std::mutex>
g(channel_lock_[channel_attempt]);
std::lock_guard<std::mutex> g(channel_lock_[channel_attempt]);
if (!contexts_[channel_attempt].empty()) {
// Get an idle context from the front of the list
ctx = *(contexts_[channel_attempt].begin());
@ -282,8 +284,8 @@ class AsyncClient : public Client {
}
if (can_issue) {
// do the work to issue
rpc_deadlines_[thread_idx].emplace_back(
grpc_time_source::now() + std::chrono::seconds(1));
rpc_deadlines_[thread_idx].emplace_back(grpc_time_source::now() +
std::chrono::seconds(1));
auto it = rpc_deadlines_[thread_idx].end();
--it;
ctx->set_deadline_posn(it);
@ -304,8 +306,7 @@ class AsyncClient : public Client {
grpc_time next_issue;
NextIssueTime(thread_idx, &next_issue);
next_issue_[thread_idx] = next_issue;
}
else {
} else {
issue_allowed_[thread_idx] = false;
}
}
@ -334,31 +335,28 @@ class AsyncUnaryClient GRPC_FINAL : public AsyncClient {
StartThreads(config.async_client_threads());
}
~AsyncUnaryClient() GRPC_OVERRIDE { EndThreads(); }
private:
static ClientRpcContext *SetupCtx(int channel_id,
TestService::Stub* stub,
static ClientRpcContext* SetupCtx(int channel_id, TestService::Stub* stub,
const SimpleRequest& req) {
auto check_done = [](grpc::Status s, SimpleResponse* response) {};
auto start_req = [](TestService::Stub* stub, grpc::ClientContext* ctx,
const SimpleRequest& request, CompletionQueue* cq) {
return stub->AsyncUnaryCall(ctx, request, cq);
};
return new ClientRpcContextUnaryImpl<SimpleRequest,
SimpleResponse>(channel_id, stub, req,
start_req, check_done);
return new ClientRpcContextUnaryImpl<SimpleRequest, SimpleResponse>(
channel_id, stub, req, start_req, check_done);
}
};
template <class RequestType, class ResponseType>
class ClientRpcContextStreamingImpl : public ClientRpcContext {
public:
ClientRpcContextStreamingImpl(int channel_id,
TestService::Stub* stub, const RequestType& req,
std::function<std::unique_ptr<
grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
TestService::Stub*, grpc::ClientContext*, CompletionQueue*,
void*)> start_req,
ClientRpcContextStreamingImpl(
int channel_id, TestService::Stub* stub, const RequestType& req,
std::function<std::unique_ptr<grpc::ClientAsyncReaderWriter<
RequestType, ResponseType>>(TestService::Stub*, grpc::ClientContext*,
CompletionQueue*, void*)> start_req,
std::function<void(grpc::Status, ResponseType*)> on_done)
: ClientRpcContext(channel_id),
context_(),
@ -374,12 +372,13 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
return (this->*next_state_)(ok, hist);
}
ClientRpcContext* StartNewClone() GRPC_OVERRIDE {
return new ClientRpcContextStreamingImpl(channel_id_,
stub_, req_, start_req_, callback_);
return new ClientRpcContextStreamingImpl(channel_id_, stub_, req_,
start_req_, callback_);
}
void Start(CompletionQueue* cq) GRPC_OVERRIDE {
stream_ = start_req_(stub_, &context_, cq, ClientRpcContext::tag(this));
}
private:
bool ReqSent(bool ok, Histogram*) { return StartWrite(ok); }
bool StartWrite(bool ok) {
@ -411,8 +410,8 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
std::function<void(grpc::Status, ResponseType*)> callback_;
std::function<
std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
TestService::Stub*, grpc::ClientContext*,
CompletionQueue *, void*)> start_req_;
TestService::Stub*, grpc::ClientContext*, CompletionQueue*, void*)>
start_req_;
grpc::Status status_;
double start_;
std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>
@ -430,9 +429,9 @@ class AsyncStreamingClient GRPC_FINAL : public AsyncClient {
}
~AsyncStreamingClient() GRPC_OVERRIDE { EndThreads(); }
private:
static ClientRpcContext *SetupCtx(int channel_id,
TestService::Stub* stub,
static ClientRpcContext* SetupCtx(int channel_id, TestService::Stub* stub,
const SimpleRequest& req) {
auto check_done = [](grpc::Status s, SimpleResponse* response) {};
auto start_req = [](TestService::Stub* stub, grpc::ClientContext* ctx,
@ -440,10 +439,8 @@ private:
auto stream = stub->AsyncStreamingCall(ctx, cq, tag);
return stream;
};
return new ClientRpcContextStreamingImpl<SimpleRequest,
SimpleResponse>(channel_id, stub,
req, start_req,
check_done);
return new ClientRpcContextStreamingImpl<SimpleRequest, SimpleResponse>(
channel_id, stub, req, start_req, check_done);
}
};

@ -64,7 +64,10 @@ class UniformDist GRPC_FINAL: public RandomDist {
public:
UniformDist(double lo, double hi) : lo_(lo), range_(hi - lo) {}
~UniformDist() GRPC_OVERRIDE {}
double operator() (double uni) const GRPC_OVERRIDE {return uni*range_+lo_;}
double operator()(double uni) const GRPC_OVERRIDE {
return uni * range_ + lo_;
}
private:
double lo_;
double range_;
@ -78,6 +81,7 @@ public:
// Note: Use 1.0-uni above to avoid NaN if uni is 0
return lambda_recip_ * (-log(1.0 - uni));
}
private:
double lambda_recip_;
};
@ -87,18 +91,21 @@ public:
explicit DetDist(double val) : val_(val) {}
~DetDist() GRPC_OVERRIDE {}
double operator()(double uni) const GRPC_OVERRIDE { return val_; }
private:
double val_;
};
class ParetoDist GRPC_FINAL : public RandomDist {
public:
ParetoDist(double base, double alpha): base_(base), alpha_recip_(1.0/alpha) {}
ParetoDist(double base, double alpha)
: base_(base), alpha_recip_(1.0 / alpha) {}
~ParetoDist() GRPC_OVERRIDE {}
double operator()(double uni) const GRPC_OVERRIDE {
// Note: Use 1.0-uni above to avoid div by zero if uni is 0
return base_ / pow(1.0 - uni, alpha_recip_);
}
private:
double base_;
double alpha_recip_;
@ -120,8 +127,7 @@ public:
qps_random_engine gen;
std::uniform_real_distribution<double> uniform(0.0, 1.0);
for (int i = 0; i < entries; i++) {
random_table_.push_back(
std::chrono::nanoseconds(
random_table_.push_back(std::chrono::nanoseconds(
static_cast<int64_t>(1e9 * r(uniform(gen)))));
}
// Now set up the thread positions
@ -137,12 +143,12 @@ public:
thread_posns_[thread_num] = random_table_.begin();
return ret;
}
private:
typedef std::vector<std::chrono::nanoseconds> time_table;
std::vector<time_table::const_iterator> thread_posns_;
time_table random_table_;
};
}
}

@ -143,7 +143,8 @@ message ClientConfig {
}
// Request current stats
message Mark {}
message Mark {
}
message ClientArgs {
oneof argtype {

Loading…
Cancel
Save