4 ms·
The problem with async programming, or cooperative multitasking (as it was popularized in the Windows 3.1 era) is that the CPU is a resource too. Threads are a
by amelius 3y ago
The problem with async programming, or cooperative multitasking (as it was popularized in the Windows 3.1 era) is that the CPU is a resource too. Threads are a better way of slicing up CPU time.
- xedrac 3y agoIt is clearly not an ideal abstraction for anything CPU bound. But for anything IO bound, it is a much more natural way to tame the complexities of concurrency.
- amelius 3y agoThe problem is that systems evolve. What's IO bound today may be CPU bound tomorrow. And then you'll have to rethink and depending on what language you use you may even have the "what color is my function" problem.
- Dowwie 3y agoWhat do you mean by this claim that what is io bound today may be cpu bound tomorrow?
- toast0 3y agoThere's two ways to understand that. What I think is the likely intention is the requirements may change, such that pieces that currently don't do much computation start to do a lot. Easiest one to think about is adding encryption. Your http server may have been bottlenecked on disk or network i/o, but your https server may be bottlenecked on cpu; not a great example because the cpu work in TLS is in bits and pieces and will probably share nicely. The other way is that sometimes a little more load perturbs the system so things take a lot longer. I've had systems that work fine until you hit X% cpu, then it jumps to 90%+, because of say lock contention; sometimes N is 80% so whatevs, but sometimes it's 25%, and then you need to find and fix the bottleneck.
- seized 3y agoThe transition from spinning disks to SATA/SAS flash to NVMe.
- jcelerier 3y agoData storage is one example, a lot of time loading of data from HDD was the n°1 performance issue as it was thousands of time slower than CPUs ; nowadays the fastest SSDs have sequential reads that read at 12GB/s (DDR3-1600 speeds!) which can easily be much faster that whatever non-trivial processing you'll apply to the data, so the bottleneck moved from IO to CPU.
- xedrac 3y agoI'm not sure that I'd want to avoid using a good abstraction because 20 years from now, it may perform marginally worse than it could had it been modeled with much more complexity. Clearly it depends on the use case, but you get my point.
- SnowProblem 3y agoAsync is a bit trendy right now and in my experience has a way of infecting a codebase. That said, I like the way it reads for server code. In a project I'm working on, we use both: explicit threads and channels the CPU-bound work and an async REST server on a single thread for handing requests and reading the database. It works nicely. But we do have a clear separation boundary between the two. Also, here's a related post that surprised me. Poster says spawning a thread per connection works fine for their server at 50K+ connections. Context switching and spawns not a problem? Maybe not always. https://stackoverflow.com/questions/17593699/tcp-ip-solving-the-c10k-with-the-thread-per-client-approach https://stackoverflow.com/questions/17593699/tcp-ip-solving-...
- toast0 3y ago50K is not really very many connections. How about 1M?
- SnowProblem 3y agoTrue, and C10M is the new C10K. I was just surprised it works well using that many OS threads rather than needing green threads or async.
- bfrog 3y agoI mean this too can be dealt with in Rust with a pool of threads dealing with the computational tasks that respond with futures. E.g. pool of 10 threads does computational heavy task requests and responds when done to the async i/o bound task.