4 ms·
Synchronous: The thread will block until the I/O operation is done. No work is performed in this time. Asynchronous: While waiting for the end of the I/O operat
by davidkunz 5y ago
Synchronous: The thread will block until the I/O operation is done. No work is performed in this time.
Asynchronous: While waiting for the end of the I/O operation, the thread can continue to work, e.g. by handling other requests.
So, it's not a problem when the thread sleeps while waiting for the end of the I/O operation, but it's not optimal.
- __turbobrew__ 5y agoSure, that one thread is blocked but it doesn’t take any CPU time and the rest of the threads on the system continue to run and handle requests? You can pretty easily run thousands of worker threads on a modern system so I don’t see the issue when one of your threads gets blocked on I/O? The linux kernel has a pretty good handle on multitasking, blocking, and scheduling so I don’t see the desire to rebuild the wheel in userspace with coroutines to achieve what the kernel already does.
- davidkunz 5y agoCareful, this is not Erlang. These are real threads, you won't be able to have thousands of them, more like 20 [1]. If most of them are idle, then you can maybe increase it to ~100. They come with a considerable overhead, so it's better to have one thread handle several I/O operations concurrently and in parallel, than to have one thread dedicated to only one I/O operation. [1]: https://serverfault.com/questions/1012360/how-can-i-tell-the-maximum-threads-my-server-can-run#:~:text=Each%20core%20can%20only%20run,one%20thread%20per%20CPU%2Fcore https://serverfault.com/questions/1012360/how-can-i-tell-the....