Reverse proxy request processing method, reverse proxy server and computer equipment
By using DPDK and Nginx in the reverse proxy server to build a communication engine and user-mode protocol stack, and using communication queues for communication, the problem of excessive CPU usage when the reverse proxy server processes large blocks of data is solved, and performance is improved.
Patent Information
- Application Number
- CN202411061015.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-10-11
AI Technical Summary
The existing reverse proxy server occupies the CPU for a long time when processing large blocks of data, resulting in low overall performance.
The communication engine and user-mode protocol stack based on DPDK and Nginx are used to build a reverse proxy engine, which communicates through communication queues, reduces the running of multiple processes, and enables multiple CPUs to collaboratively process data.
The processing performance of the reverse proxy server is improved, and the problem of excessive CPU usage when processing large blocks of data in the existing technology is avoided.
Smart Images

Figure CN118764529A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a method for processing a reverse proxy request, a reverse proxy server and a computer device. Background Art
[0002] Reverse proxy means that a proxy server receives connection requests from the Internet, then forwards the requests to a server on the internal network, and returns the results obtained from the server to the client requesting the connection on the Internet. At this time, the proxy server appears to the outside world as a reverse proxy server.
[0003] The general workflow of a reverse proxy is as follows: based on the policy, the client listens to the IP and port, and requests a connection from the reverse proxy server and sends data. The reverse proxy server accepts the connection from the downstream client, establishes an upstream connection with the server, reads the data, parses the protocol, processes the data, and forwards the data to the service system.
[0004] The existing reverse proxy server adopts the DPDK suite, user-mode protocol stack, and Nginx as the core architecture design. Nginx integrates the application protocol module and communicates with the DPDK suite through the user-mode protocol stack. Nginx, user-mode protocol stack, DPDK suite, etc. are integrated into one process, and multiple processes are run in parallel. Each process is bound to a different CPU core. The overall architecture is as follows: Figure 1 As shown in the figure, multiple processes running together occupy a lot of CPU, and Nginx integrates multiple application protocol modules and multiple security check functions. When processing large blocks of data, it takes a long time to occupy the CPU, resulting in low overall performance of the reverse proxy server. Summary of the invention
[0005] In view of this, an embodiment of the present invention proposes a method for processing reverse proxy requests, a reverse proxy server and a computer device to solve the following problems in the prior art: multiple processes running together occupy a lot of CPU, and Nginx integrates multiple application protocol modules and multiple security check functions. When processing large blocks of data, it takes a long time to occupy the CPU, resulting in low overall performance of the reverse proxy server.
[0006] On the one hand, an embodiment of the present invention proposes a method for processing a reverse proxy request, including: a communication engine receives a TCP (Transmission Control Protocol) connection request from a client, wherein the communication engine is constructed based on DPDK (Data Plane Development Kit); the communication engine searches a data queue hash table according to the PID (Process Controller) of the reverse proxy engine corresponding to the TCP connection request to obtain data queue address information corresponding to the PID, wherein the data queue address information is established based on a token and an instruction queue, and the reverse proxy engine is constructed based on Nginx and a user space protocol stack (User Space Protocol Stack); the communication engine establishes a connection between the client and the reverse proxy engine according to the data queue address information, and adds the connection to an established connection table; the reverse proxy engine polls a data queue corresponding to the data queue address information to obtain a data packet, and sends the data packet to the data queue through an interface of the user space protocol stack; the communication engine sends the data packet to a server.
[0007] In some embodiments, before the communication engine receives a TCP connection request from the client, it also includes: the reverse proxy engine obtains the token from the token queue, sets a predetermined instruction on the token, and sends the token with the setting completed to the instruction queue; the communication engine obtains the token in the instruction queue, executes the predetermined instruction in the token to create the data queue; the communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine into the token hash table according to the corresponding relationship.
[0008] In some embodiments, after the communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine into the token hash table according to the correspondence, it also includes: when the reverse proxy engine receives a forwarding request, it searches the token hash table for the data queue address information recorded in the token address information, and opens the data queue according to the data queue address information.
[0009] In some embodiments, after the communication engine receives a TCP connection request from a client, it also includes: the communication engine detects whether the TCP connection already exists in the established connection table based on the IP five-tuple information of the data packet carried by the TCP connection request; if the TCP connection does not exist in the established connection table, the communication engine establishes the TCP connection according to the expected connection table, and writes the established TCP connection into the established connection table; if the TCP connection exists in the established connection table, the communication engine establishes the TCP connection according to the established connection table.
[0010] In some embodiments, it also includes: the communication engine detects whether the life counter of the reverse proxy engine is updated according to a predetermined period; when the life counter is not updated, the communication engine sets the data queue to a suspended state; when a queue recovery instruction is received from the reverse proxy engine, the communication engine sets the data queue from a suspended state to a working state according to the queue recovery instruction.
[0011] In some embodiments, after the communication engine sets the data queue to a suspended state, it also includes: the communication engine detects whether the timeout period of the life counter is greater than a timeout threshold according to a predetermined period; when the timeout period is greater than the timeout threshold, the communication engine closes the data queue, deletes the PID in the data queue hash table, and releases the data queue address information.
[0012] In some embodiments, it also includes: when the communication engine receives a queue closing instruction from the reverse proxy engine through the instruction queue, the communication engine closes the data queue according to the PID of the reverse proxy engine and writes the result into the data queue hash table.
[0013] On the other hand, an embodiment of the present invention proposes a reverse proxy server, comprising: a network card, a Linux driver, a communication engine and a reverse proxy engine, wherein the communication engine is built based on DPDK, and the reverse proxy engine is built based on Nginx and a user-mode protocol stack; the steps of the above method are implemented when the communication engine and the reverse proxy engine interact.
[0014] On the other hand, an embodiment of the present invention provides a computer program product storing a computer program, wherein the computer program implements the steps of the above method when executed by a processor.
[0015] On the other hand, an embodiment of the present invention provides a computer device, which includes at least a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps of the above method when executing the computer program in the memory.
[0016] The embodiment of the present invention builds a reverse proxy engine based on Ngnix and a user-mode protocol stack, builds a communication engine based on DPDK, and uses communication queues for communication between the reverse proxy engine and the communication engine. The addresses of different communication queues are different during communication. When there are multiple working processes in the reverse proxy engine, multiple processes can communicate with the communication engine multi-processes without running the existing multiple overall processes. This solves the problem in the prior art that processing large blocks of data occupies the CPU for a long time, resulting in low processing performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0018] Figure 1 A schematic diagram of the overall architecture of a reverse proxy server provided by the prior art;
[0019] Figure 2 A flowchart of a method for processing a reverse proxy request provided by a first embodiment of the present invention;
[0020] Figure 3 A schematic diagram of the architecture of a reverse proxy server provided in the first embodiment of the present invention;
[0021] Figure 4 A schematic structural diagram of an electronic device provided in a fourth embodiment of the present invention. DETAILED DESCRIPTION
[0022] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0023] Unless otherwise defined, the technical terms or scientific terms used in the present invention should be understood by people with ordinary skills in the field to which the present invention belongs. The words "first", "second" and similar words used in the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0024] In order to keep the following description of the embodiments of the present invention clear and concise, detailed descriptions of well-known functions and well-known components are omitted.
[0025] In order to overcome the deficiencies of the prior art, the embodiments of the present invention focus on designing a separation of reverse proxy and network basic communication functions, and improve performance by working in a multi-process mode of the two types of services in collaboration.
[0026] The first embodiment of the present invention provides a method for processing a reverse proxy request. The process of the method is as follows: Figure 2 As shown, steps S101 to S105 are included:
[0027] S101, a communication engine receives a TCP (Transmission Control Protocol) connection request from a client, wherein the communication engine is built based on DPDK.
[0028] Regarding DPDK, it runs on the Linux system and is a collection of function libraries and drivers for fast packet processing, which can greatly improve data processing performance and throughput, and improve the efficiency of data plane business programs. DPDK uses polling instead of interrupts to process data packets. When receiving a data packet, the network card driver overloaded by DPDK will not notify the CPU through an interrupt, but will directly store the data packet in the memory and deliver it to the application layer software for direct processing through the interface provided by DPDK, which saves a lot of CPU interrupt time and memory copy time.
[0029] After the communication engine receives the TCP connection request from the client, the communication engine detects whether a TCP connection already exists in the established connection table based on the IP five-tuple information of the data packet carried in the TCP connection request; if there is no TCP connection in the established connection table, the communication engine establishes a TCP connection based on the expected connection table and writes the established TCP connection into the established connection table; if there is a TCP connection in the established connection table, the communication engine establishes a TCP connection based on the established connection table.
[0030] S102, the communication engine searches the data queue hash table according to the PID (process control identifier) of the reverse proxy engine corresponding to the TCP connection request to obtain the data queue address information corresponding to the PID, wherein the data queue address information is established based on the token and instruction queue, and the reverse proxy engine is built based on Nginx and the user-mode protocol stack.
[0031] About Nginx, it is an open source high-performance, reliable http web server and reverse proxy server architecture, with small memory usage, high concurrency, high scalability, high reliability, and support for hot deployment.
[0032] The user-space protocol stack refers to a network protocol stack implemented in the user space of the operating system rather than in the kernel space.
[0033] The data queue address information is established based on the token and the instruction queue. In the specific implementation, before the communication engine receives the TCP connection request from the client, the reverse proxy engine obtains the token from the token queue, sets the predetermined instructions on the token (usually including the configuration parameters for applying for the data queue, etc.), and sends the completed token to the instruction queue; the communication engine obtains the token in the instruction queue, executes the predetermined instructions in the token to create a data queue; the communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine to the token hash table according to the corresponding relationship. When the reverse proxy engine receives a forwarding request, it searches the token hash table for the data queue address information recorded in the token address information, and opens the data queue according to the data queue address information. At this point, a communication channel is established between the communication engine and the reverse proxy engine, and the data queue can be used for communication.
[0034] S103, the communication engine establishes a connection between the client and the reverse proxy engine according to the data queue address information, and adds the connection to the established connection table.
[0035] When the connection exists in the established connection table, when a TCP connection is received again in the future, the connection can be directly allowed to be established through the established connection table.
[0036] S104, the reverse proxy engine polls the data queue corresponding to the data queue address information to obtain the data packet, and sends the data packet to the data queue through the interface of the user mode protocol stack.
[0037] S105, the communication engine sends the data packet to the server.
[0038] After the data packet is sent to the server, the server processes the response of the data packet, and then transmits the response message returned to the client in the reverse direction of the above process. During the transmission, the data queue that is already in working state is also used to exchange data, which will not be elaborated here.
[0039] The embodiment of the present invention builds a reverse proxy engine based on Ngnix and a user-mode protocol stack, builds a communication engine based on DPDK, and uses communication queues for communication between the reverse proxy engine and the communication engine. The addresses of different communication queues are different during communication. When there are multiple working processes in the reverse proxy engine, multiple processes can communicate with the communication engine multi-processes without running the existing multiple overall processes. This solves the problem in the prior art that processing large blocks of data occupies the CPU for a long time, resulting in low processing performance.
[0040] The embodiment of the present invention also monitors the life state of the reverse proxy engine, thereby ensuring that the data queue is not over-occupied and the normal use of the communication path is ensured. In specific implementation, the communication engine detects whether the life counter of the reverse proxy engine is updated according to a predetermined period; if the life counter is not updated, the communication engine sets the data queue to a suspended state; if a queue recovery instruction is received from the reverse proxy engine, the communication engine sets the data queue from the suspended state to the working state according to the queue recovery instruction.
[0041] After the communication engine sets the data queue to the suspended state, the communication engine detects whether the timeout period of the life counter is greater than the timeout threshold according to a predetermined period; when the timeout period is greater than the timeout threshold, the communication engine closes the data queue, deletes the PID in the data queue hash table, and releases the data queue address information.
[0042] When the communication engine receives a queue closing instruction from the reverse proxy engine through the instruction queue, the communication engine closes the data queue according to the PID of the reverse proxy engine and writes the result into the data queue hash table.
[0043] Combine the following Figure 3 The reverse proxy server of exemplifies the above process. Figure 3 In the example, network card 1 corresponds to the client and network card 2 corresponds to the server.
[0044] For the DPDK-based communication engine, it provides basic network communication and security inspection functions, provides a communication queue for the working process of the reverse proxy engine, forwards data between the logical queue of the network card and the reverse proxy engine, or forwards data between network cards according to the forwarding strategy.
[0045] The functions of the communication engine are exemplarily described below.
[0046] 1. Establish and manage communication queues.
[0047] The communication engine of the embodiment of the present invention can construct a communication queue and communicate with the reverse proxy engine through the communication queue.
[0048] The communication engine is responsible for the management of the communication queue, which includes the instruction queue and the data queue. It has a two-way communication function and is implemented using a lock-free circular queue.
[0049] The communication engine uses the command queue to receive the commands issued by the upper-level reverse proxy engine. The above commands are divided into management commands and communication commands. Management commands include setting IP, routing strategy, control strategy, etc. Communication commands include expecting connection, forwarding strategy, etc. The communication engine provides a command queue and token queue for all reverse proxy engines.
[0050] When the reverse proxy engine sends an instruction to the communication engine, the reverse proxy engine first obtains a token with an ID from the token queue, then stores the instruction (usually including specific instructions and policies) in the token, and then sends the token to the instruction queue.
[0051] The communication engine obtains the token carrying the instruction from the instruction queue, executes the instruction in the token, and writes the execution result into the hash table node corresponding to the token ID. The token hash table stores a data structure with the token ID as the key.
[0052] After the reverse proxy engine issues the instruction, it will query the execution result in the token hash table according to the token ID to determine whether a subsequent data queue can be established.
[0053] When the reverse proxy engine finds the execution result in the token hash table, the reverse proxy engine will apply for the data queue through the instruction queue and the token to perform subsequent communications through the data queue.
[0054] The communication engine opens the data queue according to the instruction and returns the data queue address and other information through the token. The reverse proxy engine opens the data queue according to the data queue address and establishes a communication link. Subsequent network data packets are transmitted bidirectionally through this data queue.
[0055] The communication engine can use the PID of the reverse proxy engine when applying for the process as the key to manage the data queue. This hash table is called the data queue table. By managing the data queue through the data pair list, the communication engine can achieve multi-process communication with multiple reverse proxy engines, reduce CPU usage, and improve processing efficiency.
[0056] 2. Manage access control lists.
[0057] After receiving the access control policy, the communication engine uses a radix tree to manage the access control table based on factors such as IP and port, and checks the five-tuple of the data packet and the direction of the data packet. For example, before the reverse proxy engine opens the listening function, it needs to issue an access policy that allows access to the local IP, port, and protocol.
[0058] 3. Manage the expected connection table.
[0059] The communication engine receives the expected connection strategy through the instruction queue and manages the expected connection using a hash table. This table is called the expected connection table, which is used to manage the connection information temporarily established by the reverse proxy engine. For example, the FTP protocol module notifies the data communication engine to transmit the data packet that meets the IP and port to the reverse proxy engine. After the expected connection strategy is matched, the connection and session are established and added to the connection table. The connection and the strategy, PID, data queue and other information related to the connection are stored in the node of the connection table, and finally the strategy is deleted.
[0060] 4. Manage the established connection table.
[0061] The communication engine uses hash tables and linked lists to manage connections and sessions based on five-tuples such as IP. This table is called the established connection table. When a data packet arrives at the local machine, it first searches the established connection table. If it is not found, it searches the expected connection table and finally searches the access control table. The nodes in the established connection table store the connection and the connection-related policies, PID, data queues and other information.
[0062] The communication engine may also have a forwarding strategy function, which is similar to the forwarding function in the prior art. The forwarding strategy will be bound to the access control policy or the established connection table, which will not be described in detail here.
[0063] The reverse proxy engine integrates multiple application protocol modules to implement parsing, security checking, forwarding and other functions. It uses the Socket interface provided by the user-mode protocol stack to implement data network transmission and communicates with the communication engine through the communication queue.
[0064] The following is an exemplary description of the functions of the reverse proxy engine.
[0065] The reverse proxy engine can start multiple working processes at the same time based on the protocol stack. Each working process applies for a data queue from the communication engine through the command queue, obtains information such as the data queue address through the token, and opens the data queue. The access control policy, expected connection policy, forwarding policy and other information are sent to the data communication engine through the command queue, and the execution result is obtained according to the token ID.
[0066] The reverse proxy engine polls the data queue, obtains data packets, and transmits the data packets to the protocol stack interface. The data packets sent out by the protocol stack interface are sent to the data queue, and then the communication engine can read the data queue and search the connection table (including the established connection table and the expected connection table) according to the IP and other information of the data packet, and send the data packet to the target according to the connection and session information.
[0067] The above reverse proxy process is exemplified below based on a specific example.
[0068] 1. Initialization phase:
[0069] 1) Communication engine initialization.
[0070] The communication engine starts a process, binds to CPU core 0, binds multiple logical queues of multiple network cards, initializes the instruction queue, shares the memory pool, sets the IP, etc.
[0071] 2) Reverse proxy engine initialization.
[0072] ① The reverse proxy engine starts two working processes, working process 1 is bound to CPU core 1, and working process 2 is bound to CPU core 2.
[0073] ② Apply for data queue. The two working processes of the reverse proxy engine obtain tokens from the token queue respectively, set configuration parameters such as instructions and application data queue on the token, and send the token to the instruction queue.
[0074] ③ Create a data queue. The communication engine process reads the token, creates a data queue in the shared memory according to the configuration parameters, adds the data queue to the data queue hash table according to the PID of the working process in the reverse proxy engine, and writes the queue address, queue creation success and other information into the node corresponding to the token ID.
[0075] ④Complete the creation of the data queue. The two working processes of the reverse proxy engine read the results respectively and open their corresponding data queues according to the address and parameters.
[0076] 2. Set up strategies:
[0077] The management system sends access control policies for parameters such as the IP and port of the local machine to the instruction queue, and the communication engine adds the policies to the access control table.
[0078] When the management system configures the reverse proxy policy, after the reverse proxy policy is sent to the working process of the reverse proxy engine, the working process sends the policy ID, PID, and data queue bundling instructions to the communication engine, and the communication engine will associate the data queue, policy, and PID in the access control table.
[0079] 3. The data communication process is as follows (the following is an example of a working process of the reverse proxy engine, and the subsequent description is directly based on the reverse proxy engine as the main body):
[0080] 1) The reverse proxy engine starts listening. Since it is based on Nginx, the main process starts listening.
[0081] 2) The client initiates a TCP connection request to the reverse proxy engine. The communication engine searches the connection table, expected connection table, and access control table in turn according to the five-tuple information such as the IP address of the data packet.
[0082] The communication engine queries the access control policy to allow data packets to be sent to the local machine, and searches the data queue hash table according to the PID of the data queue in the policy, selects the corresponding data queue and sends it to the reverse proxy engine, establishes a connection and adds the connection to the connection table, and finally associates the connection with PID, data queue and other information.
[0083] The reverse proxy engine polls the data queue to obtain data packets, sends the data packets to the user-mode protocol stack interface, and sends the reply data packets to the client along the original route. After the TCP connection is established, the reverse proxy engine applies for a connection to the server.
[0084] 3) The data packet establishes a TCP connection with the server through the data queue, communication engine and routing information, then establishes a connection and session, and adds it to the connection table, and finally associates the connection with the policy, PID and data queue.
[0085] 4) The client sends application protocol data, and the data packet passes through the connection in the connection table, the data queue, the user-mode protocol stack, and the application protocol module of the reverse proxy engine. The application protocol module of the reverse proxy engine forwards the data to the user-mode protocol stack, the data queue, the connection in the connection table, and the server.
[0086] During the communication process, if a sub-connection needs to be opened (such as FTP protocol), the application protocol module sends an expected connection instruction to the instruction queue, and the communication engine establishes a node in the expected connection table, associates the node with PID, queue and other information, and finally feeds back the result.
[0087] 6) The client initiates a child connection, the communication engine checks the connection table, then searches the expected connection table, establishes a connection after successfully matching the expected connection, adds it to the connection table, associates the connection with the PID and data queue, deletes the expected connection node, and subsequently processes the data according to the parent connection processing flow.
[0088] 7) If the reverse proxy engine requires the communication engine to forward data for a sub-connection, after establishing the sub-connection and session of the reverse proxy engine, the communication engine forwards the data packet to the target server according to the forwarding identifier and target information in the expected connection, and executes the corresponding NAT process.
[0089] During execution, the communication status and data volume of the child connection will be sent to the reverse proxy parent connection regularly through the application protocol characteristics (or private protocol).
[0090] 8) When the client and server close the connection, the communication engine closes the connection in the connection table according to the status of the TCP protocol, and the UDP protocol closes the connection according to the timeout.
[0091] For the stage of closing the connection, the specific process is as follows:
[0092] When the reverse proxy engine exits normally, the command to close the queue is sent through the command queue. The communication engine closes the data queue according to the PID and writes the result to the node corresponding to the token. After the reverse proxy engine checks for success, it continues with other exit processes.
[0093] The reverse proxy engine periodically updates the life counter on the data queue. When the communication engine detects that the life counter does not increase, it determines that there is an abnormality in the reverse proxy engine and sets the data queue to a suspended state.
[0094] At this time, the reverse proxy engine may only have an exception but has not exited (only an abnormal timeout). After the communication engine sets the data queue to a suspended state, it also needs to determine whether the timeout period of the reverse proxy engine abnormality is greater than the predetermined timeout threshold. After the timeout period exceeds the timeout threshold, the data queue status is checked according to the PID, and the abnormal exit is marked in the data queue hash table with PID as the key in the shared memory, the data queue is closed, and the queue resources are recovered; after the queue resources are recovered, the data queue is re-applied if the reverse proxy engine needs it. If the timeout threshold is not exceeded, continue to wait. At this time, the reverse proxy engine can apply to restore the suspended data queue through the instruction queue, and the communication engine restores the data queue status according to the instruction.
[0095] The reverse proxy engine based on the user mode protocol stack and Nginx and the communication engine based on DPDK in the embodiment of the present invention can realize the reverse proxy function of TCP and UDP protocols, separate the existing integrated reverse proxy function and the basic network communication function, and then realize the collaborative processing of data by multiple CPUs, achieve the effect of bypassing the Linux kernel and separating services, and improve the reverse proxy performance; in the embodiment of the present invention, multiple business programs send instructions to the communication engine through tokens and instruction queues, the communication engine stores the instruction execution results through the token ID and the token hash table, and the reverse proxy engine obtains the execution results according to the token ID and the token hash table; by adopting the design of instruction queues, data queues, connection tables, expected connection tables, access control tables, forwarding strategies, etc., the functions of channel queue management, connection management, and data packet transmission between the reverse proxy engine and the communication engine are realized, thereby improving the reverse proxy performance.
[0096] The second embodiment of the present invention provides a reverse proxy server, which includes: a network card, a Linux driver, a communication engine and a reverse proxy engine, wherein the communication engine is built based on DPDK, and the reverse proxy engine is built based on Nginx and a user-mode protocol stack; when the communication engine and the reverse proxy engine interact, the following steps S201 to S205 are implemented:
[0097] S201, a communication engine receives a TCP connection request from a client, wherein the communication engine is built based on DPDK.
[0098] Regarding DPDK, it runs on the Linux system and is a collection of function libraries and drivers for fast packet processing, which can greatly improve data processing performance and throughput, and improve the efficiency of data plane business programs. DPDK uses polling instead of interrupts to process data packets. When receiving a data packet, the network card driver overloaded by DPDK will not notify the CPU through an interrupt, but will directly store the data packet in the memory and deliver it to the application layer software for direct processing through the interface provided by DPDK, which saves a lot of CPU interrupt time and memory copy time.
[0099] After the communication engine receives the TCP connection request from the client, the communication engine detects whether a TCP connection already exists in the established connection table based on the IP five-tuple information of the data packet carried in the TCP connection request; if there is no TCP connection in the established connection table, the communication engine establishes a TCP connection based on the expected connection table and writes the established TCP connection into the established connection table; if there is a TCP connection in the established connection table, the communication engine establishes a TCP connection based on the established connection table.
[0100] S202, the communication engine searches the data queue hash table according to the PID (process control identifier) of the reverse proxy engine corresponding to the TCP connection request to obtain the data queue address information corresponding to the PID, wherein the data queue address information is established based on the token and instruction queue, and the reverse proxy engine is built based on Nginx and the user-mode protocol stack.
[0101] About Nginx, it is an open source high-performance, reliable http web server and reverse proxy server architecture, with small memory usage, high concurrency, high scalability, high reliability, and support for hot deployment.
[0102] The user-space protocol stack refers to a network protocol stack implemented in the user space of the operating system rather than in the kernel space.
[0103] The data queue address information is established based on the token and the instruction queue. In the specific implementation, before the communication engine receives the TCP connection request from the client, the reverse proxy engine obtains the token from the token queue, sets the predetermined instructions on the token (usually including the configuration parameters for applying for the data queue, etc.), and sends the completed token to the instruction queue; the communication engine obtains the token in the instruction queue, executes the predetermined instructions in the token to create a data queue; the communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine to the token hash table according to the corresponding relationship. When the reverse proxy engine receives a forwarding request, it searches the token hash table for the data queue address information recorded in the token address information, and opens the data queue according to the data queue address information. At this point, a communication channel is established between the communication engine and the reverse proxy engine, and the data queue can be used for communication.
[0104] S203, the communication engine establishes a connection between the client and the reverse proxy engine according to the data queue address information, and adds the connection to the established connection table.
[0105] When the connection exists in the established connection table, when a TCP connection is received again in the future, the connection can be directly allowed to be established through the established connection table.
[0106] S204, the reverse proxy engine polls the data queue corresponding to the data queue address information to obtain the data packet, and sends the data packet to the data queue through the interface of the user mode protocol stack.
[0107] S205, the communication engine sends the data packet to the server.
[0108] After the data packet is sent to the server, the server processes the response of the data packet, and then transmits the response message returned to the client in the reverse direction of the above process. During the transmission, the data queue that is already in working state is also used to exchange data, which will not be elaborated here.
[0109] The embodiment of the present invention also monitors the life state of the reverse proxy engine, thereby ensuring that the data queue is not over-occupied and the normal use of the communication path is ensured. In specific implementation, the communication engine detects whether the life counter of the reverse proxy engine is updated according to a predetermined period; if the life counter is not updated, the communication engine sets the data queue to a suspended state; if a queue recovery instruction is received from the reverse proxy engine, the communication engine sets the data queue from the suspended state to the working state according to the queue recovery instruction.
[0110] After the communication engine sets the data queue to the suspended state, the communication engine detects whether the timeout period of the life counter is greater than the timeout threshold according to a predetermined period; when the timeout period is greater than the timeout threshold, the communication engine closes the data queue, deletes the PID in the data queue hash table, and releases the data queue address information.
[0111] When the communication engine receives a queue closing instruction from the reverse proxy engine through the instruction queue, the communication engine closes the data queue according to the PID of the reverse proxy engine and writes the result into the data queue hash table.
[0112] The embodiment of the present invention builds a reverse proxy engine based on Ngnix and a user-mode protocol stack, builds a communication engine based on DPDK, and uses communication queues for communication between the reverse proxy engine and the communication engine. The addresses of different communication queues are different during communication. When there are multiple working processes in the reverse proxy engine, multiple processes can communicate with the communication engine multi-processes without running the existing multiple overall processes. This solves the problem in the prior art that processing large blocks of data occupies the CPU for a long time, resulting in low processing performance.
[0113] A third embodiment of the present disclosure provides a computer program product, which is a computer-readable medium storing a computer program. When the computer program is executed by a processor, the method provided by any embodiment of the present disclosure is implemented, including the following steps S11 to S15:
[0114] S11, the communication engine receives a TCP connection request from the client, wherein the communication engine is built based on DPDK;
[0115] S12, the communication engine searches the data queue hash table according to the process controller PID of the reverse proxy engine corresponding to the TCP connection request to obtain the data queue address information corresponding to the PID, wherein the data queue address information is established based on the token and the instruction queue, and the reverse proxy engine is built based on Nginx and the user-mode protocol stack;
[0116] S13, the communication engine establishes a connection between the client and the reverse proxy engine according to the data queue address information, and adds the connection to the established connection table;
[0117] S14, the reverse proxy engine polls the data queue corresponding to the data queue address information to obtain the data packet, and sends the data packet to the data queue through the interface of the user mode protocol stack;
[0118] S15, the communication engine sends the data packet to the server.
[0119] The computer program is executed by the processor before the communication engine receives a TCP connection request from the client, and the processor also executes the following steps: the reverse proxy engine obtains a token from the token queue, sets a predetermined instruction on the token, and sends the token with the setting completed to the instruction queue; the communication engine obtains the token from the instruction queue, executes the predetermined instruction in the token to create a data queue; the communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine into the token hash table according to the corresponding relationship.
[0120] The computer program is executed by the processor after the communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine into the token hash table according to the correspondence, and the processor also executes the following steps: when the reverse proxy engine receives a forwarding request, it searches the token hash table for the data queue address information recorded in the token address information, and opens the data queue according to the data queue address information.
[0121] The computer program is executed by the processor after the communication engine receives the TCP connection request from the client, and the processor also executes the following steps: the communication engine detects whether a TCP connection already exists in the established connection table based on the IP five-tuple information of the data packet carried by the TCP connection request; if there is no TCP connection in the established connection table, the communication engine establishes a TCP connection according to the expected connection table, and writes the established TCP connection into the established connection table; if there is a TCP connection in the established connection table, the communication engine establishes a TCP connection according to the established connection table.
[0122] The computer program is specifically executed by the processor in the following steps: the communication engine detects whether the life counter of the reverse proxy engine is updated according to a predetermined period; when the life counter is not updated, the communication engine sets the data queue to a suspended state; when a queue recovery instruction is received from the reverse proxy engine, the communication engine sets the data queue from a suspended state to a working state according to the queue recovery instruction.
[0123] The computer program is executed by the processor after the communication engine sets the data queue to a suspended state, and the processor also executes the following steps: the communication engine detects whether the timeout period of the life counter is greater than the timeout threshold according to a predetermined period; when the timeout period is greater than the timeout threshold, the communication engine closes the data queue, deletes the PID in the data queue hash table, and releases the data queue address information.
[0124] The computer program is specifically executed by the processor as follows: when the communication engine receives a queue closing instruction from the reverse proxy engine through the instruction queue, the communication engine closes the data queue according to the PID of the reverse proxy engine and writes the result into the data queue hash table.
[0125] The embodiment of the present invention builds a reverse proxy engine based on Ngnix and a user-mode protocol stack, builds a communication engine based on DPDK, and uses communication queues for communication between the reverse proxy engine and the communication engine. The addresses of different communication queues are different during communication. When there are multiple working processes in the reverse proxy engine, multiple processes can communicate with the communication engine multi-processes without running the existing multiple overall processes. This solves the problem in the prior art that processing large blocks of data occupies the CPU for a long time, resulting in low processing performance.
[0126] Optionally, in this embodiment, the above-mentioned storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk. Optionally, in this embodiment, the processor executes the method steps recorded in the above-mentioned embodiment according to the program code stored in the storage medium. Optionally, the specific examples in this embodiment can refer to the examples described in the above-mentioned embodiment and the optional implementation mode, and this embodiment will not be repeated here. Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present invention can be implemented with a general computing device, which can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices. Optionally, they can be implemented with executable program codes of computing devices, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules respectively, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the present invention is not limited to any specific combination of hardware and software.
[0127] A fourth embodiment of the present disclosure provides an electronic device. The structural diagram of the electronic device can be as follows: Figure 4 As shown, at least a memory 901 and a processor 902 are included, the memory 901 stores a computer program, and the processor 902 implements the method provided by any embodiment of the present disclosure when executing the computer program on the memory 901. Exemplarily, the steps of the electronic device computer program are as follows S21 to S25:
[0128] S21, the communication engine receives a TCP connection request from the client, wherein the communication engine is built based on DPDK;
[0129] S22, the communication engine searches the data queue hash table according to the process controller PID of the reverse proxy engine corresponding to the TCP connection request to obtain the data queue address information corresponding to the PID, wherein the data queue address information is established based on the token and the instruction queue, and the reverse proxy engine is built based on Nginx and the user-mode protocol stack;
[0130] S23, the communication engine establishes a connection between the client and the reverse proxy engine according to the data queue address information, and adds the connection to the established connection table;
[0131] S24, the reverse proxy engine polls the data queue corresponding to the data queue address information to obtain the data packet, and sends the data packet to the data queue through the interface of the user mode protocol stack;
[0132] S25, the communication engine sends the data packet to the server.
[0133] Before executing the computer program stored in the memory in which the communication engine receives a TCP connection request from the client, the processor also executes the following computer program: the reverse proxy engine obtains a token from the token queue, sets a predetermined instruction on the token, and sends the token with the setting completed to the instruction queue; the communication engine obtains the token from the instruction queue, executes the predetermined instruction in the token to create a data queue; the communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine into the token hash table according to the corresponding relationship.
[0134] After the processor executes a computer program stored in the execution memory that causes the communication engine to write the data queue address information corresponding to the data queue and the PID of the reverse proxy engine into the token hash table according to the correspondence, the processor also executes the following computer program: when the reverse proxy engine receives a forwarding request, it searches the token hash table for the data queue address information recorded in the token address information, and opens the data queue according to the data queue address information.
[0135] After executing the computer program stored in the memory for the communication engine to receive a TCP connection request from a client, the processor further executes the following computer program: the communication engine detects whether a TCP connection already exists in an established connection table based on the IP five-tuple information of the data packet carried in the TCP connection request; if there is no TCP connection in the established connection table, the communication engine establishes a TCP connection based on the expected connection table and writes the established TCP connection into the established connection table; if there is a TCP connection in the established connection table, the communication engine establishes a TCP connection based on the established connection table.
[0136] The processor also specifically executes the following computer program: the communication engine detects whether the life counter of the reverse proxy engine is updated according to a predetermined period; when the life counter is not updated, the communication engine sets the data queue to a suspended state; when a queue recovery instruction is received from the reverse proxy engine, the communication engine sets the data queue from a suspended state to a working state according to the queue recovery instruction.
[0137] After executing the computer program stored in the memory that causes the communication engine to set the data queue to a suspended state, the processor also executes the following computer program: the communication engine detects whether the timeout period of the life counter is greater than the timeout threshold according to a predetermined period; when the timeout period is greater than the timeout threshold, the communication engine closes the data queue, deletes the PID in the data queue hash table, and releases the data queue address information.
[0138] The processor also specifically executes the following computer program: when the communication engine receives a queue closing instruction from the reverse proxy engine through the instruction queue, the communication engine closes the data queue according to the PID of the reverse proxy engine and writes the result into the data queue hash table.
[0139] The embodiment of the present invention builds a reverse proxy engine based on Ngnix and a user-mode protocol stack, builds a communication engine based on DPDK, and uses communication queues for communication between the reverse proxy engine and the communication engine. The addresses of different communication queues are different during communication. When there are multiple working processes in the reverse proxy engine, multiple processes can communicate with the communication engine multi-processes without running the existing multiple overall processes. This solves the problem in the prior art that processing large blocks of data occupies the CPU for a long time, resulting in low processing performance.
[0140] In addition, although exemplary embodiments have been described herein, the scope includes any and all embodiments based on the present invention with equivalent elements, modifications, omissions, combinations (e.g., various embodiments intersecting schemes), adaptations or changes. The elements in the claims will be interpreted broadly based on the language adopted in the claims, and are not limited to the examples described in this specification or during the implementation of this application, and the examples will be interpreted as non-exclusive. Therefore, this specification and examples are intended to be considered as examples only, and the true scope and spirit are indicated by the following claims and the full scope of their equivalents.
[0141] The above description is intended to be illustrative rather than restrictive. For example, the above examples (or one or more of them) can be used in combination with each other. For example, a person of ordinary skill in the art can use other embodiments when reading the above description. In addition, in the above-mentioned specific embodiments, various features can be grouped together to simplify the present invention. This should not be interpreted as an intention that a disclosed feature that is not required to be protected is necessary for any claim. On the contrary, the subject matter of the present invention may be less than all the features of a specific disclosed embodiment. Thus, the following claims are incorporated into the specific embodiments as examples or embodiments, wherein each claim is independently used as a separate embodiment, and it is considered that these embodiments can be combined with each other in various combinations or arrangements. The scope of the present invention should be determined with reference to the attached claims and the full scope of equivalent forms granted by these claims.
[0142] A number of embodiments of the present invention have been described in detail above, but the present invention is not limited to these specific embodiments. Those skilled in the art can make various variations and modifications to the embodiments based on the concept of the present invention, and these variations and modifications should all fall within the scope of protection claimed by the present invention.
Claims
1. A method for processing a reverse proxy request, characterized in that: include: The communication engine receives a transmission control protocol TCP connection request from a client, wherein the communication engine is built based on a data plane development kit DPDK; The communication engine searches the data queue hash table according to the process controller PID of the reverse proxy engine corresponding to the TCP connection request to obtain the data queue address information corresponding to the PID, wherein the data queue address information is established based on the token and the instruction queue, and the reverse proxy engine is built based on Nginx and the user-mode protocol stack; The communication engine establishes a connection between the client and the reverse proxy engine according to the data queue address information, and adds the connection to the established connection table; The reverse proxy engine polls the data queue corresponding to the data queue address information to obtain a data packet, and sends the data packet to the data queue through an interface of a user mode protocol stack; The communication engine sends the data packet to the server.
2. The method according to claim 1, characterized in that Before the communication engine receives a TCP connection request from a client, the method further includes: The reverse proxy engine obtains the token from the token queue, sets a predetermined instruction on the token, and sends the token with the setting completed to the instruction queue; The communication engine obtains the token in the instruction queue and executes a predetermined instruction in the token to create the data queue; The communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine into the token hash table according to the corresponding relationship.
3. The method according to claim 2, characterized in that After the communication engine writes the data queue address information corresponding to the data queue and the PID of the reverse proxy engine into the token hash table according to the corresponding relationship, it also includes: When receiving the forwarding request, the reverse proxy engine searches the token hash table for the data queue address information recorded in the token address information, and opens the data queue according to the data queue address information.
4. The method according to any one of claims 1 to 3, characterized in that After the communication engine receives the TCP connection request from the client, it also includes: The communication engine detects whether the TCP connection already exists in the established connection table according to the IP five-tuple information of the data packet carried by the TCP connection request; When the TCP connection does not exist in the established connection table, the communication engine establishes the TCP connection according to the expected connection table, and writes the established TCP connection into the established connection table; In a case where the TCP connection exists in the established connection table, the communication engine establishes the TCP connection according to the established connection table.
5. The method according to any one of claims 1 to 3, characterized in that Also includes: The communication engine detects whether the life counter of the reverse proxy engine is updated according to a predetermined period; In the case where the life counter is not updated, the communication engine sets the data queue to a suspended state; When receiving a queue recovery instruction from the reverse proxy engine, the communication engine sets the data queue from a suspended state to a working state according to the queue recovery instruction.
6. The method according to claim 5, characterized in that After the communication engine sets the data queue to a suspended state, the method further includes: The communication engine detects whether the timeout period of the life counter is greater than the timeout threshold according to a predetermined period; When the timeout period is greater than the timeout threshold, the communication engine closes the data queue, deletes the PID in the data queue hash table, and releases the data queue address information.
7. The method according to any one of claims 1 to 3, characterized in that Also includes: When the communication engine receives a queue closing instruction from the reverse proxy engine through the instruction queue, the communication engine closes the data queue according to the PID of the reverse proxy engine and writes the result into the data queue hash table.
8. A reverse proxy server, characterized in that: include: A network card, a Linux driver, a communication engine and a reverse proxy engine, wherein the communication engine is built based on DPDK, and the reverse proxy engine is built based on Nginx and a user-mode protocol stack; The communication engine and the reverse proxy engine implement the steps of the method described in any one of claims 1 to 7 when interacting.
9. A computer program product storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer device, comprising at least a memory and a processor, wherein a computer program is stored in the memory, wherein: The processor implements the steps of the method of any one of claims 1 to 7 when executing the computer program on the memory.
Citation Information
Cited By
Policy management method, electronic device, readable medium and program product
CN119051975A
