Packet Processing Method in LVS Load Balancing

By monitoring the number of connections to the backend server and replacing the load balancing algorithm when a failure is found, the problem of insufficient detection of the backend server's operating status in the prior art is solved, and faster and more reliable fault handling and load balancing allocation are achieved.

CN117240681BActive Publication Date: 2025-03-07NANJING WANQIYAN NETWORK TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310976983.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-04
Publication Date
2025-03-07
Estimated Expiration
2043-08-04

AI Technical Summary

Technical Problem

The existing packet processing methods in LVS load balancing lack detection of the operating status of the backend server and cannot respond to server failures in a timely manner, resulting in client access delays and failures.

Method used

By monitoring the number of connections to the backend server, fault detection is performed when the difference in connections between any two servers exceeds the delay limit threshold, replace the polling algorithm with the minimum connection number algorithm, renumber the backend server, and reorganize it into load balancing after the faulty server is restored.

Benefits of technology

It realizes timely detection and troubleshooting of the operating status of the back-end server, reduces client access delay, improves access success rate, and prevents other servers from failing due to overload.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117240681B_ABST
    Figure CN117240681B_ABST
Patent Text Reader

Abstract

The present invention provides a data packet processing method in LVS load balancing, relates to the technical field of data packet processing, and comprises the following steps: receiving a request data packet sent by a client, sending the request data packet to a load balancer, modifying a source address and a destination address in the request data packet, parsing and modifying request parameters in the data packet, monitoring the number of connections of a back-end server, performing fault detection processing when the difference between the number of connections of any two back-end servers exceeds a delay limit threshold, and outputting a fault repair signal when the IP address of the faulty server is received. The present invention is used to solve the problems in the existing data packet processing method in LVS load balancing that the detection of the running status of the back-end server is lacking, the client cannot be ensured to access successfully, and the server is not promptly incorporated into the load balancing after the fault is eliminated, resulting in other servers possibly failing due to overload.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data packet processing, and in particular to a data packet processing method in LVS load balancing. Background Art

[0002] LVS is equivalent to a virtualized application based on IP addresses, and provides an efficient solution for load balancing based on IP addresses and content request distribution. Through the load balancing technology achieved by LVS and the Linux operating system, a high-performance and highly available Linux server cluster is realized, which has good reliability, scalability and operability, thereby achieving optimal performance at a low cost.

[0003] In the existing technology, the data packet processing method in LVS load balancing is to use a single load balancing algorithm to select the back-end server, lacking the detection of the running status of the back-end server. When the back-end server fails, it cannot respond in time, resulting in the client needing to wait for a long time when requesting to access resources, and it cannot be ensured that the client can access successfully; for example, in the Chinese patent application publication number CN113364660A, a data packet processing method and device in load balancing are disclosed. The processing method sends the response data packet to the LVS server for forwarding through the established IP tunnel, realizes the transmission of the response data packet across computer rooms, and solves the problem that the user request cannot be completed; however, this method lacks the running detection of the back-end server, and there is a problem that the server is not incorporated into the load balancing in time after the troubleshooting, resulting in other servers may fail due to overload. Summary of the invention

[0004] In view of the deficiencies in the prior art, the present invention provides a data packet processing method in LVS load balancing, which receives a request data packet sent by a client, sends the request data packet to a load balancer, modifies the source address and the destination address in the request data packet, parses and modifies the request parameters in the data packet, monitors the number of connections of the back-end server, performs fault detection processing when the difference in the number of connections between any two back-end servers exceeds a delay limit threshold, and outputs a fault repair signal when the IP address of the faulty server is received; at this time, the polling algorithm in the original method is replaced with a minimum number of connections algorithm, and the back-end servers are renumbered; a detection data packet is sent to the faulty server at every first detection time, and when a normal response is obtained, all new loads are transferred to the server in a short time until the number of connections of the server is the same as that of the back-end server with the smallest number of connections, at which time the server is reclassified as a back-end server, and the load balancing algorithm is replaced with the original polling algorithm, so as to solve the problems that the existing data packet processing method in LVS load balancing lacks detection of the running status of the back-end server, cannot ensure that the client can access successfully, and the server is not incorporated into the load balancing in time after the fault is eliminated, resulting in other servers possibly failing due to overload.

