-
Notifications
You must be signed in to change notification settings - Fork 471
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
Yielding in crossbeam-channel #366
Comments
An idea that might alleviate the problem: if |
For the purposes of this issue its worth noting that I spoke with @stjepang over discord about the situation. Your suggestion might be worth exploring. For now I was able to alleviate the problem by attempting to coalesce things coming through the channel: loop {
match sel.ready() {
i if i == events_ready => {
// attempt to wait for more events to enable batch processing and cut down on yields
thread::sleep(std::time::Duration::from_nanos(500_000));
// use events_ready
}
i if i == shutdown_ready => {
shutdown.recv()
break;
}
_ => unreachable!(),
}
} The sleep is not the best solution here but currently is enough to allow the thread to batch things together. It may be better to try something in the |
I'm thinking the maybe the problem is the call to
that then uses a backoff without ever blocking if it's completed, at
Also note that this would occur in the context of this
where the "outer" backoff is checked for completeness and the thread blocks, if necessary. So it appears to that the "inner backoff", the one used inside
I guess the solution could be rewriting the I can suggest the following:
I'll give it a shot actually... |
Why not use something like: let mut items = vec![];
let timeout = after(duration);
loop {
select! {
recv(timeout) -> _ => { break; }
recv(chan) -> msg {
items.push(msg);
if items.len() >= BATCH_LEN { break; }
}
}
}
// Process items... |
@papertigers could you please try running your test with this PR and see if it helped at all? #447 |
found this *working* invite link here: crossbeam-rs#366 (comment) fixes crossbeam-rs#483
found this *working* invite link here: crossbeam-rs#366 (comment) fixes crossbeam-rs#483
Hey @papertigers, I just saw your message on IRC, which I am repeating here:
Thanks for the report! I think it'd be easier to chat either over on GitHub or on our discord channel since we have moved off IRC.
My guess what is going on here is that in
std::sync::mpsc
,Sender
instd::sync::mpsc
is slower than its correspondingReceiver
so the messages build up and nobody ever has to block.On the other hand, it may be that in
crossbeam-channel
,Sender
is slower thanReceiver
so sometimes theReceiver
has to block, which is where those yields come from.Could you perhaps verify if my hypothesis is true?
The text was updated successfully, but these errors were encountered: