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

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

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

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

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

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

Loading…
Cancel
Save