In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to understand UNIX's network IGUP O model". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand UNIX's network Imax O model".
UNIX's network iDUBO model:
Concept:
1) when the linux kernel reads and writes a file, it will call the system command provided by the kernel and return a file descriptor (file discriptor, referred to as fd).
A descriptor is a number that points to a structure in the kernel that contains information such as the file path. Eg: reading and writing to socket returns a descriptor socketfd
2) A read operation of complex Ibank O will include the following two stages: 1) waiting for data to be ready; 2) data is copied from the kernel to user space (that is, user process).
1) blocking Icano model: blocking Icano
Concept: when a user process reads data from a blocked socket, it returns only when the packet reaches the receive cache of the socket and the data is copied to the buffer area of the process space or when an error occurs, during which time the process blocks waiting.
Description: by default, all file operations are blocked.
Disadvantages: when the concurrent access volume of the client is relatively high, the server needs to create a large number of threads to respond to requests. When the number of threads expands, the performance of the system will decline sharply or even downtime.
Pseudo-out-of-step Imax O model:
Concept: to solve the problem of creating a thread for each request in the blocking Istroke O model, the server can use a thread pool to implement a pseudo-asynchronous Ihop O model.
The cascade failure that may be caused by pseudo-asynchronous Icano model: a server failure causes slow response-> thread reads response from failed service node-> all threads are blocked by failed node, subsequent IO messages are in queue-> queue full-> new client request is rejected and server does not respond.
2) non-blocking Imax O model: nonblocking Imax O
Concept: when a user process reads data from a non-blocking socket, if there is no data in the receive cache of the socket, the kernel will directly return an error.
Note: generally, when socket is set to non-blocking state, the user process will poll the kernel (eg: call the recvfrom function in a loop) until the kernel returns data, which will cause a lot of cpu resources to be occupied.
3) I multiplexing O reuse model: I do O reuse model.
Concept: register multiple fd to be monitored in the selector. When registering, you need to specify the events to be listened to on the fd. The selector will always listen to the registered fd. When an event occurs on the fd, the selector will handle it accordingly.
Description:
Compared with the blocking I _ peg O model, the I _ peg O reuse model blocks on select calls (or poll calls, or epoll calls), rather than on the real Imax O operation. Note: blocking is directed at the initiator.
Get the status of fd: the kernel notifies user space of fd information.
Horizontal trigger: if the ready fd is not processed by the user process, the fd will still be returned on the next query.
Edge trigger: regardless of whether the ready fd is processed by the user process or not, the fd will not be returned on the next query.
Advantages:
The connection operation initiated by the client is asynchronous, so a single thread can process IO requests from multiple clients at the same time. The system does not need to create a thread for each client request, which greatly reduces the overhead of the system
Disadvantages:
Select call:
Concept: the selector is implemented by the select function.
Monitoring mechanism:
Poll the registered fd and process it accordingly according to the status of the fd:
Read ready-> read data and delete the read ready event
Write ready state-> write data and delete the write ready event
Receive (accept) ready state-> register a new read ready event and delete the receive ready event
...
Get the status of the fd: the kernel copies the information of all listening fd into user space as a whole.
Trigger mode: horizontal trigger.
Pros: compared with the non-blocking Iplink O mode, select calls do not require the client to keep making requests.
Disadvantages:
The number of fd that can be opened by a single process is limited, with a default of 1024. If you want to change this default value, you need to recompile the kernel.
Each select call linearly scans all listening fd (that is, select checks its status regardless of whether the fd is ready or not), and the fd efficiency decreases linearly when the number of listening fd is large.
Poll call:
Concept: the selector is implemented by the poll function.
Listening mechanism: same as select call.
Trigger mode: horizontal trigger.
Advantages:
There is no limit to the number of fd that a single process can open.
Disadvantages:
Scan all monitored fd linearly, and when the number of monitored fd is relatively large, the efficiency of Ifd O decreases linearly.
Epoll call:
Concept: selector is implemented by a series of epoll_ functions.
Monitoring mechanism:
When fd is ready, fd calls back the rollback function immediately. Fd that is not ready will not call back the rollback function.
Get the status of fd: using memory mapping, there is no need to copy fd information from the kernel to user space.
Trigger method: horizontal trigger is the default, and edge trigger is supported.
Advantages:
There is no limit to the number of fd that a single process can open. (only limited by the maximum number of file handles of the operating system, the maximum number of file handles in 1g memory is about 10w)
Because epoll uses a callback function rather than a linear scan, the efficiency of fd O does not decrease linearly with the increase of the number of iUnix.
The use of memory mapping avoids the overhead of memory replication and accelerates the message delivery between the kernel and user space.
Disadvantages:
When the number of connections is small and the connections are very active, the performance of epoll may be worse than that of select and poll. After all, the notification mechanism of epoll requires a lot of function callbacks.
4) signal-driven Istroke O model: SIGIO
Turn on the socket signal-driven IO function, and execute a signal processing function through the sigaction system call. When the Datagram is ready, the kernel generates a SIGIO signal for the process. After the user process receives this signal, it can start the SIGIO O operation.
The system call returns immediately, and the user process is not blocked while waiting for the Datagram to arrive.
Note: the signal-driven Ithumb O model uses fewer scenarios.
5) Asynchronous IO O model: asynchronous IO function defined by POSIX
The asynchronous IO function is called to have the kernel notify the user process after the entire Imax O operation (including copying data from the kernel to the user's own buffer) is complete.
The system call returns immediately, and the user process is not blocked while waiting for the Imap O operation.
Note: synchronous / asynchronous is for the executor.
Thank you for your reading, the above is the content of "how to understand UNIX's network Ipaw O model". After the study of this article, I believe you have a deeper understanding of how to understand UNIX's network Ipaw O model, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.