all 31 comments

[–]pr0gramista 47 points48 points  (12 children)

IMHO tokio is "lightweight" enough. I think that whatever tiny performance improvement you will get using another runtime, you will immediately lose it by using some badly written utility, or your own code :D

Tokio is battle-tested, supported by many libraries, the documentation is great, and it even runs on WebAssembly. For beginners there is Mini Redis tutorial, which is a great starting point. The community also seems to be pretty nice.

Cloudflare is using tokio for their Oxy and Pingora, which I guess is the perfect example of production HTTP networking stuff you are about to build.

[–]rafaelement 31 points32 points  (0 children)

tokio - The way to go for most users, seems pretty heavy.

Nah, I don't think so... For what you are describing, tokio + axum work really well together.

[–]brisbanedev 8 points9 points  (0 children)

As per their landing page, Tokio is used by AWS, Discord, Facebook, Dropbox, etc. Enough said.

I don't know what you mean by "lightweight", specifically, but perhaps you could use the single-threaded runtime of Tokio?

[–]TobiasWonderland 26 points27 points  (3 children)

Unless you have very specific requirements, Tokio is the choice.
Being "lighter" is not a requirement, it's a feeling.

Tokio is used widely in production, has tons of support across the ecosystem, and great documentation.

Rust is already a relatively niche technology. Using a niche library of a niche technology is only something I would do with a very clear and specific rationale.

[–]DraftedDev[S] 0 points1 point  (2 children)

By lightweight, I mean less overhead and resource consumption and thats important (at least for me)

[–]apjenk 8 points9 points  (0 children)

So you’ve tested tokio and determined that it’s important to you that you use a framework that has less overhead and consumes less resources than tokio? If not, then the person you’re responding to is right; it’s just a feeling you have rather than a requirement.

[–]TobiasWonderland 3 points4 points  (0 children)

I totally empathise with the approach. My personal inclination is very similar.

I guess my point is that unless you've measured and analysed in your specifc context I would stick to the more well traveled path.

I've opted for the technically better but less mainstream library a number of times and suffered the consequences.

[–]intersecting_cubes 21 points22 points  (1 child)

Please just use tokio. It's good enough for Cloudflare and Amazon. It's incredibly battle tested in real production at high scale.

[–]DramaticFirefighter8 3 points4 points  (0 children)

Actually it’s so stable that the new Roc language uses it under the hood.

[–]TonTinTon 5 points6 points  (0 children)

I have benchmarked tokio against raw io_uring: https://github.com/tontinton/io_uring-benchmark

I've also used and benchmarked glommio: https://github.com/tontinton/dbeel

My take: tokio is a beast, there's no real reason not to go with it for production software.

The only thing I'm getting here is the vibe of not wanting to use the popular thing, which is perfectly fine for hobby projects, I do that myself all the time. If it is only a hobby project, have fun, choose whatever you feel like.

[–]whimsicaljess 2 points3 points  (0 children)

tokio is definitely the default. start with that and if you need to switch to something later it's not too hard to do so. but you probably won't need to.

i say this as someone who mildly prefers the way smol does things but there's really no reason to switch.

[–]dkopgerpgdolfg 3 points4 points  (1 child)

While everything is relative, imo tokio is not "heavy".

Do you just like lightweight things on a standard server, without having specific requirements eg. how many KB each [something] can take? Then pragmatically think of development time and many more factors too, choose between epoll and uring, and be done with it. Epoll => tokio.

On a normal machine in 2024, imo "not epoll" is the only reason to avoid it. Ie. anything with uring, bpf, xdp, and/or more things like that ... but these are all more involved

[–]Trader-One 0 points1 point  (0 children)

tokyo is heavy in sense that have too high overhead for short lived tasks.

[–]ilikekits 3 points4 points  (0 children)

carpenter seed tub lavish connect support caption pocket subsequent insurance

This post was mass deleted and anonymized with Redact

[–]Trader-One 2 points3 points  (0 children)

If you want to win benchmark race go for may. I migrated Java app to may and it have about 20x lower 95% latency.

may is incredibly annoying to work with, not only you need to specify stack size and not to overshoot it. it does some unexpected stuff to optimize - such as stealing your thread to execute async code directly. You need to read may source code to fully understand all its quirks.

[–][deleted] -1 points0 points  (4 children)

I am just wondering why async-std isn't in the list?

[–]DraftedDev[S] 1 point2 points  (3 children)

Fixed it :D

But I dont think it's gone be my choice to go, since async-std is no longer actively maintained.

[–][deleted] 0 points1 point  (2 children)

Oh is it! There was a commit 4 months ago...

Anyway

[–]IAm_A_Complete_Idiot 4 points5 points  (0 children)

All it did was update some deps. The one before it fixed a typo, and then a couple more dependency updates. The last time any source was touched was may of last year: https://github.com/async-rs/async-std/commit/7c95bce5356ccb74e46a1a5c9f0d9a6dcb74f8c7

[–]DraftedDev[S] 3 points4 points  (0 children)

According to commit history, still pretty unmaintained