Closed fulara closed 5 months ago
I'd like to think through the implications of this, I'm worried about heavily biasing toward a specific thread, starving others of items. Perhaps this is fine if that one thread is capable of servicing senders in appropriate time though. Do you happen to know whether there's prior work on this for other implementations?
Yes, someone else pointed out this issue too, that this might cause starvation of other workers.
This change is fine as long as all the workers have exactly same way to handle the calls. I am going to experiment with it locally, but I don't think it is a good candidate to merge here.
Maybe as a separate API it would be decent, but I don't want to go that far.
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