Threads waiting for data go to the front of the queue #151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rather than using a round-robin approach for all threads waiting on the
recv
, prioritize the threads that were most recently active to pick up an item next.Threads that have recently done some work have a higher chance of remaining in the cache. This approach is especially useful in scenarios where there are many more threads waiting to receive data than there are CPUs. Only when the system becomes backed up will threads further down the pipeline be awoken.
Imagine a scenario where we have 10 threads receiving on the channel, but usually there is only 1 item in the queue, so a single thread is able to process it all without more items accumulating. With this patch while the system is in this semi-idle state it will be always same thread, giving a slightly higher chance of its stack being still in cache.
This addresses #150