2 ms·
I realise I'm picking one sentence out of the middle of this, but this is the one thing I don't feel I understand about async: "But well-formed Futures complet
by CJefferson 2y ago
I realise I'm picking one sentence out of the middle of this, but this is the one thing I don't feel I understand about async:
"But well-formed Futures complete quickly"
Does this mean people writing async code don't ever write code which takes a while to compute?
I write lots of code which takes 10s of milliseconds, or 100s of milliseconds, or hours. And none of these feel like a good fit for async, as even a 10s of milliseconds piece of work would be enough to start to limit throughput and add unacceptable lag to other connections?
This is fine in a multi-threaded server, one thread per connection, you make a difficult request, the server spins for half a second before responding to you -- but it doesn't really fit in a async program?
- hinkley 2y agoDefinitely not going to solve a c10k problem with 10ms pauses, that’s for sure.
- CJefferson 2y agoTrue, but some problems just require that long to get the answer the user wants! Some problems take 60 CPU years, but those you don’t expect the user to actively wait while you distribute their task and wait for the results, you send them an email in 3 months or so! :)
- dcow 2y agoThe same problem comes up at the end with the proposed `#[blocking]` solution. There is no formal definition of blocking outside of async. It's a colloquial term meaning "takes a relatively longer time to finish". Async is the formalization of making a distinction between grinding the cpu and yielding until something else wakes you up and tells you to keep going. So I guess a well formed Future always adds yield points between hot loops? And then you just trust the runtime to manage execution context such that your yields are noops if there's no contention for execution time and/or to avoid needless context switching.
- CJefferson 2y agoThis sounds like the same kind of problem the Linux kernel is trying to get rid of, and we used to live with back in Windows 3. It’s very hard to put in enough yield points to never block for too long in a complex algorithm, and I was so happy when I stopped having to do that myself!