Conditional variable instead of sleep_for#23
Conditional variable instead of sleep_for#23yvoinov wants to merge 1 commit intoinkooboo:masterfrom yvoinov:patch-2
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 8Continue 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.
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.
Мммммммм, 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.
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.
If you're going to worry about the cost of that it might be more interesting to look at the call to
notify_oneyou 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.