[0005] In order to achieve the above object, the present invention is implemented through the following technical solutions: In a first aspect, the present application provides a data packet processing method in LVS load balancing, comprising the following steps:

[0006] Step S1, receiving a request data packet sent by a client, and sending the request data packet to a load balancer;

[0007] Step S2, selecting a suitable backend server as the target server according to the load balancing algorithm, and modifying the source address and destination address in the request data packet, marking it as a modified data packet; and sending the modified data packet to the target server;

[0008] Step S3, parsing and modifying the request parameters in the data packet, processing according to the logic corresponding to the request, writing the response data into the response data packet; and sending the response data packet to the load balancer;

[0009] Step S4, modifying the source address and the destination address in the response data packet, and sending the response data packet to the client;

[0010] Step S5, monitoring the number of connections of the backend servers, and performing fault detection processing when the difference between the number of connections of any two backend servers exceeds a delay limit threshold;

[0011] Step S6: When the IP address of the faulty server is received, a fault repair signal is output, and a detection data packet is sent to the faulty server at intervals of a first detection time.

[0012] Furthermore, the step S1 includes the following sub-steps:

[0013] Step S101, presetting a number of backend server IP addresses that can be loaded, wherein the backend servers have the same application program and data;

[0014] Step S102, configuring the IP address of the load balancer as the address for the client to access the server;

[0015] Step S103: When the client requests to access the server, the request data packet is sent to the IP address of the load balancer.

[0016] Furthermore, the step S2 includes the following sub-steps:

[0017] Step S201, numbering a number of backend servers from H1 to HN; wherein N is a positive integer and N is greater than 1;

[0018] Step S202, when a request data packet is received, a target server is selected using a polling algorithm; the polling algorithm is configured as follows:

[0019] Mark the IP addresses of the backend servers numbered from H1 to HN as the target IP addresses; obtain the IP address of the backend server numbered H1 and output the target IP address; when the second request data packet is received, obtain the IP address of the backend server numbered H2 and output the target IP address; and so on, when the N+1th request data packet is received, obtain the IP address of the backend server numbered H[(N+1)%N] and output the target IP address, where % is the remainder symbol, indicating that N+1 is the remainder of N;

[0020] Step S203, write the source address of the request data packet into the request data packet and mark it as the data source address; modify the source address of the request data packet to the IP address of the load balancer, and modify the destination address to the target IP address; send the modified data packet to the target server.

[0021] Furthermore, the step S3 includes the following sub-steps:

[0022] Step S3011, obtain the modification data packet, parse the request data in the modification data packet, the request data includes a request header, a request body and a request parameter; the request header includes a GET request method and a POST request method; the request body is the specific request content, wherein the request body of the GET request method is empty, and the request parameter is not empty; the request body of the POST request method includes a request parameter; the request parameter is a query string;

[0023] Step S3012, obtain the request header; when the GET request method is obtained, output the GET request signal; when the POST request method is obtained, output the POST request signal.

[0024] Furthermore, the step S3 also includes the following sub-steps:

[0025] Step S3021, receiving a request signal;

[0026] Step S3022, when a GET request signal is received, the specific content in the server is queried according to the query string in the request parameter. When the specific content is successfully queried, the status code is 200, the response time and the specific response content are output; the data source address, the specific response content and the response time are encapsulated into a response data packet; the response data packet is sent to the load balancer; when the specific content is not queried, the status code is 404; the data source address and the status code are encapsulated into a response data packet; the response data packet is sent to the load balancer;

[0027] Step S3023, when a POST request signal is received, the request body is obtained, and the specific content in the server is queried according to the request parameters in the request body. When the specific content is successfully queried, the status code is output as 200, and the response time and specific response content are output; the data source address, specific response content and response time are encapsulated into a response data packet; the response data packet is sent to the load balancer; when the specific content is not queried, the status code is output as 404; the data source address and status code are encapsulated into a response data packet; the response data packet is sent to the load balancer.

