"IO multiplexing" is a common technical term in programming. There are many frameworks that use this technology, such as Redis, Kafka, Netty, and Nginx. So the question is, what is IO multiplexing? What are its specific implementation technologies? What are the differences between these technologies? Today we will briefly discuss it. 1. What is IO multiplexing?IO multiplexing is a technology that allows a single thread to manage multiple network connections. It enables the server to efficiently handle a large number of concurrent connections without creating a separate thread or process for each connection. picture Imagine if there are tens of thousands of clients, then non-IO multiplexing will have tens of thousands of threads, and then there will be problems of excessive IO contention and multi-thread switching, because there are only a few CPU resources, but there are tens of thousands of threads to be executed. 2. IO multiplexing technology implementationCommonly used IO multiplexing implementation technologies include: select, poll, epoll and kqueue, etc. Their specific introductions are as follows. 2.1 select
The number of file descriptors is limited : usually limited to 1024. This limit can be increased by modifying system parameters, but doing so will consume more system resources. Inefficiency : Each call to select requires copying the file descriptor list to the kernel and then copying it back to user space after checking, which is very inefficient for a large number of file descriptors. Does not support edge trigger mode : only supports level trigger mode. Edge Trigger Mode VS Level Trigger Mode
Advantages : Reduces the number of system calls and improves efficiency, especially suitable for scenarios with large amounts of data transmission. Disadvantages : The application must read or write as much data as possible after receiving an event, otherwise the subsequent data may be missed. Therefore, the edge-triggered mode has higher requirements for programming and needs to be handled more carefully.
2.2 poll
2.3 epoll
Unlimited : There is no limit on the number of file descriptors. Efficient : Only active file descriptors are passed to user space, reducing unnecessary copy operations. Powerful functions : Supports two working modes: edge trigger and level trigger. 2.4 kqueue
More powerful : It not only supports event notification of file descriptors, but also can handle other types of events. Excellent performance : Similar to epoll, only active file descriptors are processed, thus improving efficiency. 3. Distinction and contrastThe differences between select, poll, epoll and kqueue are as follows:
After-class thinkingWhat is a "file descriptor"? Why does IO multiplexing require "data copying"? |
<<: Modbus protocol: the cornerstone of industrial communication
Although Apple held a press conference recently, ...
At present, 5G has become a hot topic in the indu...
After the rapid development in 2020, 2021 is a cr...
Network slicing divides the network into multiple...
Nowadays, data has become an emerging production ...
[ Promotion code expired ] Title This should be th...
On April 28, Wu Hequan, an academician of the Chi...
The business of the three major operators has bee...
Network virtualization software allows companies ...
[[347744]] Few technologies have been in the spot...
[[383502]] Industry data: Forrester predicts that...
HTTPS Introduction to HTTPS HTTPS (Hypertext Tran...
"5G is like a newborn baby, new from head to...
How to solve the problem? Only WiFi! WiFi allows ...
South Korean telecom operator SK Telecom recently...