Application load balancing method, device and equipment
Through the message sending and receiving layer of the proxy server, directly interacting with the physical network card, combined with the load balancing mechanism of the first and second communication endpoints, the problem that the load balancer performance is limited by the kernel protocol stack is solved, and the communication efficiency between applications is improved.
Patent Information
- Application Number
- CN202411388990.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-02-18
AI Technical Summary
The performance of the load balancer is limited by the kernel protocol stack, resulting in inefficient communication between applications.
Through the message sending and receiving layer of the proxy server, data interaction is directly performed with the physical network card, avoiding copying request messages from the kernel state to the user state, thereby improving the efficiency of request messages. At the same time, a connection is created between the client and the target server through the first communication endpoint and the second communication endpoint, load balancing is achieved, and the use of traditional kernel protocol stacks is avoided.
It improves the communication efficiency between the client and the target server, and solves the problem of low communication efficiency caused by the performance of load balancer due to the kernel protocol stack limitation.
Smart Images

Figure CN119484533A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an application load balancing method, device and equipment. Background Art
[0002] Load balancing is a computer technology used to distribute the workload of a network or application to multiple resources, such as servers or disk drives, to improve the communication efficiency between networks or applications. Load balancing can be performed at different network layers. For example, application load balancing can run at the seventh layer (i.e., application layer) of the OSI (Open Systems Interconnection) network model. In the seventh layer, the load balancer can make balancing decisions and route allocations based on application layer information such as HTTP (HyperText Transfer Protocol) headers, HTTPS (Hypertext Transfer Protocol Secure) headers, SSL (Secure Sockets Layer) session identifiers, SSL certificates, FTP (File Transfer Protocol), and DNS (Domain Name System) queries.
[0003] In the prior art, taking the Nginx (Engine-X, a proxy server) load balancer running on the seventh layer as an example, the load balancer can receive a TCP (Transmission Control Protocol) connection from a client by interacting with the kernel protocol stack through a system call, and then the Nginx load balancer will parse the TCP connection to obtain the data required by the application layer, such as HTTP request data, and then the Nginx load balancer will make a load balancing decision according to a preset rule, for example, distribute the TCP connection to different target servers according to the URL (Uniform Resource Locator) of the HTTP request, and then the Nginx load balancer will send the processed TCP connection to the kernel protocol stack through a system call, and then send the processed TCP connection to the target server through the kernel protocol stack, thereby achieving load balancing between the client and the target server. However, since the performance of the load balancer is limited by the kernel protocol stack, and the TCP connection data needs to be copied from the kernel state to the user state, the sending and receiving speed of the TCP connection data is slow, and the communication efficiency between applications is low. Technical problems.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The present application provides an application load balancing method, apparatus and device to at least solve the technical problem of low communication efficiency between applications due to the limitation of the load balancer performance by the kernel protocol stack.
[0006] According to one aspect of the present application, an application load balancing method is provided, comprising: parsing a request message from a client through a message transceiver layer of the proxy server to obtain first data, wherein the message transceiver layer is at least used to directly interact with a physical network card of the proxy server; transmitting the first data to a first communication endpoint in the proxy layer of the proxy server, and after the proxy layer of the proxy server parses the first data received by the first communication endpoint into second data, processing the second data into target data to send to the load balancing layer of the proxy server, wherein the first communication endpoint is at least used to create a first connection, which is a connection between the client and the proxy server; determining a second communication endpoint through the proxy layer of the proxy server according to a load balancing result returned by the load balancing layer based on the target data, wherein the second communication endpoint is at least used to create a second connection, which is a connection between the proxy server and the target server, and the proxy layer of the proxy server includes the second communication endpoint; sending the second data to the target server through the second communication endpoint.
[0007] Optionally, before parsing the request message from the client through the message transceiver layer of the proxy server to obtain the first data, the application load balancing method also includes: receiving the request message from the client through the receiving queue of the physical network card as the first queue; and copying the request message in the first queue to the memory of the user state process through the message transceiver layer.
[0008] Optionally, the proxy layer of the proxy server includes a first proxy layer and a second proxy layer, the first proxy layer includes a first communication endpoint and a second communication endpoint, the first data is data in a TCP message format, and the application load balancing method also includes: creating a first communication endpoint through the first proxy layer; transmitting the first data to a second queue, wherein the second queue is a receiving queue of the first communication endpoint; performing TCP parsing on the first data in the second queue through the first proxy layer to obtain third data; transmitting the third data to the second proxy layer, and performing HTTP parsing on the third data through the second proxy layer to obtain second data, wherein the second proxy layer is an upper layer of the first proxy layer.
[0009] Optionally, the application load balancing method also includes: determining target parameters based on second data, wherein the target parameters include at least a request header, a request line, a request method, and a uniform resource identifier; transmitting the target parameters to a load balancer, wherein the load balancer is used to determine a second communication endpoint based on the target parameters; and creating a target proxy connection through a second proxy layer, wherein the target proxy connection is used to characterize the association relationship between the first communication endpoint and the second communication endpoint.
[0010] Optionally, the application load balancing method also includes: detecting a first connection type and a second connection type, wherein the first connection type is a connection type of the first communication endpoint, the second connection type is a connection type of the second communication endpoint, and the connection types include long connections and short connections; when both the first connection type and the second connection type are long connections, prohibiting the proxy server from sending target messages to the client and the target server, wherein the target message is used to close the first connection and / or the second connection; when both the first connection type and the second connection type are short connections, prohibiting the proxy server from sending target messages to the target server, and allowing the proxy server to send target messages to the client; when the first connection type is a long connection and the second connection type is a short connection, prohibiting the proxy server from sending target messages to the client, and allowing the proxy server to send target messages to the target server.
[0011] Optionally, the request state corresponding to the first communication endpoint is any one of a first request state, a second request state, a third request state and a fourth request state, wherein the first request state is used to characterize that the first communication endpoint is waiting for the establishment of a first connection; the second request state is used to characterize that the first communication endpoint receives complete message data that needs to be parsed by the proxy layer through the created first connection; the third request state is used to characterize that the first communication endpoint sends the message data parsed by the proxy layer to the second communication endpoint; and the fourth request state is used to characterize that the first communication endpoint is waiting to receive reply data from the second communication endpoint.
[0012] Optionally, the response state corresponding to the second communication endpoint is any one of a first response state, a second response state, a third response state, a fourth response state and a fifth response state, wherein the first response state is used to characterize that the second communication endpoint is in an idle state; the second response state is used to characterize that the second communication endpoint is waiting for the creation of a second connection; the third response state is used to characterize that the second communication endpoint receives complete message data that needs to be parsed by the proxy layer through the created second connection; the fourth response state is used to characterize that the second communication endpoint sends the message data parsed by the proxy layer to the first communication endpoint; and the fifth response state is used to characterize that the second communication endpoint deactivates the second connection.
[0013] Optionally, after detecting the first connection type and the second connection type, the application load balancing method also includes: when the first connection type is a short connection and the client actively closes the first connection, switching the response state corresponding to the second communication endpoint to the first response state; after switching the response state corresponding to the second communication endpoint to the first response state, storing the second connection in a preset cache pool; when the client re-initiates a connection to the target server, selecting a second connection corresponding to a target server from the preset cache pool, and re-enabling the second connection.
[0014] Optionally, the application load balancing method also includes: performing HTTP parsing on the third data through the second proxy layer to obtain request header data corresponding to the third data; storing the request header data in a preset memory of the second proxy layer, wherein the space size of the preset memory is dynamically allocated according to the data amount of the request header data; detecting whether the request header data stored in the preset memory is in a complete state, wherein the complete state represents that the request header data corresponds to a complete HTTP transaction; if the request header data stored in the preset memory is not in a complete state, storing the request header data corresponding to the next third data in the memory, wherein the next third data is new third data obtained by parsing the first proxy layer.
[0015] According to another aspect of the present application, an application load balancing device is also provided, including: a first parsing unit, used to parse a request message from a client through a message transceiver layer of a proxy server to obtain first data, wherein the message transceiver layer is at least used to directly interact with a physical network card of the proxy server; a first transmission unit, used to transmit the first data to a first communication endpoint in the proxy layer of the proxy server, and after the proxy layer of the proxy server parses the first data received by the first communication endpoint into second data, the second data is processed into target data to send to the load balancing layer of the proxy server, wherein the first communication endpoint is at least used to create a first connection, which is a connection between the client and the proxy server; a first determination unit, used to determine a second communication endpoint through the proxy layer of the proxy server according to a load balancing result returned by the load balancing layer based on the target data, wherein the second communication endpoint is at least used to create a second connection, which is a connection between the proxy server and the target server, and the proxy layer of the proxy server includes the second communication endpoint; a transmission unit, used to send the second data to the target server through the second communication endpoint.
[0016] According to another aspect of the present application, a computer program product is provided, in which a computer program is stored, wherein when the computer program is running, the computer program product is controlled to execute any one of the above-mentioned application load balancing methods.
[0017] According to another aspect of the present application, an electronic device is also provided, wherein the electronic device includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement any one of the above-mentioned application load balancing methods.
[0018] In the present application, the request message from the client is first parsed by the message transceiver layer of the proxy server to obtain the first data, wherein the message transceiver layer is at least used to directly interact with the physical network card of the proxy server. After that, the present application transmits the first data to the first communication endpoint, wherein the first communication endpoint is at least used to create a first connection, the first connection is a connection between the client and the proxy server, and the proxy layer of the proxy server includes the first communication endpoint. Then, the present application determines the second communication endpoint based on the target data corresponding to the first data, wherein the target data is the data obtained by parsing the first data, the second communication endpoint is at least used to create a second connection, the second connection is a connection between the proxy server and the target server, and the proxy layer of the proxy server includes the second communication endpoint. Finally, the present application implements load balancing between the client and the target server based on the first communication endpoint and the second communication endpoint.
[0019] From the above content, it can be seen that the present application directly interacts with the physical network card through the message transceiver layer to achieve the purpose of obtaining network messages (i.e., request messages from the client). The present application obtains network messages directly from the physical network card, thereby avoiding the operation steps in the prior art of copying the request message from the kernel state of the system to the user state, thereby improving the efficiency of obtaining the request message.
[0020] Furthermore, the present application creates a connection between a client and a proxy server through a first communication endpoint, and after the proxy layer of the proxy server parses the first data received by the first communication endpoint into second data, processes the second data into target data to send to the load balancing layer of the proxy server, and determines the second communication endpoint through the proxy layer of the proxy server according to the load balancing result returned by the load balancing layer based on the target data, and creates a connection between the proxy server and the target server through the second communication endpoint, thereby achieving the purpose of load balancing the communication between the client and the target server through the first communication endpoint and the second communication endpoint. The technical solution of the present application does not use the traditional kernel protocol stack, thereby avoiding causing the performance of the load balancer to be limited by the kernel protocol stack, thereby improving the communication efficiency between the client and the target server.
[0021] It can be seen that the present application achieves the purpose of improving the efficiency of obtaining request messages by directly interacting with the physical network card through the message transceiver layer. In addition, the present application load balances the communication between the client and the target server through the first communication endpoint and the second communication endpoint, thereby achieving the technical effect of improving the communication efficiency between the client and the target server, thereby solving the technical problem of low communication efficiency between applications caused by the limitation of the load balancer performance by the kernel protocol stack. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0023] Figure 1 is a flow chart of an optional application load balancing method according to an embodiment of the present application;
[0024] Figure 2 is a schematic diagram of an optional association state of a proxy connection according to an embodiment of the present application;
[0025] Figure 3 is a schematic diagram of an optional proxy server according to an embodiment of the present application;
[0026] Figure 4 is a flowchart of an optional HTTP transaction state migration process according to an embodiment of the present application;
[0027] Figure 5 is a flowchart of an optional process of parsing multiple HTTP messages according to an embodiment of the present application;
[0028] Figure 6is a schematic diagram of an optional application load balancing device according to an embodiment of the present application;
[0029] Figure 7 is a schematic diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0032] It should also be noted that the relevant information (including but not limited to information for display and analysis) and data (including but not limited to network message data) involved in this application are all information and data authorized by the user or fully authorized by all parties. For example, an interface is set between this system and the relevant user or organization. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or organization.
[0033] In addition, the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant information and data involved in this application comply with the relevant laws, regulations and standards of the relevant regions, and necessary confidentiality measures have been taken and do not violate public order and good morals. In addition, this application provides corresponding operation entrances for users to choose to agree to authorization or refuse authorization. If the user chooses to refuse authorization, he / she will enter the corresponding expert decision-making process.
[0034] According to an embodiment of the present application, an embodiment of an application load balancing method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0035] In an optional embodiment, Figure 1 is a flow chart of an optional application load balancing method according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0036] Step S101: parse a request message from a client through a message transceiver layer of a proxy server to obtain first data.
[0037] In step S101, the message transceiver layer is at least used to directly interact with the physical network card of the proxy server.
[0038] The method provided in the embodiment of the present application can be applied to a proxy server (or a load balancing device or a load balancing system). The method can be applied to various types of seven-layer application load balancing technologies, including hardware application load balancing devices or application delivery devices, seven-layer application load balancing gateways of virtualized clusters, etc., and can also be applied to various network proxy devices to realize application load balancing functions.
[0039] Optionally, the hierarchical structure of the proxy server may include a message sending and receiving layer, a proxy layer and a load balancing layer, wherein the proxy layer includes a first proxy layer (e.g., a TCP proxy layer) and a second proxy layer (e.g., an HTTP proxy layer), and the first proxy layer includes a first communication endpoint and a second communication endpoint.
[0040] Optionally, the message transceiver layer of the proxy server can process the sending and receiving process of network messages, wherein the network message is a request message from the client. The processing process includes: first, the proxy server receives the request message from the client through the physical network card of the proxy server, and puts it into the receiving queue of the physical network card. After that, the proxy server controls the message transceiver layer to directly take out the message from the receiving queue of the physical network card, and copies the taken out message to the memory of the user state process.
[0041] Exemplarily, after the request message of the client is copied to the memory of the user state process, the message transceiver layer may parse the request message stored in the memory of the user state process to obtain the first data in the TCP message format.
[0042] Optionally, after the proxy server parses the network message through the first proxy layer and the second proxy layer to obtain the target data, and the proxy server determines the second communication endpoint based on the target data, the proxy server re-encapsulates the processed target data into a network message. After that, the proxy server returns the network message to the message transceiver layer, and then transmits the network message to the sending queue of the physical network card through the message transceiver layer, thereby achieving the purpose of forwarding the network message from the client to the target server.
[0043] Optionally, the proxy server sends and receives network messages by controlling the message sending and receiving layer, thereby bypassing the kernel protocol stack and directly interacting with the physical network card, thereby avoiding the performance limitations of the kernel protocol stack during the sending and receiving of network messages, thereby improving the sending and receiving efficiency of network messages.
[0044] Step S102, transmitting the first data to the first communication endpoint in the proxy layer of the proxy server, and after the proxy layer of the proxy server parses the first data received by the first communication endpoint into second data, processing the second data into target data to send to the load balancing layer of the proxy server.
[0045] For example, in the proxy layer of the proxy server, the second proxy layer reads the TCP data packet from the first communication endpoint created by the first proxy layer, and parses the HTTP format data as the second data, and then parses the second data into the parameter information required by the upper-layer load balancer and stores it in the data structure to obtain the target data. The target data will be passed to the load balancer to perform load balancing to obtain a load balancing result. The load balancing result is used to indicate the target server selected from multiple servers.
[0046] In this embodiment, the target server is selected from multiple servers by the load balancer according to a preset load balancing decision. Here, the load balancing layer of the proxy server can act as a load balancer.
[0047] In step S102, the first communication endpoint is at least used to create a first connection, the first connection is a connection between a client and a proxy server, and the proxy layer of the proxy server includes the first communication endpoint.
[0048] Optionally, the first communication endpoint is a user-state socket (i.e., a socket, which refers to a software endpoint that can perform network communication) created for the client. Compared with a kernel-state socket, a user-state socket can reduce the number of system calls, thereby improving system performance. In addition, a user-state socket is more flexible in implementation and easier to expand and maintain.
[0049] Optionally, when the client needs to send or receive message data (ie, first data), repeated copying of the message data from kernel state to user state can be avoided through the user state socket, thereby improving the transmission efficiency of the message data.
[0050] Step S103: determining a second communication endpoint through the proxy layer of the proxy server according to the load balancing result returned by the load balancing layer based on the target data.
[0051] In step S103, the target data is data obtained by parsing the first data by the proxy layer of the proxy server, the second communication endpoint is at least used to create a second connection, the second connection is a connection between the proxy server and the target server, and the proxy layer of the proxy server includes the second communication endpoint.
[0052] Exemplarily, the target server is determined according to the load balancing result by the proxy layer of the proxy server, and a second communication endpoint corresponding to the target server is created.
[0053] After determining the target server according to the load balancing result, a second communication endpoint is created through the first proxy layer of the proxy server, a TCP connection is initiated to the corresponding target server, and after the connection with the server side is established, HTTP transaction data (i.e., the second data) is transmitted to the sending queue of the second communication endpoint to be sent to the target server. Optionally, the proxy server can proxy the TCP connection between the client and the target server through the first proxy layer, and associate the first communication endpoint with the second communication endpoint through the second proxy layer.
[0054] Optionally, the proxy server can also control the first proxy layer to perform TCP parsing on the first data, and control the second proxy layer to further perform HTTP parsing on the result obtained by the first proxy layer parsing, so as to obtain the target data.
[0055] Optionally, the second communication endpoint is a user-mode socket created for the target server.
[0056] Step S104: sending the second data obtained by the proxy service layer parsing the first data to the target server through the second communication endpoint.
[0057] The target server is used to receive the message data sent by the second communication endpoint and package the processing result of the message data into a response message, and send the response message to the client through the proxy server.
[0058] Exemplarily, the process of sending the response message to the client through the proxy server may include: after the message transceiver layer of the proxy server receives the response message sent by the target server through the physical network card, the message transceiver layer forwards the response message to the second communication endpoint of the proxy layer, and the parsing result obtained after the message parsing processing of the proxy layer is sent by the first communication endpoint of the proxy layer to the message transceiver layer, and then sent by the message transceiver layer to the client through the physical network card.
[0059] Optionally, Figure 2 is a schematic diagram of an optional association state of a proxy connection according to an embodiment of the present application, such as Figure 2 As shown, the load balancer (i.e. Figure 2 The l7 loadbalance context in the load balancer is used to store the relevant content of the preset load balancing decision. The load balancer is connected to the HTTP proxy in the second proxy layer (i.e. Figure 2 The http proxycontext in the HTTP proxycontext corresponds to the target proxy connection in this application), wherein the second proxy layer communicates with the first communication endpoint (i.e. Figure 2 The client TCP socket in the communication endpoint (i.e. Figure 2 The server tcpsocket in the client associates the TCP connections between the client and the target server.
[0060] Optionally, different HTTP transactions originating from the same client connection can be load balanced to multiple different second communication endpoints, and the TCP connections corresponding to the multiple second communication endpoints of the same client will all be associated with the same HTTP proxy connection and managed uniformly by the HTTP proxy connection.
[0061] Optionally, when the TCP connection on the client side is closed, it will trigger the closing of the TCP connection on the target server side. After all the TCP connections on the target server side are closed, the proxy server deletes the HTTP proxy connection.
[0062] From the above content, it can be seen that the present application directly interacts with the physical network card through the message transceiver layer to achieve the purpose of obtaining network messages (i.e., request messages from the client). The present application obtains network messages directly from the physical network card, thereby avoiding the operation steps in the prior art of copying the request message from the system kernel state to the user state, thereby improving the efficiency of obtaining the request message.
[0063] Furthermore, the present application subsequently creates a connection between the client and the proxy server through the first communication endpoint, and utilizes the proxy layer of the proxy server to parse the first data received by the first communication endpoint into second data, and then processes the second data into target data to send to the load balancing layer of the proxy server, and determines the second communication endpoint through the proxy layer of the proxy server according to the load balancing result returned by the load balancing layer based on the target data, and creates a connection between the proxy server and the target server through the second communication endpoint, thereby achieving the purpose of load balancing the communication between the client and the target server through the first communication endpoint and the second communication endpoint. The technical solution of the present application does not use the traditional kernel protocol stack, thereby avoiding causing the performance of the load balancer to be limited by the kernel protocol stack, thereby improving the communication efficiency between the client and the target server.
[0064] It can be seen that the present application achieves the purpose of improving the efficiency of obtaining request messages by directly interacting with the physical network card through the message transceiver layer. In addition, the present application load balances the communication between the client and the target server through the first communication endpoint and the second communication endpoint, thereby achieving the technical effect of improving the communication efficiency between the client and the target server, thereby solving the technical problem of low communication efficiency between applications caused by the limitation of the load balancer performance by the kernel protocol stack.
[0065] In an optional embodiment, before parsing the request message from the client through the message transceiver layer of the proxy server to obtain the first data, the proxy server receives the request message from the client through the receiving queue of the physical network card as the first queue, and then the proxy server copies the request message in the first queue to the memory of the user state process through the message transceiver layer.
[0066] Optionally, a preset tool is deployed in the message transceiver layer, and the preset tool is used at least to manage the physical network card, wherein the preset tool can be set to DPDK (Data Plane Development Kit, an open source software library and driver collection) or EBPF (Extended Berkeley Packet Filter, a programmable network data packet processing technology), wherein DPDK is used to quickly process data packets on modern processor architectures, and DPDK provides a series of underlying libraries and drivers to achieve the purpose of optimizing the processing capability of data packets, and EBPF provides a mechanism for securely running programs in the kernel, wherein the securely running programs can be used to perform network filtering, performance analysis, and security auditing operations.
[0067] Optionally, the proxy server manages the physical network card through the message receiving and sending layer, thereby bypassing the use of the kernel protocol stack, thereby avoiding the complex operation steps corresponding to the kernel protocol stack, the process switching steps from kernel state to user state, and the copying process of network messages, saving system resources while improving the efficiency of sending and receiving network messages.
[0068] Optionally, Figure 3 is a schematic diagram of an optional proxy server according to an embodiment of the present application, such as Figure 3 As shown, the proxy server includes a message sending and receiving layer, a TCP proxy layer (corresponding to the first proxy layer in this application), an HTTP proxy layer (corresponding to the second proxy layer in this application) and a load balancing layer.
[0069] Message transceiver layer: used to process the sending and receiving process of physical messages.
[0070] The message is sent to the physical network card receiving queue, and the message transceiver layer takes the message data from the physical network card receiving queue, copies it to the user state process memory, parses and identifies the message at the second and third layer networks, and transfers the TCP message to the upper-layer proxy module for processing.
[0071] After the upper-layer proxy module completes the processing, it returns the message to the message transceiver layer, which then forwards the message to the physical network card sending queue to complete the message forwarding.
[0072] The message receiving and sending layer bypasses the kernel protocol stack and directly receives and sends data from the physical network card. The figure uses DPDK[1] as an example to illustrate the implementation of the solution, but other solutions can also be used to bypass the kernel protocol stack to complete message receiving and sending and three-layer network parsing, such as the eBPF method.
[0073] TCP proxy layer: used to proxy the TCP connection between the client and server.
[0074] The TCP proxy layer creates user-mode sockets for the client and server respectively, stores the received TCP messages in the socket receive queue of the corresponding connection, and after the TCP protocol is parsed by this module, the application data is transferred to the upper-level proxy module for processing.
[0075] Similarly, after the upper-layer proxy module completes processing, it returns the application data to the TCP proxy layer, which then encapsulates the TCP message and puts it into the socket sending queue of the corresponding connection, and forwards it to the message transceiver layer for processing.
[0076] The TCP proxy layer supports setting independent behaviors for specific TCP connections by creating user-mode sockets, such as TCP window update mechanism and congestion control. The upper-layer application can also control the associated TCP socket so that its behavior at the TCP layer meets the application requirements.
[0077] HTTP proxy layer: used to parse and process application layer data. This article mainly focuses on the HTTP protocol and describes the proxy process of HTTP connections and the application data parsing process.
[0078] The HTTP proxy layer reads the TCP payload (TCP data packet) from the client socket created by the TCP proxy layer, parses the HTTP format data, parses the HTTP transaction data into the parameter information required by the upper-layer load balancer, stores it in the data structure, and passes it to the load balancer to perform load balancing.
[0079] According to the load balancing result, a server socket is created through the TCP proxy layer, a TCP connection is initiated to the corresponding server, and after the connection with the server side is established, the HTTP transaction data is transmitted to the sending queue of the server socket.
[0080] The HTTP proxy layer associates the client socket of the TCP proxy layer with the server socket. When an HTTP request / response on one side fails or times out, the HTTP proxy layer needs to decide how to handle the TCP connection on the other side. At the same time, the HTTP proxy layer supports HTTP persistent connections.
[0081] Load balancing layer: Load balancing application connection requests based on user-defined rules. The load balancing layer supports seven-layer application data recognition. Based on the application data parsed by the HTTP proxy layer, it can search for load balancing and session persistence rules, execute matching rules, and select the appropriate server for forwarding.
[0082] In an optional embodiment, the proxy layer of the proxy server includes a first proxy layer and a second proxy layer, the first proxy layer includes a first communication endpoint and a second communication endpoint, and the first data is data in a TCP message format.
[0083] Optionally, the method may also include: the proxy server first creates a first communication endpoint through a first proxy layer, and then the proxy server transmits the first data to a second queue, wherein the second queue is a receiving queue of the first communication endpoint, and then the proxy server performs TCP parsing on the first data in the second queue through the first proxy layer to obtain third data, and finally, the proxy server transmits the third data to a second proxy layer, and performs HTTP parsing on the third data through the second proxy layer to obtain second data, wherein the second proxy layer is an upper layer of the first proxy layer.
[0084] Alternatively, if Figure 3 As shown, the proxy server creates the client tcp socket and server tcp socket through the TCP proxy layer. After that, the proxy server uses the preset tool (corresponding to Figure 3 DPDK in the Figure 3 The network message received in the Nic in the client TCP socket is placed in the receiving queue of the client TCP socket (corresponding to the second queue in this application). Then, the proxy server controls the TCP proxy layer to perform TCP protocol parsing on the network message in the receiving queue of the client TCP socket, and transfers the application data obtained by the parsing (corresponding to the third data in this application) to the upper proxy layer (i.e. Figure 3 The HTTP proxy layer in the process parses and processes the second data to obtain the second data, and then processes the second data into the target data sent to the load balancing layer.
[0085] Similarly, after the upper-layer proxy module performs corresponding processing on the parsed application data, the proxy server returns the processed application data to the TCP proxy layer, and then encapsulates the processed application data into a TCP message through the TCP proxy layer, transmits it to the sending queue of the server TCP socket, and controls the server TCP socket to send the TCP message to the message transceiver layer.
[0086] Optionally, the proxy server can set a preset mechanism such as a TCP window update mechanism and / or a congestion control mechanism for a specific TCP connection through a user-mode socket created by the TCP proxy layer.
[0087] Optionally, the proxy server can also proxy connections between user-mode sockets through the HTTP proxy layer (corresponding to Figure 3 The http proxy context in the TCP proxy layer is used for control, thereby achieving the purpose of controlling the behavior of the user-state socket in the TCP proxy layer to meet the requirements of the preset mechanism.
[0088] In an optional embodiment, the method may also include: the proxy server first determines the target parameters based on the target data, wherein the target parameters include at least a request header, a request line, a request method, and a uniform resource identifier; thereafter, the proxy server transmits the target parameters to the load balancer, wherein the load balancer is used to determine the second communication endpoint based on the target parameters; and then, the proxy server creates a target proxy connection through the second proxy layer, wherein the target proxy connection is used to characterize the association relationship between the first communication endpoint and the second communication endpoint.
[0089] Alternatively, if Figure 3 As shown, the HTTP proxy layer is mainly for the HTTP protocol, and the proxy layer is used to describe the proxy process of the HTTP connection and the application data parsing process. The HTTP proxy layer obtains the TCP payload (TCP data payload) from the client tcp socket created by the TCP proxy layer, and then the HTTP proxy layer parses the TCP payload into HTTP transaction data in HTTP format (corresponding to the target data in this application), and then the HTTP proxy layer parses the HTTP transaction data into the parameter information required by the load balancer in the load balancing layer (corresponding to the target parameter in this application), and stores the parameter information in the data structure corresponding to the HTTP proxy layer, and then passes the parameter information to the load balancer to perform the load balancing operation.
[0090] Optionally, the proxy server controls the TCP proxy layer to create a server TCP socket based on the balancing operation result generated by the load balancing device, and controls the server TCP socket to initiate a TCP connection to the corresponding target server. After the TCP connection between the server TCP socket and the target server is successfully established, the proxy server transmits the HTTP transaction data to the sending queue of the server TCP socket.
[0091] Optionally, after associating the client TCP socket in the TCP proxy layer with the server TCP socket through the HTTP proxy layer, when the HTTP request / response on either side of the client and the target server fails or times out, the proxy server can determine the processing of the TCP connection on the other side through the HTTP proxy layer.
[0092] Optionally, Figure 3The load balancing layer in the load balancing layer performs load balancing operations on the connection requests between the client and the target server based on preset rules, wherein the load balancer in the load balancing layer can obtain the target parameters based on the HTTP proxy layer analysis, and then determine and execute the corresponding load balancing rules and session persistence rules based on the target parameters, thereby achieving the purpose of selecting a suitable second communication endpoint for message forwarding.
[0093] In an optional embodiment, in the process of implementing load balancing between a client and a target server based on a first communication endpoint and a second communication endpoint, the proxy server first detects a first connection type and a second connection type, wherein the first connection type is a connection type of the first communication endpoint, and the second connection type is a connection type of the second communication endpoint, and the connection types include long connections and short connections.
[0094] Optionally, when the first connection type and the second connection type are both long connections, the proxy server prohibits the proxy server from sending target messages to the client and the target server, wherein the target message is used to close the first connection and / or the second connection; when the first connection type and the second connection type are both short connections, the proxy server prohibits the proxy server from sending target messages to the target server, and allows the proxy server to send target messages to the client; when the first connection type is a long connection and the second connection type is a short connection, the proxy server prohibits the proxy server from sending target messages to the client, and allows the proxy server to send target messages to the target server.
[0095] Optionally, the target message is a FIN message.
[0096] Optionally, the HTTP proxy layer supports two connection types: HTTP long connection and HTTP short connection. The HTTP connection type is determined by the "Connection" field in the HTTP request header. When the content of the "Connection" field is set to "keep-alive", it means that the connection type of the current HTTP proxy connection is a long connection. After completing the processing of an HTTP transaction data, the long connection will not be closed immediately, but will continue to wait for and process the next HTTP transaction data. The long connection will not be closed until the preset connection duration of the long connection times out.
[0097] Optionally, when the content of the "Connection" field is set to "close", it means that the connection type of the current HTTP proxy connection is a short connection. After completing the processing of an HTTP transaction data, the short connection is immediately closed. After that, the HTTP transaction data needs to create a new TCP connection for transmission.
[0098] Optionally, the HTTP proxy layer in the proxy server will not actively close the HTTP proxy connection, and the connection between the HTTP proxy layer and the client needs to be consistent with the actual server behavior, so as to ensure the normal forwarding of HTTP transaction data.
[0099] Optionally, the proxy server processes the HTTP proxy connection through the HTTP proxy layer in the following four scenarios, including:
[0100] (1) The client side uses HTTP persistent connection, and the target server side uses HTTP persistent connection;
[0101] (2) The client side uses HTTP short connection, and the target server side uses HTTP short connection;
[0102] (3) The client side uses HTTP long connection, and the target server side uses HTTP short connection;
[0103] (4) The client side uses HTTP short connection, and the target server side uses HTTP long connection.
[0104] Optionally, since the connection on the target server side is a connection initiated by the proxy server, when the connection initiated by the client side is a short connection, the proxy server does not need to establish a long connection on the target server side. Therefore, the fourth scenario is not considered in practical applications.
[0105] Optionally, for the first three scenarios, the management behavior of the HTTP proxy layer for the HTTP proxy connection is shown in List 1 below:
[0106] Table 1
[0107]
[0108] In an optional embodiment, the request state corresponding to the first communication endpoint in the proxy server is any one of the first request state, the second request state, the third request state and the fourth request state, and the response state corresponding to the second communication endpoint in the proxy server is any one of the first response state, the second response state, the third response state, the fourth response state and the fifth response state.
[0109] Optionally, the first request state is used to characterize that the first communication endpoint is waiting to establish a first connection; the second request state is used to characterize that the first communication endpoint receives complete message data that needs to be parsed by the proxy layer through the created first connection; the third request state is used to characterize that the first communication endpoint sends the message data parsed by the proxy layer to the second communication endpoint; the fourth request state is used to characterize that the first communication endpoint is waiting to receive reply data from the second communication endpoint.
[0110] Optionally, the first response state is used to characterize that the second communication endpoint is in an idle state; the second response state is used to characterize that the second communication endpoint is waiting to create a second connection; the third response state is used to characterize that the second communication endpoint receives complete message data that needs to be parsed by the proxy layer through the created second connection; the fourth response state is used to characterize that the second communication endpoint sends the message data parsed by the proxy layer to the first communication endpoint; the fifth response state is used to characterize that the second communication endpoint deactivates the second connection.
[0111] Optionally, in order to manage the HTTP proxy connection, the HTTP proxy layer needs to establish a state migration process for the HTTP transaction, wherein: Figure 4 is a flowchart of an optional HTTP transaction state migration process according to an embodiment of the present application, such as Figure 4 As shown, the white box represents the request state corresponding to the first communication endpoint, and the gray box represents the response state corresponding to the second communication endpoint.
[0112] Alternatively, if Figure 4 As shown, since there is no event on the responding side in the IDLE response state (corresponding to the first response state in this application), the migration from the IDLE response state to the WAITING request state (corresponding to the first request state in this application) is directly triggered by the requesting side. In addition, the migration from the REPLYING request state (corresponding to the fourth request state in this application) to the WAITING request state is autonomously migrated by the requesting side, and the corresponding response state of the responding side needs to be referred to during the migration process.
[0113] Optionally, the state migration process established by the HTTP proxy layer for the HTTP transaction is as follows:
[0114] Optionally, when the first communication endpoint is in the WAITING request state, the HTTP proxy layer reads the TCP payload from the first communication endpoint, and after waiting for the TCP proxy layer to successfully establish a three-way handshake, sends the TCP payload to the target server; when the first communication endpoint is in the HEADER_RECEIVING request state (corresponding to the second request state in the present application), the HTTP proxy layer reads data from the first communication endpoint and performs HTTP parsing; when the first communication endpoint is in the SENDING request state (corresponding to the third request state in the present application), after completing the HTTP parsing in the HEADER_RECEIVING state, the target parameters obtained by the parsing are handed over to the load balancing layer for processing, and then the client is controlled to establish a connection with the server and forward the message data to the second communication endpoint; after the client's network message data is sent, the first communication endpoint is in the REPLYING request state (corresponding to the fourth request state in the present application), and the first communication endpoint waits to receive the server's reply message and forwards the reply message to the client.
[0115] Optionally, when the target server starts to establish a connection, the second communication endpoint switches to the IDLE response state, and switches to the WAITING response state (corresponding to the second response state in this application) after the target server waits for the connection to be successfully established; when the second communication endpoint is in the WAITING response state, the HTTP proxy layer waits to read data from the second communication endpoint, and after the HTTP proxy layer receives the data from the second communication endpoint, the second communication endpoint switches to the HEADER_RECEIVING response state (corresponding to the third response state in this application); when the second communication endpoint is in the HEADER_RECEIVING response state, the HTTP proxy layer receives data from the second communication endpoint and performs HTTP parsing; when the second communication endpoint is in the SENDING response state (corresponding to the fourth response state in this application), the second communication endpoint forwards data to the first communication endpoint; after the server completes the data transmission, it enters the FINISHED response state (corresponding to the fifth response state in this application), and then triggers the client to actively switch states and close the connection, switching back to the IDLE state.
[0116] Optionally, the data read and write timeouts on both the client and server sides are controlled by the TCP proxy layer, and the HTTP proxy layer performs state transition only when the TCP proxy layer triggers a timeout event and executes processing steps in the corresponding state.
[0117] In an optional embodiment, after detecting the first connection type and the second connection type, after the first connection type is a short connection and the client actively closes the first connection, the proxy server switches the response state corresponding to the second communication endpoint to the first response state; after switching the response state corresponding to the second communication endpoint to the first response state, the proxy server stores the second connection in a preset cache pool; when the client re-initiates a connection to the target server, the proxy server selects a second connection corresponding to a target server from the preset cache pool and re-enables the second connection.
[0118] In an optional example, when using HTTP short connection, the proxy server needs to establish a new TCP connection for each request message transmission, which causes the problem of increased system resource consumption and may also affect system performance.
[0119] Optionally, when the proxy server is connected to the target server, the proxy server caches all socket connections corresponding to the target server through a preset connection cache pool to achieve the effect of socket connection reuse, that is, when the HTTP short connection initiated by the client is closed, the socket connection corresponding to the target server is not closed immediately, but the second communication endpoint is controlled to enter the IDLE response state, and then the socket connection corresponding to the target server is placed in the connection cache pool. After that, when a new request message arrives, the proxy server directly takes out an established socket connection from the connection cache pool for use.
[0120] Optionally, the proxy server caches all socket connections corresponding to the target server through a preset connection cache pool, thereby reducing the system overhead of establishing and closing the target server connection, thereby reducing system resource consumption and avoiding impact on system performance.
[0121] Optionally, assuming that the target server closes the socket connection after processing the transmission of a request message, if you want to re-establish the socket connection within a period of time, since the second communication endpoint is in the TIME_WAIT state, you must send a RST command to reset the connection, which will cause unnecessary delays. This delay problem can be solved by using a cache connection pool.
[0122] In an optional embodiment, the proxy server first performs HTTP parsing on the third data through the second proxy layer to obtain request header data corresponding to the third data. Then, the proxy server stores the request header data in a preset memory of the second proxy layer, wherein the space size of the preset memory is dynamically allocated according to the data amount of the request header data. Then, the proxy server detects whether the request header data stored in the preset memory is in a complete state, wherein the complete state represents that the request header data corresponds to a complete HTTP transaction. Finally, when the request header data stored in the preset memory is not in a complete state, the proxy server stores the request header data corresponding to the next third data in the memory, wherein the next third data is new third data obtained by parsing the first proxy layer.
[0123] Optionally, the proxy server's analysis of HTTP transactions mainly serves the load balancer. The proxy server can complete the analysis of a single HTTP message by calling an open source HTTP parsing library, such as http-parser. However, due to the complexity of seven-layer load balancing, in order to ensure the integrity of HTTP transaction data, the load balancer may need to parse multiple HTTP messages. Therefore, the proxy server caches the analysis results of each message analysis at the HTTP proxy layer, and after the complete HTTP transaction data is parsed, the cached serialized analysis results are sent to the upper-layer load balancing device to perform load balancing operations.
[0124] Optionally, the proxy server can also limit the cache capacity of each HTTP transaction data. When the amount of data to be cached exceeds the preset limit, the HTTP proxy layer stops parsing. It should be noted that the load balancer will not perform balancing operations based on the incomplete HTTP transaction data at this time, but will select a preset second communication endpoint to directly forward data.
[0125] Optionally, Figure 5 is a flowchart of an optional process of parsing multiple HTTP messages according to an embodiment of the present application, such as Figure 5 As shown, in order to reduce memory usage, the proxy server first obtains a memory of a preset size, where the preset size can be set to 128 bytes. After that, the proxy server will obtain the HTTP message from the communication endpoint for the first time, and transfer the obtained HTTP message to the preset memory. Then, the proxy server obtains the HTTP request header (or HTTP response header) through HTTP parsing. Then, the proxy server determines whether the current HTTP transaction data is complete based on the HTTP request header (or HTTP response header) obtained by parsing. If the current HTTP transaction data is complete, the parsing process ends.
[0126] In addition, when the current HTTP transaction data is incomplete, if the size of the HTTP request header (or HTTP response header) exceeds the preset size, the proxy server will reallocate a piece of memory of the preset size to store the HTTP request header (or HTTP response header). After the proxy server reallocates a piece of memory of the preset size, if it still cannot store the complete HTTP request header (or HTTP response header), it will continue to allocate memory of the preset size until the size of all allocated memory is greater than or equal to a preset threshold, wherein the preset threshold can be set to 4096 bytes, and the memory size and preset threshold allocated by the proxy server for the first time can be adjusted according to actual needs.
[0127] In summary, the present application directly obtains the request message in the physical network card through the message transceiver layer, thereby achieving the purpose of bypassing the use of the kernel protocol stack, thereby avoiding the complex operation steps corresponding to the kernel protocol stack, the process switching steps from kernel state to user state, and the copying process of network messages, while saving system resources. At the same time, the efficiency of sending and receiving network messages is improved; and when managing the HTTP proxy connection, the present application controls the opening and closing of the connection based on the state transition process of the HTTP transaction and the different connection types corresponding to the HTTP proxy connection, and caches the server tcp socket connection through a preset cache connection pool, avoiding the need to repeatedly recreate the server tcpsocket operation steps, thereby saving system resources; in addition, the present application caches the HTTP message through the memory, ensures the integrity of the HTTP transaction data obtained by parsing, and achieves the purpose of load balancing operation based on the complete HTTP transaction data.
[0128] From the above content, it can be seen that the present application directly interacts with the physical network card through the message transceiver layer to achieve the purpose of obtaining the request message (i.e., network message) from the client. The present application avoids the operation steps of copying the request message from the system kernel state to the user state in the prior art by directly obtaining the network message from the physical network card, thereby improving the efficiency of obtaining the request message.
[0129] Furthermore, the present application subsequently creates a connection between the client and the proxy server through the first communication endpoint, and creates a connection between the proxy server and the target server through the second communication endpoint, thereby achieving the purpose of load balancing the communication between the client and the target server through the first communication endpoint and the second communication endpoint. The technical solution of the present application does not use the traditional kernel protocol stack, thereby avoiding the performance of the load balancer being limited by the kernel protocol stack, thereby improving the communication efficiency between the client and the target server.
[0130] It can be seen that the technical solution of the present invention has at least the following effects:
[0131] 1. Provide an optimization solution for the seven-layer application load balancing technology, including bypassing the kernel protocol stack, using the user-mode TCP and HTTP proxy modules to parse the seven-layer application data, and finally completing the load balancing process, avoiding the complex operation of the kernel protocol stack and the process of process switching and data copying from kernel mode to user mode, saving system resources;
[0132] 2. The management method of HTTP connection is based on the state transition process of HTTP transaction. According to the different attributes of the client and server connection, the appropriate time and method are selected to close the connection, and the normal forwarding of client HTTP transaction is completed. At the same time, the consumption of server network resources is minimized, and more network optimization and adjustment space is provided. The proxy and parsing process of TCP and HTTP can be optimized according to specific application requirements;
[0133] 3. Use the connection pool to manage server-side connections to avoid wasting resources by repeatedly establishing connections with the server. The cross-message parsing and caching mechanism of a single HTTP transaction improves the processing efficiency of network requests and improves system performance.
[0134] The load balancer performance is limited by the kernel protocol stack and the communication efficiency between applications is low.
[0135] According to another aspect of the embodiment of the present application, an application load balancing device is also provided. Figure 6 is a schematic diagram of an optional application load balancing device according to an embodiment of the present application, such as Figure 6 As shown, the application load balancing device includes: a first parsing unit 601, a first transmission unit 602, a first determination unit 603 and a load balancing unit 604.
[0136] Optionally, a first parsing unit is used to parse a request message from a client through a message transceiver layer of a proxy server to obtain first data, wherein the message transceiver layer is at least used to directly interact with a physical network card of the proxy server; a first transmission unit is used to transmit the first data to a first communication endpoint in a proxy layer of the proxy server, and after the proxy layer of the proxy server parses the first data received by the first communication endpoint into second data, the second data is processed into target data to send to a load balancing layer of the proxy server, wherein the first communication endpoint is at least used to create a first connection, which is a connection between the client and the proxy server; a first determination unit is used to determine a second communication endpoint through the proxy layer of the proxy server according to a load balancing result returned by the load balancing layer based on the target data, wherein the second communication endpoint is at least used to create a second connection, which is a connection between the proxy server and the target server, and the proxy layer of the proxy server includes the second communication endpoint; a second transmission unit is used to implement load balancing between the client and the target server according to the first communication endpoint and the second communication endpoint.
[0137] In an optional embodiment, the application load balancing device further includes: a third transmission unit and a replication unit.
[0138] Optionally, the third transmission unit is used to receive the request message from the client through the receiving queue of the physical network card as the first queue; the copying unit is used to copy the request message in the first queue to the memory of the user state process through the message transceiver layer.
[0139] In an optional embodiment, the proxy layer of the proxy server includes a first proxy layer and a second proxy layer, the first proxy layer includes a first communication endpoint and a second communication endpoint, the first data is data in a TCP message format, and the application load balancing device also includes: a first creation unit, a fourth transmission unit, a second parsing unit, and a third parsing unit.
[0140] Optionally, the first creation unit is used to create a first communication endpoint through the first proxy layer; the third transmission unit is used to transmit the first data to the second queue, wherein the second queue is a receiving queue of the first communication endpoint; the second parsing unit is used to perform TCP parsing on the first data in the second queue through the first proxy layer to obtain third data; the third parsing unit is used to transmit the third data to the second proxy layer, and perform HTTP parsing on the third data through the second proxy layer to obtain second data, wherein the second proxy layer is an upper layer of the first proxy layer.
[0141] In an optional embodiment, the application load balancing device further includes: a second determining unit, a fourth transmitting unit and a second creating unit.
[0142] Optionally, a second determination unit is used to determine target parameters based on second data, wherein the target parameters include at least a request header, a request line, a request method, and a uniform resource identifier; a fourth transmission unit is used to transmit the target parameters to a load balancer, wherein the load balancer is used to determine a second communication endpoint based on the target parameters; a second creation unit is used to create a target proxy connection through a second proxy layer, wherein the target proxy connection is used to characterize the association relationship between the first communication endpoint and the second communication endpoint.
[0143] In an optional embodiment, the load balancing unit includes: a first detection subunit, a first control subunit, a second control subunit and a third control subunit.
[0144] Optionally, a first detection subunit is used to detect a first connection type and a second connection type, wherein the first connection type is the connection type of the first communication endpoint, the second connection type is the connection type of the second communication endpoint, and the connection types include long connections and short connections; a first control subunit is used to prohibit the proxy server from sending target messages to the client and the target server when the first connection type and the second connection type are both long connections, wherein the target message is used to close the first connection and / or the second connection; a second control subunit is used to prohibit the proxy server from sending target messages to the target server, and allow the proxy server to send target messages to the client when the first connection type and the second connection type are both short connections; a third control subunit is used to prohibit the proxy server from sending target messages to the client, and allow the proxy server to send target messages to the target server when the first connection type is a long connection and the second connection type is a short connection.
[0145] In an optional embodiment, the request state corresponding to the first communication endpoint is any one of a first request state, a second request state, a third request state and a fourth request state, wherein the first request state is used to characterize that the first communication endpoint is waiting for the establishment of a first connection; the second request state is used to characterize that the first communication endpoint receives complete message data that needs to be parsed by the proxy layer through the created first connection; the third request state is used to characterize that the first communication endpoint sends the message data parsed by the proxy layer to the second communication endpoint; and the fourth request state is used to characterize that the first communication endpoint is waiting to receive reply data from the second communication endpoint.
[0146] In an optional embodiment, the response state corresponding to the second communication endpoint is any one of a first response state, a second response state, a third response state, a fourth response state and a fifth response state, wherein the first response state is used to characterize that the second communication endpoint is in an idle state; the second response state is used to characterize that the second communication endpoint is waiting for the creation of a second connection; the third response state is used to characterize that the second communication endpoint receives complete message data that needs to be parsed by the proxy layer through the created second connection; the fourth response state is used to characterize that the second communication endpoint sends the message data parsed by the proxy layer to the first communication endpoint; and the fifth response state is used to characterize that the second communication endpoint deactivates the second connection.
[0147] In an optional embodiment, the load balancing unit further includes: a switching subunit, a first storage subunit, and an enabling subunit.
[0148] Optionally, a switching subunit is used to switch the response state corresponding to the second communication endpoint to the first response state after the first connection type is a short connection and the client actively closes the first connection; a first storage subunit is used to store the second connection in a preset cache pool after the response state corresponding to the second communication endpoint is switched to the first response state; and an enabling subunit is used to select a second connection corresponding to a target server from the preset cache pool and re-enable the second connection when the client re-initiates a connection to the target server.
[0149] In an optional embodiment, the third parsing unit includes: a parsing subunit, a second storage subunit, a second detection subunit and a third storage subunit.
[0150] Optionally, a parsing subunit is used to perform HTTP parsing on the third data through the second proxy layer to obtain request header data corresponding to the third data; a second storage subunit is used to store the request header data in a preset memory of the second proxy layer, wherein the space size of the preset memory is dynamically allocated according to the data amount of the request header data; a second detection subunit is used to detect whether the request header data stored in the preset memory is in a complete state, wherein the complete state represents that the request header data corresponds to a complete HTTP transaction; a third storage subunit is used to store the request header data corresponding to the next third data in the memory when the request header data stored in the preset memory is not in a complete state, wherein the next third data is new third data obtained by parsing the first proxy layer.
[0151] From the above content, it can be seen that the present application directly interacts with the physical network card through the message transceiver layer to achieve the purpose of obtaining the request message (i.e., network message) from the client. The present application avoids the operation steps of copying the request message from the system kernel state to the user state in the prior art by directly obtaining the network message from the physical network card, thereby improving the efficiency of obtaining the request message.
[0152] Furthermore, the present application subsequently creates a connection between the client and the proxy server through the first communication endpoint, and creates a connection between the proxy server and the target server through the second communication endpoint, thereby achieving the purpose of load balancing the communication between the client and the target server through the first communication endpoint and the second communication endpoint. The technical solution of the present application does not use the traditional kernel protocol stack, thereby avoiding the performance of the load balancer being limited by the kernel protocol stack, thereby improving the communication efficiency between the client and the target server.
[0153] It can be seen that the present application achieves the purpose of improving the efficiency of obtaining request messages by directly interacting with the physical network card through the message transceiver layer. In addition, the present application load balances the communication between the client and the target server through the first communication endpoint and the second communication endpoint, thereby achieving the technical effect of improving the communication efficiency between the client and the target server, thereby solving the technical problem of low communication efficiency between applications caused by the limitation of the load balancer performance by the kernel protocol stack.
[0154] According to another aspect of an embodiment of the present application, a computer program product is further provided, the computer program product comprising a stored computer program, wherein when the computer program is running, the computer program product is controlled to execute any one of the above-mentioned application load balancing methods.
[0155] According to another aspect of an embodiment of the present application, an electronic device is also provided, including: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute any one of the above-mentioned application load balancing methods by executing the executable instructions.
[0156] Optionally, Figure 7 is a schematic diagram of an optional electronic device according to an embodiment of the present application, such as Figure 7 As shown, an embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor, and when the processor executes the program, any one of the above-mentioned application load balancing methods is implemented.
[0157] The above-mentioned embodiments or examples disclosed in the present application are not exhaustive, but are only illustrative of some embodiments or examples, and are not intended to be specific limitations on the scope of protection disclosed in the present application. In the absence of contradiction, each step in a certain embodiment or example in the present application can be implemented as an independent example, and the steps can be combined arbitrarily. For example, the scheme after removing some steps in a certain embodiment or example can also be implemented as an independent example, and the order of the steps in a certain embodiment or example can be arbitrarily exchanged. In addition, the optional methods or optional examples in a certain embodiment or example can be combined arbitrarily; in addition, the various embodiments or examples can be combined arbitrarily, for example, some or all steps of different embodiments or examples can be combined arbitrarily, and a certain embodiment or example can be combined arbitrarily with the optional methods or optional examples of other embodiments or examples.
[0158] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0159] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0160] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0161] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0162] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory. The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0163] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0164] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0165] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0166] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. An application load balancing method, characterized in that: Applied in a proxy server, the method comprises: Parsing a request message from the client through a message transceiver layer of the proxy server to obtain first data, wherein the message transceiver layer is at least used to directly interact with a physical network card of the proxy server; The first data is transmitted to a first communication endpoint in the proxy layer of the proxy server, and after the proxy layer of the proxy server parses the first data received by the first communication endpoint into second data, the second data is processed into target data to send to the load balancing layer of the proxy server, wherein the first communication endpoint is at least used to create a first connection, and the first connection is a connection between the client and the proxy server; Determine, by the proxy layer of the proxy server, a second communication endpoint according to the load balancing result returned by the load balancing layer based on the target data, wherein the second communication endpoint is at least used to create a second connection, the second connection is a connection between the proxy server and the target server, and the proxy layer of the proxy server includes the second communication endpoint; The second data is sent to the target server through the second communication endpoint.
2. The application load balancing method according to claim 1, characterized in that: Before parsing the request message from the client through the message transceiver layer of the proxy server to obtain the first data, the application load balancing method further includes: Receiving a request message from the client by using the receiving queue of the physical network card as a first queue; The request message in the first queue is copied to the memory of the user state process through the message transceiver layer.
3. The application load balancing method according to claim 1, characterized in that: The proxy layer of the proxy server includes a first proxy layer and a second proxy layer, the first proxy layer includes the first communication endpoint and the second communication endpoint, the first data is data in a TCP message format, and the application load balancing method further includes: Creating the first communication endpoint through a first proxy layer; Transmitting the first data to a second queue, wherein the second queue is a receiving queue of the first communication endpoint; Performing TCP parsing on the first data in the second queue through the first proxy layer to obtain third data; The third data is transmitted to a second proxy layer, and HTTP parsing is performed on the third data by the second proxy layer to obtain the second data, wherein the second proxy layer is an upper layer of the first proxy layer.
4. The application load balancing method according to claim 3, characterized in that: The application load balancing method further includes: Determine target parameters according to the second data, wherein the target parameters at least include a request header, a request line, a request method, and a uniform resource identifier; transmitting the target parameter to a load balancer, wherein the load balancer is used to determine the second communication endpoint according to the target parameter; A target proxy connection is created through the second proxy layer, wherein the target proxy connection is used to represent an association relationship between the first communication endpoint and the second communication endpoint.
5. The application load balancing method according to claim 1, characterized in that: The application load balancing method further includes: Detecting a first connection type and a second connection type, wherein the first connection type is a connection type of the first communication endpoint, the second connection type is a connection type of the second communication endpoint, and the connection types include long connections and short connections; When both the first connection type and the second connection type are the long connection, prohibiting the proxy server from sending a target message to the client and the target server, wherein the target message is used to close the first connection and / or the second connection; When both the first connection type and the second connection type are the short connections, prohibiting the proxy server from sending the target message to the target server, and allowing the proxy server to send the target message to the client; When the first connection type is the long connection and the second connection type is the short connection, the proxy server is prohibited from sending the target message to the client, and the proxy server is allowed to send the target message to the target server.
6. The application load balancing method according to claim 1, characterized in that: The request state corresponding to the first communication endpoint is any one of a first request state, a second request state, a third request state and a fourth request state, wherein: The first request state is used to represent that the first communication endpoint is waiting to establish a first connection; The second request state is used to represent that the first communication endpoint receives complete message data that needs to be parsed by the proxy layer through the created first connection; The third request state is used to indicate that the first communication endpoint sends the message data parsed by the proxy layer to the second communication endpoint; The fourth request state is used to represent that the first communication endpoint is waiting to receive reply data from the second communication endpoint.
7. The application load balancing method according to claim 1, characterized in that: The response state corresponding to the second communication endpoint is any one of a first response state, a second response state, a third response state, a fourth response state and a fifth response state, wherein: The first response state is used to indicate that the second communication endpoint is in an idle state; The second response state is used to indicate that the second communication endpoint is waiting to establish a second connection; The third response state is used to indicate that the second communication endpoint receives complete message data that needs to be parsed by the proxy layer through the created second connection; The fourth response status is used to indicate that the second communication endpoint sends the message data parsed by the proxy layer to the first communication endpoint; The fifth response status is used to indicate that the second communication endpoint deactivates the second connection.
8. The application load balancing method according to claim 5 or 7, characterized in that: After detecting the first connection type and the second connection type, the application load balancing method further includes: When the first connection type is the short connection and the client actively closes the first connection, switching the response state corresponding to the second communication endpoint to the first response state; After switching the response state corresponding to the second communication endpoint to the first response state, storing the second connection in a preset cache pool; When the client re-initiates a connection to the target server, a second connection corresponding to the target server is selected from the preset cache pool, and the second connection is re-enabled.
9. An application load balancing device, characterized in that: include: A first parsing unit, configured to parse a request message from a client through a message transceiver layer of a proxy server to obtain first data, wherein the message transceiver layer is at least configured to directly perform data interaction with a physical network card of the proxy server; A first transmission unit is configured to transmit the first data to a first communication endpoint in a proxy layer of the proxy server, and after the proxy layer of the proxy server parses the first data received by the first communication endpoint into second data, process the second data into target data to send to the load balancing layer of the proxy server, wherein the first communication endpoint is at least used to create a first connection, and the first connection is a connection between the client and the proxy server; A first determining unit is configured to determine, through a proxy layer of the proxy server, a second communication endpoint according to a load balancing result returned by the load balancing layer based on the target data, wherein the second communication endpoint is at least used to create a second connection, the second connection is a connection between the proxy server and the target server, and the proxy layer of the proxy server includes the second communication endpoint; The second transmission unit is used to send the second data to the target server through the second communication endpoint.
10. An electronic device, characterized in that: It includes one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the application load balancing method described in any one of claims 1 to 8.