Live data from Hacker News

Who Runs Your Rust Future? Hands-On Intro to Async Rust

aibodh.com

31–40 of 40 posts

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#31
post #16

Earlier quoted context omitted.

Your confusing concurrency with parallelism. Async allows one core to switch between many threads of execution that can do work and not stop one thread of execution because it needs to wait for a resource. It's beneficial to use async if you're application is I/O heavy even if it's single threaded. > Whereas async simply locks the CPUWhereas async simply locks the CPU This is also completely nonsense, context switchi…

> context switching behavior is OS dependent and your average general purpose kernel is not cooperative. True, but if all you are using is async, then you're basically back at Windows 3.1 cooperative multitasking, except now within a Rust program.

Tokio uses a thread pool with work stealing so it is definitely more advanced than Windows 3.1's model!

As other commenters have pointed out, cooperative multitasking is actually a great fit for I/O bound code.

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#32

Ok, what is going on in the comments here? I get people liking the article but this many comments just to say they liked it is very un-HN to me. Smells like bots to me.

Taking a quick look at the commenter's in question, it seems possible that the person who wrote the article asked people they know to boost it on yc. They don't appear to be bots at least.

Author of the article here.

No, I haven't asked anyone to upvote or comment. It was posted 2-3 days ago, there were no upvotes. And I was feeling concerned. (I am doing this full time and getting on top of HN for my own work was a dream). I had written articles on bevy and also posted on HN (in last 6 months). But they hardly got any traction on HN.

Not sure what happened today, I saw traffic from HN and was surprised to see this on #8.

I also noticed few comments looked LLM generated (they got deleted), but I am not sure why someone would do it, I mean the incentive.

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#33
post #18

Earlier quoted context omitted.

You can mix and match. For work, I run a conferencing server ... packet processing runs in one thread per core, out of band signalling runs in async on a separate pool of threads. It used to all be async, but using threads for packet processing shaved a little cpu, doing my own timers shaved a little cpu, cpu pinning the threads and the sockets shaved a little cpu, and at the end of the day we shaved a couple instanc…

> For other things, async task (or green thread, whatevs) per connection is a very nice model that you can't do with thread per connection I don’t think I ever seem this patterns, What I’ve seen is either a thread pool for tasks (what essentially async is), or dedicated threads for each parts of the processing (a thread for the UI, and a thread for some background services like playing music).

> I don’t think I ever seem this patterns, What I’ve seen is either a thread pool for tasks (what essentially async is)

this doesn't really contradict with

> async task (or green thread, whatevs) per connection

The async tasks will probably run on a thread pool (e.g. in tokio).

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#34

Async ruined rust and I’ll stand by that until I die

Async Rust can be nice, especially when juggling multiple tasks and composing them with timeouts and such.

Async in an embedded context is actually really nice, too. You can have high level "send this thing over SPI, receive this data from USB" futures and they will run (ideally via DMA) and your CPU can go to sleep, only waking up when interrupts fire from the hardware peripherals you were using.

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#35
post #17
post #11

Bit weird to have a rust tutorial list JavaScript async as assumed knowledge tbh.

Yeah, it also makes it seem like Rust is weird for using Future as the type name, but actually JavaScript (Promise) is the odd one out here. Probably a JS dev learning Rust without much exposure to other languages

Fixed this, thank you.

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#36

Earlier quoted context omitted.

You use async to preserve system resources. For example you can easily exhaust the host with ~20k connections running a thread-per-connection schema where each thread simply waits for epoll event, async prevents this by having a threadpool of ~16 threads that handle all the connections instead of polling the scheduler wakes it up, asks "do you haev work to do" if not continues to next task. (This heavily varied by th…

> You use async to preserve system resources. For example you can easily exhaust the host with ~20k connections running a thread-per-connection schema... Sure, if you need to run 20k connections then use async. But the fact of the matter is that the vast majority of software is not going to take on 20k connections. Those people (i.e the majority of software devs) should use threads, because they are much easier to re…

[dead]

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#37
post #4

> What is harder to find is the bridge between them, the part that connects understanding how async works to actually shipping with it. There is actually already a tutorial at this level: Tokio has its ‘async in depth’ tutorial [1] that walks you through building a toy runtime and using it to run a future. Not a complaint — you can never have too many tutorials, unless they're about monads — but just a pointer in cas…

Ah what a great little tutorial. Thanks for sharing that one.

It looks like rust async creates state machines similar to how Kotlin does it with so-called Continuations.

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#38
post #11

Bit weird to have a rust tutorial list JavaScript async as assumed knowledge tbh.

I had the same thought, but then I realized that everyone on my team actually _does_ have experience with JavaScript async, so I just rolled with it. Not sure what that's about

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#39
post #4

> What is harder to find is the bridge between them, the part that connects understanding how async works to actually shipping with it. There is actually already a tutorial at this level: Tokio has its ‘async in depth’ tutorial [1] that walks you through building a toy runtime and using it to run a future. Not a complaint — you can never have too many tutorials, unless they're about monads — but just a pointer in cas…

Ah what a great little tutorial. Thanks for sharing that one. It looks like rust async creates state machines similar to how Kotlin does it with so-called Continuations.

Yes I really think it should be better advertised!

The continuation model is the standard model of async programming and still perhaps the nicest semantically. Rust's big innovation is that futures are polled from the top, i.e. (potentially) advanced in an idempotent way whenever any of their relevant resources progresses, which is nicer for resource-conscious programming because it doesn't require that you capture the stack. It adds complexity over the continuation model from the programmer's point of view, but opens up async programming to a wider range of contexts in a way that is genuinely novel.

Re: Who Runs Your Rust Future? Hands-On Intro to Async Rust

#40

Async ruined rust and I’ll stand by that until I die

I think it was rushed, and it has some rough edges that are now too late to fix post-stabilisation. But it's neat to have such a runtime.

One annoying thing is that it's optimised for multi-threaded runtimes, so the APIs enforce lifetime requirements which don't make sense for single-threaded async applications.

Post reply on HN