schets / multiqueue

A fast mpmc queue with broadcast capabilities
MIT License
201 stars 29 forks source link

Try to avoid 100% cpu usage for reading #32

Open maxgorovenko opened 2 years ago

maxgorovenko commented 2 years ago

I'm trying to make a data bus with this lib and have a problem. When thread begins reading from stream, it uses 100% cpu.

Here is the example:

let (send, recv) = multiqueue::broadcast_queue(10);
let result = recv.recv(); // <-- while we are here, cpu is 100% hot

Is there a way not to use 100% cpu for reading/waiting? Tried multiqueue::broadcast_fut_queue() - got the same, but I think may be I don't understand some basics. I'm not very experienced in rust.

I'm not talking about async, just want thread not using 100% cpu while it is waiting for new message.

P.S. In some cases I saw cpu goes down to 2-4%, but I am not sure if that was not my code logic mistake.

Env: MacOS 11.6 rustc 1.55.0 (c8dfcfe04 2021-09-06)

f0i commented 2 years ago

I experience the same issue on Linux/Docker: Debian 11.1 rustc 1.56.1 (59eed8a2a 2021-11-01)