[0028] Furthermore, the step S4 includes the following sub-steps:

[0029] Step S401, parsing a response data packet to obtain a data source address in the response data packet;

[0030] Step S402, modifying the source address of the response data packet to the IP address of the target server, modifying the destination address of the response data packet to the data source address, and deleting the data source address;

[0031] Step S403: Send the response data packet to the client.

[0032] Furthermore, the step S5 includes the following sub-steps:

[0033] Step S5011, monitoring the number of connections of all backend servers, where the number of connections is the number of connections being processed by the backend servers; when the difference between the number of connections of any two backend servers is greater than the delay limit threshold, proceed to step S5012, otherwise no subsequent processing is performed;

[0034] Step S5012, send a detection data packet to all backend servers. If the detection data packet receives a normal response, no processing is performed; if the detection data packet receives no response or receives an abnormal response, obtain the IP address of the backend server, mark it as a faulty server, and output the IP address of the faulty server.

[0035] Furthermore, the step S5 further includes the following sub-steps:

[0036] Step S502: replace the polling algorithm in step S202 with a minimum connection number algorithm, and select a suitable backend server according to the minimum connection number algorithm; the minimum connection number algorithm is configured as follows:

[0037] Obtain the number of connections of all backend servers, and sort the backend servers according to the number of connections. The number of the server with the least number of connections is L1, and the number of the server with the most number of connections is LM, where M is a positive integer and M is greater than 1; when there are several backend servers with the same number of connections, obtain the backend server numbers in step S201 and sort them from small to large according to the numbers;

[0038] When receiving the request data packet, select the backend server with sequence number L1, mark it as the target server, and output the IP address of the target server;

[0039] Monitor the number of connections of all backend servers again and re-sort the backend servers;

[0040] The source address of the request data packet is modified to the IP address of the load balancer, and the destination address is modified to the IP address of the target server; the modified data packet is sent to the target server.

[0041] Furthermore, the step S6 includes the following sub-steps:

[0042] Step S6011, receiving the IP address of the faulty server, and outputting an IP address signal and a fault repair signal;

[0043] Step S6012, sending a detection data packet to the faulty server at intervals of the first detection time. When a normal response is obtained, the faulty server is changed to a maintenance server and troubleshooting information is output. When no response is obtained or an abnormal response is obtained, the detection data packet continues to be sent at intervals of the first detection time.

[0044] Furthermore, the step S6 also includes the following sub-steps:

[0045] Step S6021, when troubleshooting information is received, the connection numbers of all backend servers are obtained, the connection number of the backend server with the least number of connections is obtained, and marked as the target number; when a request data packet is received, the source address of the request data packet is modified to the IP address of the load balancer, and the destination address is modified to the IP address of the maintenance server; and the modified data packet is sent to the maintenance server;

[0046] Step S6022, monitoring the number of connections to the maintenance server, when the number of connections to the maintenance server is equal to the target number, changing the maintenance server to a backend server, and replacing the minimum connection number algorithm in step S202 with a polling algorithm.

[0047] In a second aspect, the present invention provides an electronic device, comprising a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in any of the methods described above are executed.

[0048] In a third aspect, the present invention provides a storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps in any of the methods described above are executed.

[0049] Beneficial effects of the present invention: The present invention determines whether a backend server fails by monitoring the number of connections of all backend servers. When a failure occurs, the server is marked as a failed server, and the load balancing algorithm in the original method is replaced, so that the problem of a long waiting time when the client accesses and the problem of not getting a normal response to the access can be avoided, thereby improving the timeliness of access feedback;

[0050] The present invention determines whether the faulty server has been repaired by sending a detection data packet to the faulty server at every first detection time. When the repair is completed, all new loads in a short period of time are transferred to the server. When the number of connections of the server is the same as the minimum number of connections in the back-end server, the load balancing algorithm is replaced, and the maintenance status of the faulty server can be judged in time. When the repair is completed, the server is incorporated into the load balancing processing to prevent other back-end servers from being overloaded for a long time and malfunctioning, thereby improving the comprehensiveness of load balancing distribution.

[0051] Advantages of additional aspects of the present invention will be given in part in the description of the following specific embodiments, and in part will become apparent from the following description, or will be learned through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0053] Figure 1The figure is a flow chart of the steps of the method of the present invention. DETAILED DESCRIPTION

[0054] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the present invention is further explained below in conjunction with specific implementation methods.

[0055] Embodiment 1

[0056] See also Figure 1 As shown, the present invention provides a data packet processing method in LVS load balancing, receives a request data packet sent by a client, sends the request data packet to a load balancer, modifies the source address and the destination address in the request data packet, parses and modifies the request parameters in the data packet, monitors the number of connections of the back-end server, performs fault detection processing when the difference in the number of connections between any two back-end servers exceeds a delay limit threshold, and outputs a fault repair signal when the IP address of the faulty server is received; at this time, the polling algorithm in the original method is replaced with a minimum connection number algorithm, and the back-end servers are renumbered; a detection data packet is sent to the faulty server at every first detection time, and when a normal response is obtained, all new loads are transferred to the server in a short time until the number of connections of the server is the same as the number of connections of the back-end server with the smallest number of connections, at which time the server is reclassified as a back-end server, and the load balancing algorithm is replaced with the original polling algorithm.

[0057] Specifically, the steps include:

[0058] Step S1, receiving a request data packet sent by a client, and sending the request data packet to a load balancer; Step S1 also includes the following sub-steps:

[0059] Step S101, presetting a number of backend server IP addresses that can be loaded, wherein the backend servers have the same application program and data;

[0060] When implementing it, the backend servers need to be configured with the same application and data to ensure that the same response data can be obtained no matter which backend server is selected as the target server;

[0061] Step S102, configuring the IP address of the load balancer as the address for the client to access the server;

[0062] Step S103, when the client requests to access the server, the request data packet is sent to the IP address of the load balancer;

[0063] Step S2, selecting a suitable backend server as the target server according to the load balancing algorithm, modifying the source address and destination address in the request data packet, and sending the modified data packet to the target server; Step S2 also includes the following sub-steps:

[0064] Step S201, numbering a number of backend servers from H1 to HN; wherein N is a positive integer and N is greater than 1;

[0065] Step S202, when a request data packet is received, a target server is selected using a polling algorithm; the polling algorithm is configured as follows:

[0066] Mark the IP addresses of the backend servers numbered from H1 to HN as the target IP addresses; obtain the IP address of the backend server numbered H1 and output the target IP address; when the second request data packet is received, obtain the IP address of the backend server numbered H2 and output the target IP address; and so on, when the N+1th request data packet is received, obtain the IP address of the backend server numbered H[(N+1)%N] and output the target IP address;

[0067] % is the modulo symbol, which means N+1 modulo N. When more than N request packets are received, the backend server is selected as the target server by calculating the modulo.

[0068] Step S203, write the source address of the request data packet into the request data packet and mark it as the data source address; modify the source address of the request data packet to the IP address of the load balancer, and modify the destination address to the target IP address; send the modified data packet to the target server;

[0069] In the specific implementation, in order to ensure the correct transmission and response of the data packet, the source address and destination address of the request data packet need to be modified to the IP address of the load balancer and the IP address of the backend server; in this way, the request sent by the client will be received by the load balancer, which will then perform routing selection and forward the data packet to the corresponding backend server for processing; the source address of the request data packet is written into the request data packet in text form, and the modified source address is the source address in the attributes of the request data packet;

[0070] Step S3, parse and modify the request parameters in the data packet, process according to the logic corresponding to the request, write the response data into the response data packet; send the response data packet to the load balancer; Step S3 includes the following sub-steps:

[0071] Step S3011, obtain the modification data packet, parse the request data in the modification data packet, the request data includes a request header, a request body and a request parameter; the request header includes a GET request method and a POST request method; the request body is the specific request content, wherein the request body of the GET request method is empty, and the request parameter is not empty; the request body of the POST request method includes a request parameter; the request parameter is a query string;

[0072] Step S3012, obtain the request header; when the GET request method is obtained, output the GET request signal; when the POST request method is obtained, output the POST request signal.

[0073] Step S3021, receiving a request signal;

[0074] Step S3022, when a GET request signal is received, the specific content in the server is queried according to the query string in the request parameter. When the specific content is successfully queried, the status code is 200, the response time and the specific response content are output; the data source address, the specific response content and the response time are encapsulated into a response data packet; the response data packet is sent to the load balancer; when the specific content is not queried, the status code is 404; the data source address and the status code are encapsulated into a response data packet; the response data packet is sent to the load balancer;

[0075] In specific implementation, it is necessary to query an MP4 file named "1". The query string is / media?name=1&type=mp4, where the query parameter name specifies the file name 1, and the query parameter type specifies the file type MP4. When processing the request, the backend server will find the MP4 file named 1 from the file system, read it into the memory, encapsulate it into a response data packet and return it to the client.

[0076] Step S3023, when a POST request signal is received, the request body is obtained, and the specific content in the server is queried according to the request parameters in the request body. When the specific content is successfully queried, the status code is output as 200, and the response time and specific response content are output; the data source address, specific response content and response time are encapsulated into a response data packet; the response data packet is sent to the load balancer; when the specific content is not queried, the status code is output as 404; the data source address and status code are encapsulated into a response data packet; the response data packet is sent to the load balancer;

[0077] In specific implementation, it is necessary to query an MP4 file named "1", and the request parameters in the request body are name=1&type=mp4&action=query; wherein the name parameter specifies that the file name is 1, the type parameter specifies that the file type is MP4, and the action parameter specifies that the operation is query;

[0078] Step S4, modifying the source address and the destination address in the response data packet, and sending the response data packet to the client; Step S4 includes the following sub-steps:

[0079] Step S401, parsing a response data packet to obtain a data source address in the response data packet;

[0080] Step S402, modifying the source address of the response data packet to the IP address of the target server, modifying the destination address of the response data packet to the data source address, and deleting the data source address;

[0081] Step S403, sending the response data packet to the client;

[0082] In specific implementation, the data source address is deleted in order to return the content corresponding to the client request; the source address and destination address in the response data packet are modified in order to ensure that the response can be correctly returned to the client;

[0083] Step S5, monitoring the number of connections of the backend servers, and performing fault detection processing when the difference between the number of connections of any two backend servers exceeds the delay limit threshold; Step S5 includes the following sub-steps:

[0084] Step S5011, monitoring the number of connections of all backend servers, where the number of connections is the number of connections being processed by the backend server, and the connection is specifically set to be a communication channel established between the client and the server; when the difference between the number of connections of any two backend servers is greater than the delay limit threshold, proceed to step S5012, otherwise no subsequent processing is performed;

[0085] The delay limit threshold is set to 50, which means that the difference in the number of connections between all backend servers is within the normal range within the allowed delay range;

[0086] Step S5012, sending a detection data packet to all backend servers. If the detection data packet receives a normal response, no processing is performed; if the detection data packet receives no response or receives an abnormal response, the IP address of the backend server is obtained, marked as a faulty server, and the IP address of the faulty server is output;

[0087] Step S502: replace the polling algorithm in step S202 with a minimum connection number algorithm, and select a suitable backend server according to the minimum connection number algorithm; the minimum connection number algorithm is configured as follows:

[0088] Obtain the number of connections of all backend servers, and sort the backend servers according to the number of connections. The number of the server with the least number of connections is L1, and the number of the server with the most number of connections is LM, where M is a positive integer and M is greater than 1; when there are several backend servers with the same number of connections, obtain the backend server numbers in step S201 and sort them from small to large according to the numbers;

[0089] Among them, M is the value of N minus the faulty server; the reason for sorting from small to large numbers is that in the polling algorithm, when the number of connections of two backend servers is the same, the one with the smaller number receives the modification data packet first and responds. Sorting from small to large can reduce the load on the server;

[0090] When receiving the request data packet, select the backend server with sequence number L1, mark it as the target server, and output the IP address of the target server;

[0091] Monitor the number of connections of all backend servers again and re-sort the backend servers;

[0092] Modify the source address in the request data packet to the IP address of the load balancer, and modify the destination address to the IP address of the target server; send the modified data packet to the target server;

[0093] In specific implementation, the probe packet is a small data packet sent by the LVS load balancer, which contains some information about the load balancer, such as the sequence number and timestamp of the probe packet. When the backend server successfully receives the probe packet, it will generate a normal response, usually returning the same probe packet to the load balancer to indicate its normal status.

[0094] In addition, the probe data packet may also receive an abnormal response. For example, when the backend server cannot process the probe packet in time, it may reply with a timeout response, indicating that the server has exceeded the reasonable response time; when the backend server cannot process the probe packet for some reason, it may reply with a rejection response, indicating that the server will not process the probe request; when an error occurs when the backend server responds to the probe packet, it may return an error response, which usually contains an error code or detailed error information;

[0095] Step S6, when the IP address of the faulty server is received, a fault repair signal is output, and a detection data packet is sent to the faulty server at intervals of a first detection time; the first detection time is set to 1 minute, and step S6 includes the following sub-steps:

[0096] Step S6011, receiving the IP address of the faulty server, and outputting an IP address signal and a fault repair signal;

[0097] Step S6012, sending a detection data packet to the faulty server at intervals of the first detection time. When a normal response is obtained, the faulty server is changed to a maintenance server and troubleshooting information is output. When no response is obtained or an abnormal response is obtained, the detection data packet continues to be sent at intervals of the first detection time.

[0098] Step S6021, when troubleshooting information is received, the connection numbers of all backend servers are obtained, the connection number of the backend server with the least number of connections is obtained, and marked as the target number; when a request data packet is received, the source address in the request data packet is modified to the IP address of the load balancer, and the destination address is modified to the IP address of the maintenance server; and the modified data packet is sent to the maintenance server;

[0099] Step S6022, monitoring the number of connections to the maintenance server, when the number of connections to the maintenance server is equal to the target number, changing the maintenance server to a backend server, and replacing the minimum number of connections algorithm in step S202 with a polling algorithm;

[0100] In specific implementation, when the faulty server responds to the detection data packet normally, in order to relieve the load of other backend servers, all new modified data packets are temporarily sent to the server for response. When the number of connections of the server is the same as that of the server with the least number of connections before, the minimum connection number algorithm is replaced with the polling algorithm to reduce the resources required to recalculate the number of connections and sort them each time;

[0101] Embodiment 2

[0102] In a second aspect, the present application provides an electronic device, including a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in any one of the above methods are performed. Through the above technical solution, the processor and the memory are interconnected and communicate with each other through a communication bus and / or other forms of connection mechanisms (not marked), and the memory stores a computer program executable by the processor. When the electronic device is running, the processor executes the computer program to execute the method in any optional implementation method of the above embodiment to achieve the following functions: receiving a request data packet sent by the client, and sending the request data packet to the load balancer; selecting a suitable back-end server as the target server according to the load balancing algorithm, and modifying the source address and destination address in the request data packet, marking it as a modified data packet; sending the modified data packet to the target server; parsing the request parameters in the modified data packet, processing according to the logic corresponding to the request, and writing the response data into the response data packet; sending the response data packet to the load balancer; modifying the source address and destination address in the response data packet, and sending the response data packet to the client; monitoring the number of connections of the back-end servers, and performing fault detection processing when the difference in the number of connections between any two back-end servers exceeds the delay limit threshold; when the IP address of the faulty server is received, outputting a fault repair signal, and sending a detection data packet to the faulty server at intervals of the first detection time.

[0103] Embodiment 3

[0104] In the third aspect, the present application provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in any of the above methods are executed. Through the above technical solution, when the computer program is executed by the processor, the method in any optional implementation of the above embodiment is executed to achieve the following functions: receiving a request data packet sent by a client, sending the request data packet to a load balancer; selecting a suitable backend server as a target server according to a load balancing algorithm, and modifying the source address and destination address in the request data packet, marking it as a modified data packet; sending the modified data packet to the target server; parsing the request parameters in the modified data packet, processing according to the logic corresponding to the request, and writing the response data into the response data packet; sending the response data packet to the load balancer; modifying the source address and destination address in the response data packet, and sending the response data packet to the client; monitoring the number of connections of the backend server, and performing fault detection processing when the difference in the number of connections between any two backend servers exceeds the delay limit threshold; when the IP address of the faulty server is received, outputting a fault repair signal, and sending a detection data packet to the faulty server at intervals of the first detection time.

[0105] It should be understood by those skilled in the art that the embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program codes. Wherein, the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, referred to as EPROM), programmable read-only memory (Programmable Red-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic memory, flash memory, disk or optical disk. 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 1A function specified in one or more boxes.

[0106] The above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A data packet processing method in LVS load balancing, characterized in that: The steps include: Step S1, receiving a request data packet sent by a client, and sending the request data packet to a load balancer; Step S2, selecting a suitable backend server as the target server according to the load balancing algorithm, and modifying the source address and destination address in the request data packet, marking it as a modified data packet; and sending the modified data packet to the target server; Step S3, parsing and modifying the request parameters in the data packet, processing according to the logic corresponding to the request, writing the response data into the response data packet; and sending the response data packet to the load balancer; The step S3 includes the following sub-steps: Step S3011, obtaining a modification data packet, parsing request data in the modification data packet, wherein the request data includes a request header, a request body, and request parameters; the request header includes a GET request method and a POST request method; The request body is the specific request content, wherein the request body of the GET request method is empty, and the request parameters are not empty; the request body of the POST request method contains request parameters; the request parameters are query strings; Step S3012, obtaining a request header; when a GET request method is obtained, outputting a GET request signal; when a POST request method is obtained, outputting a POST request signal; The step S3 further comprises the following sub-steps: Step S3021, receiving a request signal; Step S3022, when a GET request signal is received, the specific content in the server is queried according to the query string in the request parameter. When the specific content is successfully queried, the status code is 200, the response time and the specific response content are output; the data source address, the specific response content and the response time are encapsulated into a response data packet; the response data packet is sent to the load balancer; when the specific content is not queried, the status code is 404; the data source address and the status code are encapsulated into a response data packet; the response data packet is sent to the load balancer; Step S3023, when a POST request signal is received, the request body is obtained, and the specific content in the server is queried according to the request parameters in the request body. When the specific content is successfully queried, the status code is output as 200, and the response time and specific response content are output; the data source address, specific response content and response time are encapsulated into a response data packet; the response data packet is sent to the load balancer; when the specific content is not queried, the status code is output as 404; the data source address and status code are encapsulated into a response data packet; the response data packet is sent to the load balancer; Step S4, modifying the source address and the destination address in the response data packet, and sending the response data packet to the client; Step S5, monitoring the number of connections of the backend servers, and performing fault detection processing when the difference between the number of connections of any two backend servers exceeds a delay limit threshold; Step S6: When the IP address of the faulty server is received, a fault repair signal is output, and a detection data packet is sent to the faulty server at intervals of a first detection time.

2. The method for processing data packets in LVS load balancing according to claim 1, characterized in that: The step S1 includes the following sub-steps: Step S101, presetting a number of backend server IP addresses that can be loaded, wherein the backend servers have the same application program and data; Step S102, configuring the IP address of the load balancer as the address for the client to access the server; Step S103: When the client requests to access the server, the request data packet is sent to the IP address of the load balancer.

3. The method for processing data packets in LVS load balancing according to claim 2, characterized in that: The step S2 includes the following sub-steps: Step S201, numbering a number of backend servers from H1 to HN; wherein N is a positive integer and N is greater than 1; Step S202: When a request data packet is received, a target server is selected using a polling algorithm; the polling algorithm is configured as follows: Mark the IP addresses of the backend servers numbered from H1 to HN as the target IP addresses; obtain the IP address of the backend server numbered H1 and output the target IP address; when the second request data packet is received, obtain the IP address of the backend server numbered H2 and output the target IP address; and so on, when the N+1th request data packet is received, obtain the IP address of the backend server numbered H[(N+1)%N] and output the target IP address, where % is the remainder symbol, indicating that N+1 is the remainder of N; Step S203, write the source address of the request data packet into the request data packet and mark it as the data source address; modify the source address of the request data packet to the IP address of the load balancer, and modify the destination address to the target IP address; send the modified data packet to the target server.

4. The method for processing data packets in LVS load balancing according to claim 3, characterized in that: The step S4 includes the following sub-steps: Step S401, parsing a response data packet to obtain a data source address in the response data packet; Step S402, modifying the source address of the response data packet to the IP address of the target server, modifying the destination address of the response data packet to the data source address, and deleting the data source address; Step S403: Send the response data packet to the client.

5. The method for processing data packets in LVS load balancing according to claim 4, characterized in that: The step S5 comprises the following sub-steps: Step S5011, monitoring the number of connections of all backend servers, where the number of connections is the number of connections being processed by the backend servers; when the difference between the number of connections of any two backend servers is greater than the delay limit threshold, proceed to step S5012, otherwise no subsequent processing is performed; Step S5012, send a detection data packet to all backend servers. If the detection data packet receives a normal response, no processing is performed; if the detection data packet receives no response or receives an abnormal response, obtain the IP address of the backend server, mark it as a faulty server, and output the IP address of the faulty server.

6. The method for processing data packets in LVS load balancing according to claim 5, characterized in that: The step S5 further comprises the following sub-steps: Step S502: replace the polling algorithm in step S202 with a minimum connection number algorithm, and select a suitable backend server according to the minimum connection number algorithm; the minimum connection number algorithm is configured as follows: Obtain the number of connections of all backend servers, and sort the backend servers according to the number of connections. The number of the server with the least number of connections is L1, and the number of the server with the most number of connections is LM, where M is a positive integer and M is greater than 1; when there are several backend servers with the same number of connections, obtain the backend server numbers in step S201 and sort them from small to large according to the numbers; When receiving the request data packet, select the backend server with sequence number L1, mark it as the target server, and output the IP address of the target server; Monitor the number of connections of all backend servers again and re-sort the backend servers; The source address of the request data packet is modified to the IP address of the load balancer, and the destination address is modified to the IP address of the target server; the modified data packet is sent to the target server.

7. The method for processing data packets in LVS load balancing according to claim 6, characterized in that: The step S6 comprises the following sub-steps: Step S6011, receiving the IP address of the faulty server, and outputting an IP address signal and a fault repair signal; Step S6012, sending a detection data packet to the faulty server at a first detection time interval, and when a normal response is obtained, changing the faulty server to a maintenance server and outputting fault elimination information; When no response is obtained or an abnormal response is obtained, the detection data packet continues to be sent at intervals of the first detection time.

8. The method for processing data packets in LVS load balancing according to claim 7, characterized in that: The step S6 also includes the following sub-steps: Step S6021, when troubleshooting information is received, the connection numbers of all backend servers are obtained, the connection number of the backend server with the least number of connections is obtained, and marked as the target number; when a request data packet is received, the source address of the request data packet is modified to the IP address of the load balancer, and the destination address is modified to the IP address of the maintenance server; and the modified data packet is sent to the maintenance server; Step S6022, monitoring the number of connections to the maintenance server, when the number of connections to the maintenance server is equal to the target number, changing the maintenance server to a backend server, and replacing the minimum connection number algorithm in step S202 with a polling algorithm.

9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the steps in the method according to any one of claims 1 to 8 are executed.

10. A storage medium having a computer program stored thereon, 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 8 are executed.

Citation Information

Patent Citations

  • Data packet processing method and device in LVS load balancing

    CN113364660A

  • Load equalization implementing method, storage control equipment and memory system

    CN101345770A

  • Load balancing method, device and system

    CN111866064A