A high-concurrency network connection load balancing method based on operating system
By setting up IP-CPU binding relationships and global hash tables in domestic operating systems, the problem of unconscious load distribution is solved, accurate load scheduling and resource balancing in high-concurrency network connections are achieved, and system stability and reliability are improved.
Patent Information
- Application Number
- CN202510899115.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-01
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2045-07-01
AI Technical Summary
Domestic operating systems have unconscious load distribution and are unable to achieve more fine-grained load division in high-concurrency network connections, resulting in uncontrollable latency and unbalanced resource utilization.
Through the interaction between the application layer and the kernel layer, the user layer interface sets the IP-CPU binding relationship. The kernel layer maintains a global hash table to store the binding information of IP and CPU, and accurately allocates CPU cores according to the hash table during message processing.
It achieves precise load scheduling and resource balancing, reduces CPU overload, improves system stability and reliability in high-concurrency environments, and allows flexible adjustments to meet different business needs.
Smart Images

Figure CN120407205B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of load balancing, and in particular to a high-concurrency network connection load balancing method based on an operating system. Background Art
[0002] With the efforts of researchers and the expansion of market opportunities, domestic operating systems have gradually grown and matured. While achieving progress and breakthroughs, domestic operating systems still face numerous development challenges and bottlenecks. Currently, mainstream desktop distributions generally use RPS and RFS as load balancing technologies. These technologies use a hash algorithm to randomly distribute network packets to a single CPU in a multi-core CPU for processing, achieving load balancing. This is as follows:
[0003] The load balancing strategies of domestic operating systems are mainly divided into hardware and software:
[0004] (1) Software-based RPS / RFS: Relying on five-tuple hashing to randomly distribute messages, it is impossible to perform targeted optimization for critical business IPs (such as high-frequency trading and video streaming), resulting in uncontrollable latency.
[0005] (2) Hardware-based NIC RSS: The NIC hardware distributes traffic to multiple queues based on the received message's quadruple (the calculation method can be specified). Although this method can specify a hashing strategy, it still cannot bind the receiving queue to a specific IP address.
[0006] However, traditional load balancing strategies are opaque to users, preventing them from manually configuring the mapping between CPU cores and traffic. Traditional hash table-based load balancing methods suffer from "unintentional" allocation in highly concurrent network connections and lack fine-grained CPU core load allocation in complex traffic scenarios with complex priorities. Summary of the Invention
[0007] In order to overcome the above defects, the present invention proposes a high-concurrency network connection load balancing method based on an operating system to solve the problems of unconscious allocation in load balancing and the inability to divide loads in a finer granularity.
[0008] The present invention provides a high-concurrency network connection load balancing method based on an operating system, comprising the following steps:
[0009] Control the application layer to submit an IP-CPU binding request, and pass the binding request from the application layer to the kernel layer through the kernel interface; the binding information of the binding request includes the target IP address and the target CPU core;
[0010] When the kernel layer receives the binding request, it stores the binding information in a global hash table; wherein the key of the global hash table is the hash value of the target IP address, and the value of the global hash table is the target CPU core;
[0011] Receive a network message request, and parse the request IP address of the network message request; determine the request CPU core corresponding to the hash value of the request IP address through the global hash table, and the request CPU core is the CPU core that processes the network message request.
[0012] A further improvement of the present invention is that, before storing the binding information in the global hash table, the method further comprises:
[0013] Search the global hash table to see if there is a node with the hash value of the target IP address as the key;
[0014] If it exists, update the node with the hash value of the target IP address as the key, using the target CPU core as the value;
[0015] If it does not exist, the hash value of the target IP address is used as the key and the target CPU core is used as the value and stored in the hash table.
[0016] A further improvement of the present invention is that the hash value of the target IP address is obtained by calling the jhash() kernel interface with the target IP address as a parameter.
[0017] A further improvement of the present invention is that the request IP address for parsing the network message request is specifically:
[0018] Extract the header information of the network message request, and use the header information as a parameter to call the netfi_receive_skb_internal() kernel interface to obtain it.
[0019] A further improvement of the present invention is that determining the requesting CPU core corresponding to the hash value of the requesting IP address through the global hash table includes:
[0020] When there is a node with the hash value of the requested IP address as the key in the global hash table, the target CPU corresponding to the node with the hash value of the requested IP address as the corresponding requesting CPU core is obtained, and the network message request is distributed to the receiving queue of the requesting CPU core.
[0021] A further improvement of the present invention is that, when there is no node with the hash value of the requested IP address as a key in the global hash table, the network message request is distributed to a receiving queue of a CPU core that meets preset conditions.
[0022] A further improvement of the present invention is that, when the network message request fails to be distributed to the receiving queue of the requesting CPU core, the network message request is distributed to the receiving queue of the CPU core that meets the preset conditions.
[0023] Beneficial effects of the present invention:
[0024] Through IP-CPU binding, CPUs can be assigned based on IP addresses, achieving precise load scheduling and balanced resource utilization. This reduces overload on individual CPUs, reduces the risk of system failures due to uneven loads, and improves system stability and reliability in high-concurrency environments. In situations where priorities are complex, network traffic can be divided more finely based on IP addresses, replacing the traditional process-based processing of network packets. This allows for more targeted and adaptable processing of network traffic details. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0026] Figure 1 is a logical architecture diagram of an embodiment of the present invention;
[0027] Figure 2 FIG. 4 is another logical architecture diagram of an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to have a further understanding of the technical solution and beneficial effects of the present invention, the technical solution and beneficial effects of the present invention are described in detail below with reference to the accompanying drawings.
[0029] Definitions of Abbreviations and Key Terms:
[0030] RPS (Receive Packet Steering): A Linux kernel mechanism that distributes network packets to multiple CPU cores for processing using a hash algorithm to achieve load balancing.
[0031] RFS (Receive Flow Steering): Based on the RPS extension, it optimizes CPU affinity by tracking the flow processing location. However, it takes effect only after the first packet is processed.
[0032] RSS (receive side scaling): Receive side scaling. The network card hardware distributes traffic to multiple queues on the network card based on the four-tuple of the received message (the calculation method can be specified).
[0033] CPU core: When Linux manages multiple CPU cores, it uses physical numbers to distinguish different CPUs. The numbers are CPU cores, also called CPU logical numbers.
[0034] Socket: It is an intermediate software abstraction layer for communication between the application layer and the TCP / IP protocol suite in Linux. Socket provides a set of interfaces that allow applications to communicate over the network.
[0035] Please combine Figure 1 and Figure 2 As shown, the present invention is completed through the interaction between the application layer and the kernel layer. The application layer is responsible for initiating requests, and the kernel layer receives and processes the requests.
[0036] In this example, the Kylin V10 version is installed on a domestically produced D2000 processor. By specifying the IP-CPU binding relationship through a user-layer interface, this allows for precise and targeted delivery of packets to specific IP addresses, meeting the personalized computing resource requirements of different services. For example, service IP addresses requiring high computing performance can be bound to a higher-performance CPU, improving service processing efficiency.
[0037] The details are as follows:
[0038] S1, the user layer or application layer (also called application) sets the binding relationship between the destination IP address and the destination CPU core through the upper interface, and calls the socket interface to complete the setting (that is, the corresponding Figure 1 (1) Call the interface to set the binding relationship between IP and CPU, and Figure 2 The socket interface example is as follows:
[0039] setsockopt(fd,SOL_SOCKET,SO_CPU_BIND,&bind_info,sizeof(bind_info));
[0040] The meanings of the parameters in the interface are as follows:
[0041] fd: indicates the socket handle to be set;
[0042] SOL_SOCKET: indicates that the socket option needs to be set;
[0043] SO_CPU_BIND: This embodiment defines a new macro to set the IP-CPU binding relationship of the socket;
[0044] bind_info: indicates the binding information that the application layer wants to pass to the kernel layer. The kernel layer builds the IP-CPU hash table based on this information. The bind_info definition structure is as follows:
[0045] struct ip_cpu_bind {
[0046] char ip_addr[INET_ADDRSTRLEN]; / / target IP address
[0047] int cpu_id; / / Target CPU core, that is, the bound CPU logical core number (0-based)
[0048] };
[0049] After the call is completed, the target IP address in the bind_info passed by the application layer will be bound to the target CPU core.
[0050] S2, after receiving the binding request passed by the application layer, the kernel layer calls the jhash() kernel interface to calculate the hash value corresponding to the target IP address of the binding information in the binding request, and uses the hash value as the subscript of the global hash table ip_cpu_bind_table, that is, the key of the global hash table. Before storing the target CPU core as the value in the global hash table, the kernel layer checks whether there is a node with the hash value of the target IP address as the key; if so, the kernel layer updates the node with the hash value of the target IP address as the key with the target CPU core as the value; if not, the kernel layer updates the node with the hash value of the target IP address as the key with the target CPU core as the value (that is, the corresponding Figure 1 (2) in the above example stores the IP address in a hash table, where the entry is the CPU number, and Figure 2 jhash() in Calculate the IP hash value and maintain the global hash table ip_cpu_bind_table). The final structure is:
[0051] ip_cpu_bind_table[hash value of target IP address] = target CPU core.
[0052] S3, when the network interface card receives a network message from an external request, the hardware device interrupt triggers the kernel layer network protocol stack processing flow. The network message request is first parsed by the driver layer, extracting the second and third layer header information, calling the netfi_receive_skb_internal() interface in the kernel layer, parsing the request IP address of the network message request, and calling the jhash() interface to calculate the hash value of the request IP address. The hash value is used to query the global hash table to obtain the request CPU core (corresponding to the hash value of the request IP address) bound to the request IP address. Figure 1 (3) in the query CPU number according to the destination IP in the message, where the destination IP in the message refers to the requesting IP address; and Figure 2 netfi_receive_skb_internal() in the parse method resolves the destination IP address, and jhash() calculates the hash value.
[0053] When there is a node with the hash value of the request IP address as the key in the global hash table, get the target CPU core corresponding to the node with the hash value corresponding to the request IP address as the requesting CPU core, call the enqueue_to_backlog() interface to distribute the network message request to the receiving queue of the requesting CPU core (corresponding to Figure 1 (4) puts the data packet into the corresponding CPU's receive queue, and Figure 2 The global hash table is queried in, and enqueue_to_backlog() sends the message to the corresponding CPU receive queue). After that, network messages with the same request IP address will be sent to this CPU. enqueue_to_backlog() is an existing interface in the kernel layer. The interface example is as follows:
[0054] enqueue_to_backlog(skb, cpu);
[0055] The meanings of the parameters in the interface are as follows:
[0056] skb: indicates the received sk_buff message, that is, the network message;
[0057] cpu: indicates the corresponding cpu number in the ip_cpu_bind_table global table, that is, the requested CPU core;
[0058] It should be noted that when the enqueue_to_backlog() interface returns a value of 1, it means that the network message has failed to be added to the receiving queue of the requesting CPU core, indicating that the receiving queue of the requesting CPU core is full. In this case, the Linux default processing principle is followed and the message is distributed to the CPU core that meets the preset conditions for processing. The CPU core that meets the preset conditions can be the local CPU core (corresponding to Figure 1 (5) in the current CPU receive queue).
[0059] In another case of this embodiment, when there is no node with the hash value of the requested IP address as the key in the global hash table, in this case, the Linux default processing principle is followed and the system is distributed to a CPU core that meets the preset conditions for processing. The CPU core that meets the preset conditions can be a local CPU core.
[0060] The beneficial effects of the present invention are as follows:
[0061] By setting up a dedicated interface at the user layer / application layer, the user layer / application layer is allowed to actively specify the correspondence between the target IP address and the target CPU core, thereby achieving active control of load distribution.
[0062] A global hash table is used to store the binding information between IP and CPU. The global hash table is queried during the message processing process, and the requested CPU core for message forwarding is determined based on the query result, achieving accurate directional message sending.
[0063] Designed to address the unique characteristics of domestic operating systems, this approach offers excellent compatibility and leverages their strengths. Furthermore, the user-layer / application-layer interface design makes this method highly scalable. The user-layer / application-layer interface allows for flexible adjustment of IP and CPU binding strategies based on diverse business needs, adapting to evolving network application scenarios.
[0064] Precise load scheduling and balanced resource utilization reduce overload on individual CPUs, lower the risk of system failures due to uneven load, and improve system stability and reliability in high-concurrency environments. In complex priority scenarios, such as when resources need to be allocated to multiple IP addresses, network traffic is no longer processed on a per-process basis. Instead, network traffic is divided more finely by IP address, fully leveraging policy customization.
[0065] Although the present invention has been described using the above preferred embodiments, they are not intended to limit the scope of protection of the present invention. Any person skilled in the art may make various changes and modifications to the above embodiments without departing from the spirit and scope of the present invention. These changes and modifications are still within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be based on the definition of the claims.
Claims
1. A high-concurrency network connection load balancing method based on an operating system, characterized in that: include: Control the application layer to submit an IP-CPU binding request, and pass the binding request from the application layer to the kernel layer through the kernel interface; The binding information of the binding request includes the target IP address and the target CPU core; When the kernel layer receives the binding request, it stores the binding information in a global hash table; wherein the key of the global hash table is the hash value of the target IP address, and the value of the global hash table is the target CPU core; Receive a network message request, and parse the request IP address of the network message request; determine the request CPU core corresponding to the hash value of the request IP address through the global hash table, the request CPU core being the CPU core that processes the network message request; Before storing the binding information into the global hash table, the method further includes: Search the global hash table to see if there is a node with the hash value of the target IP address as the key; If it exists, update the node with the hash value of the target IP address as the key, using the target CPU core as the value; If it does not exist, the hash value of the target IP address is used as the key and the target CPU core is used as the value and stored in the hash table.
2. The method for high-concurrency network connection load balancing based on an operating system according to claim 1, wherein: The hash value of the target IP address is obtained by calling the jhash() kernel interface with the target IP address as a parameter.
3. The method for high-concurrency network connection load balancing based on an operating system according to claim 1, wherein: The specific IP address of the network message request is: Extract the header information of the network message request, and use the header information as a parameter to call the netfi_receive_skb_internal() kernel interface to obtain it.
4. The method for high-concurrency network connection load balancing based on an operating system according to claim 1, wherein: Determining the requested CPU core corresponding to the hash value of the request IP address through the global hash table includes: When there is a node with the hash value of the requested IP address as the key in the global hash table, the target CPU corresponding to the node with the hash value of the requested IP address as the corresponding requesting CPU core is obtained, and the network message request is distributed to the receiving queue of the requesting CPU core.
5. The method for high-concurrency network connection load balancing based on an operating system according to claim 4, characterized in that: When there is no node with the hash value of the requested IP address as the key in the global hash table, the network message request is distributed to the receiving queue of the CPU core that meets the preset conditions.
6. The method for high-concurrency network connection load balancing based on an operating system according to claim 4, characterized in that: When the network message request fails to be distributed to the receiving queue of the requesting CPU core, the network message request is distributed to the receiving queue of the CPU core that meets the preset conditions.
Citation Information
Patent Citations
Message sending and receiving methods and devices and network equipment
CN107547508A