3 ms·
> basically you shouldn't expect your code to block on disk io. But even if it does block for a very short amount of time it's probably fine. No, it's very oft
by beagle3 11y ago
> basically you shouldn't expect your code to block on disk io. But even if it does block for a very short amount of time it's probably fine.
No, it's very often not fine. Magnetic disks, still the norm for many, and definitely with large storage, often go as low as 5KB/s for random access (or even sequential access to very fragmented files). Reading a 1MB file can easily take 5-10 seconds in some setups - which is not acceptable for any interactive service. It's not fine for a web server to not service any requests for 5 seconds.
> Another option is to use modern APIs like aio in Linux, but as far as I know almost nobody uses it for real.
Anyone I know who tried came back screaming. There is no way to do an async file open, for example - which means that if you rely on aio, you can block for 10 minutes waiting for an NFS or SMB mounted file to open.
The only sane, portable thing to do for Unix/Posix is use a threadpool for async file io - or just use something like libuv which already abstracted async operations this way.