635
STOP DOING ASYNC (lemmy.world)
submitted 8 months ago by Maven@lemmy.world to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] barsoap@lemm.ee 2 points 8 months ago* (last edited 8 months ago)

Because the kernel doesn't like you spawning 100k threads. Your RAM doesn't, either. Even all the stacks aside, the kernel needs to record everything in data structures which now are bigger and need longer to traverse. Each thread is a process which could e.g. be sent a signal, requiring keeping stuff around that rust definitely doesn't keep around (async functions get compiled to tight state machines).

Specifically with io_uring: You can fire off quite a number of requests, not incurring a context switch (kernel and process share a ring buffer) and later on check on the completion status quite a number, also without having to context switch. If you're (exceedingly) lucky no io_uring call ever cause a context switch as the kernel will work on that queue on another cpu. The whole thing is memory, not CPU, bound.

Anyhow, your mode of inquiry is fundamentally wrong in the first place: It doesn't matter whether you can explain why exactly async is faster (I probably did a horrible job and got stuff wrong), what matters is that benchmarks blow blocking io out of the water. That's the ground truth. As programmers, as a first approximation, or ideas and models of how things work are generally completely wrong.

this post was submitted on 28 Jan 2024
635 points (94.8% liked)

Programmer Humor

32275 readers
995 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS