Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Eighth, the network service Istroke O model

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

8.1. Four kinds of Istroke O models

In the operating system, the process cannot directly manipulate the Icano device, it must assist in completing the Icano action by requesting kernel through the system call, and the kernel maintains a buffer for each iUnip O device. The communication model between the process and Icano is shown in the figure.

For input, it takes time to wait data into buffer, and to copy (copy) data from buffer to the process. According to the difference between the caller and the callee, there are four Icano models.

Caller handling measures:

Blocking: the process initiates an Iamp O call, and the current process will be suspended before it is completed

Non-blocking: the process initiates an Ithumb O call, which does not block the current process until the called function is completed, but returns immediately

Callee responds:

Synchronization: after a process initiates a procedure call (function, function) call, the call will not return until the result is obtained

Async: after a process initiates a procedure call, even if the caller cannot get the result immediately, the call will return with an unfinished state. When the call is completed, the kernel will notify the caller that the result has been OK.

8.2. Five kinds of network service Ithumb 0 model

According to the waiting mode, the Istroke O action can be divided into five modes:

Synchronous blocking: the process blocks until the data copy is complete.

Synchronous non-blocking: non-blocking IO repeatedly calls IO functions through the process (multiple system calls and returns immediately); the process is blocked during data copying.

Select O reuse: mainly select and epoll; have no advantage over blocking IO for a single IO port with two calls and two returns. The key is to listen to multiple IO ports at the same time.

Asynchronous IO: the process does not need to block when data is copied.

Signal driver: two calls and two returns.

Comparison of five IO models:

8.3 、 select/poll/epoll

Select

In essence, the next step is to set or check the data structure that stores the fd flag bits, but the number of fd that a single process can monitor is limited, that is, the size of the listening port is limited. Socket is scanned linearly, that is, polling is used, which is inefficient, and it is necessary to maintain a data structure used to store a large amount of fd, which makes it expensive for user space and kernel space to copy the structure.

# cat / proc/sys/fs/file-max # check the number of listenable fd

Poll

Essentially no different from select, it copies the array passed in by the user to the kernel space, and then queries the device status corresponding to each fd. There is no limit on the number of connections, because it is stored based on a linked list, but it also has one drawback: a large number of fd arrays are copied between the user state and the kernel address space as a whole, regardless of whether such replication is intentional or not. Another feature of poll is "horizontal trigger". If the fd is not processed after it is reported, the fd will be reported again the next time poll.

Epoll

Support horizontal trigger and edge trigger, the biggest feature is edge trigger, it only tells the process which fd has just become on demand, and will only be notified once. Using the "event" ready notification method, register the fd through the epoll_ctl, and once the fd is ready, the kernel uses a callback mechanism similar to callback to activate the fd,epoll_wait to receive notifications.

Its advantage is that there is no limit on the maximum concurrent connections: the upper limit of the FD that can be opened is much greater than 1024 (about 100000 ports can be monitored on 1G memory). The efficiency of the non-polling method will not decrease as the number of FD increases; only the active FD will call the callback function, that is, the biggest advantage of epoll is that it only manages "active" connections and has nothing to do with the total number of connections. Using the memory copy method, the mmap () file maps memory to accelerate messaging with kernel space; that is, epoll uses mmap to reduce replication overhead.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report