Dont start requests until all clients have gotten connected

pull/8094/head
Craig Tiller 9 years ago
parent 531976a6d4
commit 9e1c2d2358
  1. 28
      test/cpp/qps/client.h

@ -129,13 +129,17 @@ class HistogramEntry GRPC_FINAL {
class Client {
public:
Client() : timer_(new UsageTimer), interarrival_timer_() {}
Client() : timer_(new UsageTimer), interarrival_timer_() {
gpr_event_init(&start_requests_);
}
virtual ~Client() {}
ClientStats Mark(bool reset) {
Histogram latencies;
UsageTimer::Result timer_result;
MaybeStartRequests();
// avoid std::vector for old compilers that expect a copy constructor
if (reset) {
Histogram* to_merge = new Histogram[threads_.size()];
@ -189,7 +193,10 @@ class Client {
}
}
void EndThreads() { threads_.clear(); }
void EndThreads() {
MaybeStartRequests();
threads_.clear();
}
virtual void DestroyMultithreading() = 0;
virtual bool ThreadFunc(HistogramEntry* histogram, size_t thread_idx) = 0;
@ -265,6 +272,13 @@ class Client {
Thread& operator=(const Thread&);
void ThreadFunc() {
while (!gpr_event_wait(
&client_->start_requests_,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(1, GPR_TIMESPAN)))) {
gpr_log(GPR_INFO, "Waiting for benchmark to start");
}
for (;;) {
// run the loop body
HistogramEntry entry;
@ -302,6 +316,16 @@ class Client {
size_t threads_remaining_;
std::condition_variable threads_complete_;
gpr_event start_requests_;
bool started_requests_;
void MaybeStartRequests() {
if (!started_requests_) {
started_requests_ = true;
gpr_event_set(&start_requests_, (void*)1);
}
}
void CompleteThread() {
std::lock_guard<std::mutex> g(thread_completion_mu_);
threads_remaining_--;

Loading…
Cancel
Save