← Back to context

Comment by himata4113

8 hours ago

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 the async runtime implementation, each async runtime can and will act differently to maximize efficiency over throughput)

> 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 reason about and work with.

  • async gives you a few other advantages, it allows you to handle bi-streams much easier than two sync threads especially when it comes to synchronization.