-
Notifications
You must be signed in to change notification settings - Fork 567
Avoid absl::BlockingCounter use for the single-threaded WorkerPool #8852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b84b6ba
to
552168b
Compare
552168b
to
23ae71f
Compare
@@ -14,6 +14,11 @@ class WorkerPool { | |||
using Task = std::function<void()>; | |||
static std::unique_ptr<WorkerPool> create(int size, spdlog::logger &logger); | |||
virtual void multiplexJob(std::string_view taskName, Task t) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we document this one too, something like
"does not block after launching the workers, usually useful so that the main thread can 8000 have a consumer queue that streams the results of the worker threads as they produce them"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely!
@@ -26,6 +26,7 @@ cc_library( | |||
"//common/enforce_no_timer", | |||
"//common/exception", | |||
"//common/os", | |||
"@com_google_absl//absl/synchronization", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know whether it's worth it to also remove the absl/synch dep from common/BUILD
(or even whether it's possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it a try!
In some uses of
WorkerPool::multiplexJob
we allocate anabsl::BlockingCounter
and wait on it after the call tomultiplexJob
to ensure that all workers finished processing our job. This is a fine pattern, but in the case of a worker pool created with0
workers, the blocking counter is totally unneeded asmultiplexJob
will execute our task directly.We can avoid the
absl::BlockingCounter
use entirely if we add a specialization ofmultiplexJob
for this case specifically, and that's what this PR does.WorkerPool::multiplexJobWait
manages the allocation and use of the counter in the multi-threaded case, and avoids it all when we're running single-threaded.Motivation
Performance improvements when we're running with an empty worker pool, which happens frequently during slow path preemption in LSP.
Test plan
Existing tests.