this post was submitted on 22 Sep 2023
42 points (97.7% liked)
Rust
6005 readers
4 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
A good topic to chat about.
But before that, I should mention that I had to use the browser's inspector to disable that background color. Light and dark backgrounds are both fine (I have color inversion bindkeyed after all). It's the ones in the middle like this one that are a no-no.
Stats? User surveys?
I would expect that many users (including myself) actually just use the runtime, directly or indirectly (e.g. via
async-global-executor
with thetokio
feature), while API usage is covered by crates likeasync-io
,async-fs
,async-channel
,blocking
, ...etc.In fact, I would hypothesize that, from an ecosystem adoption POV,
tokio
's only killer feature ishyper
's dependence on it. If it wasn't for that dependence,tokio
's adoption, I would expect, would be much lower. But this is admittedly anecdotal.This and the quote above it seem to be Rust intellectuals' flavor of the month position.
It kind of reminds me of the lowering dependencies' compile times craze from a few years ago. Stretching the anti-MT-RT narrative to the point of making bad advice like recommending sync channels for an IO task adds to the parallels.
Or maybe you know, using APIs that already existed in std for a reason, as intended!
Generally true. But probably false here.
People reaching for
Arc
+Mutex
/RwLock
/... (doesn't have to be aMutex
) in asyc code are probably aware of alternative designs, but still decide to useArc
+Mutex
/RwLock
/... when it's either necessary, or when it actually makes things simpler, and the downsides (performance) are of no measurable relevance, or the alternative design is actually slower (i.e. the multi-threaded runtime is actually helping).I would consider arguments that talk about "killing all the joy of actually writing Rust" in this context as either intellectual posturing, or simply disingenuous.
Otherwise, there is not much to disagree with.
As someone who has tried doing multithreaded design with Arc/Mutex, this is a complete nightmare. You constantly get into deadlocks and performance is abysmal, because Mutex is serializing access (so it’s not really async or multithreaded any more).
I myself often use channels. And pass owned data around.
I don't think anyone argues that Arc+interior-mutation is ideal. But it's the over-the-top language like "complete nightmare" that some may take issue with.
Note that I again make the distinction between
Mutex
, and all interior mutation primitives. BecauseMutex
is indeed a bad choice in many cases. and over-usage of it may indeed be a signal that we have a developer who's not comfortable with Rust's ownership/borrowing semantics.Mutex
specifically as above.async-lock
,tokio
,parking_lot
, or juststd
?I used parking_lot back then.
AFAICT, the current hyper v1 release candidate only depends on tokio for
tokio::sync::{mpsc, oneshot}
(andsync
is the only enabled feature).It's intended to be runtime-agnostic. See also https://docs.rs/hyper/1.0.0-rc.4/hyper/rt/trait.Executor.html . I agree that its ecosystem is still very tokio-centric.
FYI, I had some time to check out
hyper
v1 today.The new API of
hyper
proper is very low-level. Directly usable API is apparently moved to ahyper-util
crate, which, as expected, does have a hard dependency on the tokio runtime.So, while it's good that
hyper
proper won't hard-depend on tokio rt, it appears that non-tokio-rt usage will either depend on a higher-level 3d party crate, or a lot of effort from directhyper
dependants to write a lot of glue code themselves.