From 773ecd62ddeea4c483d3d248fa30a978d2520ee8 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Fri, 5 Aug 2016 09:26:56 -0700 Subject: [PATCH] Dramatically reduce time required to complete sync test when running with lots of threads (by parallelizing shutdown of course) --- test/cpp/qps/client.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 4045e13460f..8a750196b26 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -169,6 +169,7 @@ class Client { // Must call AwaitThreadsCompletion before destructor to avoid a race // between destructor and invocation of virtual ThreadFunc void AwaitThreadsCompletion() { + gpr_atm_rel_store(&thread_pool_done_, static_cast(1)); DestroyMultithreading(); std::unique_lock g(thread_completion_mu_); while (threads_remaining_ != 0) { @@ -180,6 +181,7 @@ class Client { bool closed_loop_; void StartThreads(size_t num_threads) { + gpr_atm_rel_store(&thread_pool_done_, static_cast(0)); threads_remaining_ = num_threads; for (size_t i = 0; i < num_threads; i++) { threads_.emplace_back(new Thread(this, i)); @@ -241,16 +243,11 @@ class Client { class Thread { public: Thread(Client* client, size_t idx) - : done_(false), - client_(client), + : client_(client), idx_(idx), impl_(&Thread::ThreadFunc, this) {} ~Thread() { - { - std::lock_guard g(mu_); - done_ = true; - } impl_.join(); } @@ -280,11 +277,14 @@ class Client { if (entry.used()) { histogram_.Add(entry.value()); } + bool done = false; if (!thread_still_ok) { gpr_log(GPR_ERROR, "Finishing client thread due to RPC error"); - done_ = true; + done = true; } - if (done_) { + done = done || (gpr_atm_acq_load(&client_->thread_pool_done_) != + static_cast(0)); + if (done) { client_->CompleteThread(); return; } @@ -292,7 +292,6 @@ class Client { } std::mutex mu_; - bool done_; Histogram histogram_; Client* client_; const size_t idx_; @@ -305,6 +304,7 @@ class Client { InterarrivalTimer interarrival_timer_; std::vector next_time_; + gpr_atm thread_pool_done_; std::mutex thread_completion_mu_; size_t threads_remaining_; std::condition_variable threads_complete_;