Asynchronous I/O in DuckDB: Work, Thread, Work
duckdb.org(Disclaimer: I’m the author of the blog post.)
Ducks all the way down!
I built a system once which had (this is Rust) a Rayon worker thread pool of 4 threads and a Tokio async pool of 2 (multithreaded runtime). On a system of 6 vCPU. This ended up working fine. Tokio was not starved so handled network requests at low latency.
One difference is DuckDB is a pure network client. If one of its async threads is starved it is not the end of the world (e.g. k8s does not kill your pod for failure of replying to health checks).
There is still something to gain from tuning it further (as you can see in the async I/O tuned benchmark), but having that network saturation by default is still a work in progress.
(Disclaimer: I'm the author of the blogpost)
On my ryzen 9 it needs around 8 cores to do the same work in a threaded io loop than you can do single threaded. And the mechanism doesnt matter, you could share an fd, use SO_REUSEPORT or just share memory between threads.
Just doing the sharing makes everything extremely slow. One context switch becomes more expensive than just doing it single threaded.
I've never gotten around to writing a blog post about it, but I go quite in-depth on the technique in this presentation: https://www.youtube.com/watch?v=YrqSp8m7fmk
(Disclaimer: I'm the author of the blog post and also the developer who implemented the entire CSV parser in DuckDB.)
version 1.4.4: 31.89s
preview: 4.42s