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 > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Introduction
The kernel of Linux operates all external devices as a file (everything is a file). Reading and writing to a file calls system commands provided by the kernel and returns a file descriptor (fd, file descriptor). There is also a descriptor that responds to the reading and writing of a socket, called socket fd (socket file descriptor), which is a number that points to a structure in the kernel (file path, data area, and so on).
According to the classification of Imax O models by UNIX network programming, UNIX provides five Imax O models.
1.1. Blocking Imax O model
The most commonly used Imax O model, by default, all file operations are blocked.
For example, the socket interface under the Icano model: recvfrom is called in the process space, and the system call does not return until the packet arrives and is copied into the buffer of the application process or when an error occurs, waiting during this period.
The process is blocked for the entire period from the start of the call to recvfrom until it returns, so it is called blocking Icano model.
The figure shows:
1.2. Non-blocking Istroke O model
When recvfrom goes from the application layer to the kernel, it returns an EWOULDBLOCK error directly, which is generally polled to check the status of the non-blocking I-map O model to see if any data has arrived in the kernel.
The figure shows:
1.3. I use O reuse model.
Linux provides select/poll, and processes block select operations by passing one or more fd to select or poll system calls, so that select/poll can help us detect whether multiple fd are ready.
Select/poll is a sequential scan of whether the fd is ready, and the number of fd supported is limited, so its use is subject to some restrictions.
Linux also provides an epoll system call, and epoll uses an event-driven approach instead of sequential scanning, resulting in higher performance. When fd is ready, call back the function rollback immediately.
The figure shows:
1.4. Signal-driven Istroke O model
First of all, turn on the socket signal-driven Ithumb O function, and execute a signal processing function through the system call sigaction (this system call returns immediately, the process continues to work, non-blocking). When the data is ready, it generates a SIGIO signal for the modification process, informs the application through the signal callback to call recvfrom to read the data, and informs the main loop function to process the setting.
The figure shows:
1.5, Asynchronous Ihamo
Tells the kernel to start an operation and tells the kernel to notify the process after the entire operation is complete (including data replication).
The signal-driven Ipicuro model informs when an Ipicuro operation can be started, and the asynchronous Icancano model has a kernel to tell when the Ipicuro operation has been completed.
The figure shows:
2. Icano multiplexing technology.
When multiple client access requests need to be processed in Icano programming, multithreading or Icano multiplexing technology can be used to process them.
As previously introduced, Ihammer O multiplexing enables the system to process multiple client requests at the same time in a single thread by multiplexing the blocking of multiple Icano onto the blocking of the same select.
Compared with the traditional multithreading model, the biggest advantage of Icano multiplexing is that the system overhead is small, the system does not need to create new additional threads, and does not need to maintain the operation of these threads, which reduces the maintenance workload of the system and saves system resources.
Main application scenarios:
The server needs to process multiple sockets in the listening state or connection state at the same time. The server needs to handle sockets for multiple network protocols at the same time.
Select, pselect, poll, and epoll are the main system calls that support Icano multiplexing.
Currently, epoll is recommended. The advantages are as follows:
There are no restrictions on the socket fd that can be opened by a process. The efficiency of fd O does not decrease linearly with the increase of the number of PUBG. Use mmap to accelerate messaging between the kernel and user space. Epoll has a simpler API.
3. Network IO programming in Java
If you just do Java development, you just need to understand the above, and you don't have to dig into it (casually).
There has been a special introduction to the article: summary of Java network IO programming (BIO, NIO, AIO all contain complete example codes)
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.