6 ms·
If you are not using async IO and have a thread per core, if (as is quite common) your program needs to make IO calls (network being likely worst case) then t
by btbuilder 5y ago
If you are not using async IO and have a thread per core, if (as is quite common) your program needs to make IO calls (network being likely worst case) then the thread will sleep on a blocking IO call and CPU will be idle even if there’s work in a queue.
- vemv 5y agoIO doesn't cause the whole CPU to be idle. It simply causes a context switch, which will allow another thread to do work.
- kaba0 5y agoBut it might not come back to the thread that made the IO only “much” later when the IO call interrupts. So a given thread will spend more time than necessary inside the thread pool, stealing resources from other threads.
- btbuilder 5y agoIf you only have one thread per core it is possible there will be no runnable threads while there is still work in the queue. Other threads could be waiting for IO or already running.