Timeline for Is Epoll/Multiplexing suitable to make network requests instead of "listen to" incoming requests?
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 26, 2022 at 13:24 | comment | added | Criticizing Israel not allowed | @amon If a socket is set to non-blocking mode, then read, write, recv and send do not block. That's why it's called non-blocking mode. | |
Jul 26, 2022 at 13:23 | comment | added | amon | @user253751 Really depends on how non-blocking you want to be. Select/epoll only tell you whether data is available, but you'd still have to use blocking syscalls like read/write/recv/send to actually perform the IO. Posix AIO exists but no one uses it since it isn't actually asynchronous in many situations. Only io_uring provides for truly async IO on Linux. | |
Jul 26, 2022 at 12:45 | comment | added | Criticizing Israel not allowed | Select and epoll can be made to work if you also use non-blocking I/O. You don't need a thread pool. | |
Apr 27, 2021 at 14:46 | vote | accept | Mattias Santoro | ||
Apr 27, 2021 at 14:40 | comment | added | amon | @MattiasSantoro (1) The point of the thread pool is that those threads are blocked, not the main thread. But if you have 10 tasks for 4 threads then yes, 6 will have to wait. (2) The main thread doesn't have to context-switch (syscall or to another thread) to enqueue IO tasks: the queue can use shared memory. The IO threads will context switch a lot. Since the IO threads spend most of the time waiting for something, they're not hogging their own CPU each – threads that are blocked will not be scheduled, and the scheduler can run other tasks meanwhile. | |
Apr 27, 2021 at 14:00 | comment | added | Mattias Santoro | Thanks for your answer! If possible, I ask some clarification: (1) I know there is a thread pool to handle IO, but how each operation is delegated to the thread pool? If I enqueue 10 IO operations and I have 4 IO threads free in the pool I end up with 4 operations running each on a thread and 6 waiting for a free thread, right? Or they are somehow "all distributed" among the 4 threads? (2) Why you say there is no context switch? On a 4 core CPU, I can have one core handling the main loop and the other three handling IO threads, won't the fourth IO thread never gain its turn on the CPU? | |
Apr 27, 2021 at 13:23 | history | answered | amon | CC BY-SA 4.0 |