"Be careful with mutexes" is good advice, but I'm surprised it doesn't explicitly call out the various channels that tokio provides as alternatives (detailed here: https://docs.rs/tokio/latest/tokio/sync/index.html ). There are a variety of options that fit different use cases, and you don't even need to enable the runtime feature to use them (e.g. if you want to do a single check for completion rather than await). I…
(I am OP) Both good call outs. Will update the article to include them
Principles for Fast Tokio Applications
41–50 of 72 posts
Re: Principles for Fast Tokio Applications
#42For a true high performance you should use thread busy-spinning, CPU pinning and SPSC/MPSC ring buffers.
It all depends on what you are doing. I do embedded with strict realtime requirements. CPU pinning would not be an option. I have also done software that should use as little resources as possible (but still be quick) to coexist with other software on the same hardware. All of these are different, valid, meanings of high performance. You need context. An interactive IDE is yet another thing that needs to be high perf…
Re: Principles for Fast Tokio Applications
#43Earlier quoted context omitted.
The "C++ community", if it even exists, barely believes in sharing code let alone any library being "dominant." They'd have to agree on a build system first, after all. But honestly that's a mischaracterization of the situation in Rust. Tokio is popular for networked service backends. If that's the wheelhouse you're in then yea it might look "dominant."
You don't need a build system to share code. You can share with header files and respective (shared) object files regardless of the build system you're using. Likewise you could just share the source. None of this needs a build system.
Re: Principles for Fast Tokio Applications
#44Earlier quoted context omitted.
Just curious, why? Is this true even if you did something like a per-CPU histogram that uses atomic ops to increment?
If you have a per-cpu metric there would not be a reason to use atomic instructions to mutate it.
Re: Principles for Fast Tokio Applications
#45Re: Principles for Fast Tokio Applications
#46"Be careful with mutexes" is good advice, but I'm surprised it doesn't explicitly call out the various channels that tokio provides as alternatives (detailed here: https://docs.rs/tokio/latest/tokio/sync/index.html ). There are a variety of options that fit different use cases, and you don't even need to enable the runtime feature to use them (e.g. if you want to do a single check for completion rather than await). I…
Re: Principles for Fast Tokio Applications
#47"Be careful with mutexes" is good advice, but I'm surprised it doesn't explicitly call out the various channels that tokio provides as alternatives (detailed here: https://docs.rs/tokio/latest/tokio/sync/index.html ). There are a variety of options that fit different use cases, and you don't even need to enable the runtime feature to use them (e.g. if you want to do a single check for completion rather than await). I…
Why use mutexes (mutices?) over semaphores?
Re: Principles for Fast Tokio Applications
#48Earlier quoted context omitted.
If you have a per-cpu metric there would not be a reason to use atomic instructions to mutate it.
In general your unpinned userspace threads will hit the same CPU 99.99% of the time, but not 100%.
Re: Principles for Fast Tokio Applications
#49Earlier quoted context omitted.
It all depends on what you are doing. I do embedded with strict realtime requirements. CPU pinning would not be an option. I have also done software that should use as little resources as possible (but still be quick) to coexist with other software on the same hardware. All of these are different, valid, meanings of high performance. You need context. An interactive IDE is yet another thing that needs to be high perf…
Also, using 100% CPU without a good reason can cause thermal throttling that makes it slower for the sections that actually need 100% CPU
Re: Principles for Fast Tokio Applications
#50Earlier quoted context omitted.
Why use mutexes (mutices?) over semaphores?
Aren't semaphores a more fundamental primitive that is trickier to get right? Otherwise, the mutex guards in Rust are very ergonomic.