-
Notifications
You must be signed in to change notification settings - Fork 128
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
Conditional variable instead of sleep_for #23
base: master
Are you sure you want to change the base?
Conversation
I'm trying to avoid some overhead when pool is idle or underload. Pls, advice me - is this way correct? Testing shows less overall pool latency, but I'm in doubt - this should not be serialization point for scaling.
Codecov Report
@@ Coverage Diff @@
## master #23 +/- ##
======================================
Coverage 94.2% 94.2%
======================================
Files 5 5
Lines 138 138
======================================
Hits 130 130
Misses 8 8 Continue to review full report at Codecov.
|
template <typename Handler> | ||
inline bool Worker<Task, Queue>::post(Handler&& handler) | ||
{ | ||
+ m_conditional_lock.notify_one(); |
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 think you should do the notification after you have added the job to the queue otherwise the worker might try to pull the job too soon
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.
Мммммммм, in theory may be. In practice....hardly. Also, how you imagine such implementation? I see only one way - additional local variable requires, so more assembler, slower execution... No, not so good idea.
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.
If you're going to worry about the cost of that it might be more interesting to look at the call to notify_one
you have for every posted job. Compared to that cost saving the bool result is essentially free.
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.
If you're going to worry about the cost of that it might be more interesting to look at the call to
notify_one
you have for every posted job. Compared to that cost saving the bool result is essentially free.
Take a look on my own fork of this library. Done long time ago. :) This PR is years old :)
Anyway, you can make you own fork, perform benchmark and compare. :)
I've just made some performance tests with variant you offered:
There is no visible performance difference with original one. So... see no reason to make such change. Don't forget - compiler can change code order, and it is non-mandatory will execute as written. |
I'm trying to avoid some overhead when pool is idle or underload.
Pls, advice me - is this way correct? Testing shows less overall pool latency, but I'm in doubt - this should not be serialization point for scaling.