Message processing method and device for multi-server load balancing scene, electronic equipment and readable storage medium

By adopting message processing methods in multi-server load balancing scenarios, the problems of idle standby machines and stand-alone bottlenecks in traditional load balancing mode are solved, load balancing and rapid connection recovery are achieved, and system reliability and user experience are improved.

CN119583322AActive Publication Date: 2025-03-07HANGZHOU JUCHI NETWORK TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411685093.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-22
Publication Date
2025-03-07
Estimated Expiration
2044-11-22

AI Technical Summary

Technical Problem

In the traditional load balancing mode, the standby machine is idle during normal operation, wasting computing resources, and because all traffic relies on a single host to process, it is easy to cause problems such as stand-alone bottlenecks and service interruptions.

Method used

In a multi-server load balancing scenario, by setting multiple servers in the server group to share the same virtual IP address, the message processing method is adopted, including receiving messages, processing network layer messages, determining the target server for transport layer messages, processing and responding messages, recording and sharing connection information, so as to achieve load balancing and rapid recovery of connections.

Benefits of technology

It realizes rapid election and sharing of connection tables when the main server is unavailable, reduces server resource waste, avoids stand-alone bottlenecks and service interruptions, and improves system reliability and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119583322A_ABST
    Figure CN119583322A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of network communication, in particular to a message processing method and device for a multi-server load balancing scene, electronic equipment and a readable storage medium, and the method comprises the steps: receiving a message; when the message is a network layer message, the message is processed at the server; when the message is a transport layer message and the server is a main server, determining a target server for processing the message; and if the server is the auxiliary server and is designated as the main server when the main server is unavailable, acquiring a corresponding second connection table from other auxiliary servers in the server group to generate a first connection table of the server. According to the technical scheme, through connection table sharing among the server groups, under the condition that the server groups are not provided with standby servers, most connections of the main server can be quickly recovered, the influence of crash of the main server on user connections is reduced, and the resource utilization efficiency of the server groups is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of network communication technology, and in particular to a message processing method, device, electronic device and readable storage medium in a multi-server load balancing scenario. Background Art

[0002] In the Layer 2 network environment of modern data centers, the virtual IP function of traditional load balancing usually adopts the active-standby mode to achieve high availability. The host and the standby are assigned the same virtual IP address. The host sends a GARP (Gratuitous ARP) announcement to the switch to declare that it owns the virtual IP address and is willing to accept traffic sent to the virtual IP. In contrast, although the standby is configured with the virtual IP, it does not send any GARP messages and does not participate in processing any messages sent to the VIP. This design ensures that traffic is only directed to the active host. The host and the standby periodically exchange heartbeat signals. Once the standby detects that the host has failed or cannot work properly, the standby will immediately start and send a GARP message to the switch to declare itself as the new active host. Subsequently, the switch updates its MAC address table and directs the traffic sent to the virtual IP to the standby, thereby achieving host switching.

[0003] This model has some significant problems. First, the backup machine is actually idle during normal operation, wasting computing resources. Second, because all traffic relies on a single host to handle it, it is easy to cause a single-machine bottleneck problem. When traffic demand surges or traffic peaks occur, the host may be unable to handle all traffic due to resource limitations (such as CPU, memory, or network bandwidth), thus affecting the response speed and reliability of the service.

[0004] In addition, when switching between the primary and backup machines, a brief service interruption is inevitable. Although this interruption may only last for a few seconds, all connections on the original host may be affected, resulting in a degraded user experience. Summary of the invention

[0005] In order to solve the problems in the related art, the embodiments of the present disclosure provide a message processing method, device, electronic device and readable storage medium in a multi-server load balancing scenario.

[0006] In a first aspect, an embodiment of the present disclosure provides a method for processing a message in a multi-server load balancing scenario, the method being applied to a server in a server group, the server group comprising a plurality of servers, the plurality of servers being connected to a switch and having the same virtual IP address, the switch sending a message with a destination of the virtual IP address to a primary server among the plurality of servers, the method comprising:

[0007] Receive messages;

[0008] When the message is a network layer message, processing the message on the server;

[0009] When the message is a transport layer message and the server is the primary server, determining a target server for processing the message includes: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, and if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, and recording a corresponding relationship between the connection information and the target server in the first connection table;

[0010] If the target server is not the current server, sending the message to the target server;

[0011] Process the message whose target server is this server and send the response message back to the switch;

[0012] When the server is a secondary server, the connection information of the message processed by the server is recorded in the second connection table;

[0013] If the server is a secondary server and is designated as the primary server when the primary server is unavailable, the server obtains the corresponding second connection table from other secondary servers in the server group to generate its own first connection table;

[0014] If the server is a secondary server and is not designated as the primary server when the primary server is unavailable, the server sends its own second connection table to the secondary server designated as the primary server.

[0015] According to an embodiment of the present disclosure, allocating a target server to the message according to a preset rule includes:

[0016] Calculate a message hash value according to the connection information;

[0017] Obtain the number of servers in the server group;

[0018] The message hash value is modulo the number of servers to determine the target server of the transport layer message.

[0019] According to an embodiment of the present disclosure, the method further includes, if the server is a primary server and the secondary server is unavailable, performing the following operations:

[0020] When there is an idle server in the server group, modify the connection information in the first connection table that uses the auxiliary server as the target server to use the idle server as the target server;

[0021] When there is no idle server in the server group, the connection information in the first connection table that uses the auxiliary server as the target server is modified to use other servers in the server group as the target server.

[0022] According to an embodiment of the present disclosure, the method further includes:

[0023] Get the processor utilization of this server;

[0024] When the processor utilization exceeds a preset utilization threshold, obtaining a message ratio of a total number of messages per second of the server, a sub-number of messages per second of the connection information, and the total number of messages per second;

[0025] When the message ratio of the connection information exceeds a preset message ratio threshold, modifying the target server of the connection information to the current server and an idle server;

[0026] When the message ratio of the connection information does not exceed a preset message ratio threshold, one or more target servers of the connection information are modified to be the idle servers.

[0027] According to an embodiment of the present disclosure, the message is a network layer message, and processing the message on the server includes:

[0028] When the server is a secondary server, the network layer message is subjected to packet loss processing.

[0029] According to an embodiment of the present disclosure, the method further includes:

[0030] When the server is the main server and receives a message after receiving a service termination instruction, the following operations are performed:

[0031] Retrieving a server corresponding to the connection information of the message in the first connection table as the target server; if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, the target server does not include the current server;

[0032] If the target server of the message is the present server, processing the message on the present server and deleting the connection information in the first connection table at a preset deletion time;

[0033] If the target server of the message is not the current server, sending the message to the target server;

[0034] After the preset end time is reached, the first connection table is sent to the new main server and the server is shut down;

[0035] The service termination instruction is used to terminate the message processing service of the server after a preset termination time, and the preset deletion time is earlier than the preset termination time.

[0036] In a second aspect, an embodiment of the present disclosure provides a message processing device for a multi-server load balancing scenario, the device being applied to a server in a server group, the server group comprising a plurality of servers, the plurality of servers being connected to a switch and having the same virtual IP address, the switch sending a message with a destination of the virtual IP address to a primary server among the plurality of servers, the device comprising:

[0037] A receiving module, configured to receive messages;

[0038] A first processing module is configured to process the message on the server when the message is a network layer message;

[0039] a determination module configured to determine a target server for processing the message when the message is a transport layer message and the server is a primary server, including: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, and if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, and recording a correspondence between the connection information and the target server in the first connection table;

[0040] A first sending module, configured to send the message to the target server if the target server is not the current server;

[0041] The second processing module is configured to process the message that the target server is the current server and send a response message back to the switch;

[0042] a recording module, configured to record connection information of messages processed by the server in the second connection table when the server is a secondary server;

[0043] a generating module configured to obtain corresponding second connection tables from other secondary servers in the server group to generate its own first connection table if the server is a secondary server and is designated as the primary server when the primary server is unavailable;

[0044] The first sending module is configured to send its own second connection table to the auxiliary server designated as the main server if the server is an auxiliary server and is not designated as the main server when the main server is unavailable.

[0045] According to an embodiment of the present disclosure, the determining module includes:

[0046] A first calculation submodule is configured to calculate a message hash value according to the connection information;

[0047] An acquisition submodule, configured to acquire the number of servers in the server group;

[0048] The second calculation submodule is configured to perform a modulo calculation on the message hash value and the number of servers to determine a target server of the transport layer message.

[0049] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising a memory and a processor, wherein the memory is used to store one or more computer instructions, and wherein the one or more computer instructions are executed by the processor to implement a method as described in any one of the first aspects.

[0050] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed by a processor, the method described in the first aspect is implemented.

[0051] According to the technical solution provided by the embodiment of the present disclosure, applied to a server in a server group, the server group includes multiple servers, the multiple servers are connected to a switch and have the same virtual IP address, the switch sends a message with the destination being the virtual IP address to a main server among the multiple servers, the method includes: receiving a message; when the message is a network layer message, processing the message on the server; when the message is a transport layer message and the server is the main server, determining a target server for processing the message, including: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, and if no server corresponding to the connection information is retrieved, classifying the message according to a preset rule; a target server, and records the corresponding relationship between the connection information and the target server in the first connection table; if the target server is not the present server, sends the message to the target server; processes the message whose target server is the present server and sends the response message back to the switch; when the present server is the auxiliary server, records the connection information of the message processed by the present server in the second connection table; if the present server is the auxiliary server and is designated as the main server when the main server is unavailable, obtains the corresponding second connection table from other auxiliary servers in the server group to generate its own first connection table; if the present server is the auxiliary server and is not designated as the main server when the main server is unavailable, sends its own second connection table to the auxiliary server designated as the main server.

[0052] According to the technical solution of the present disclosure, by recording connection information in the first connection table and the second connection table, and when the main server is unavailable, a new main server can be elected in the auxiliary server and the connection table can be shared, so that most connections can be quickly restored, and the connections of most users are not affected by server failures, and there is no need to set up a backup server, thereby reducing the waste of server resources.

[0053] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Other features, objectives and advantages of the present disclosure will become more apparent through the following detailed description of non-limiting embodiments in conjunction with the accompanying drawings. In the accompanying drawings:

[0055] Figure 1 A schematic diagram of the entire process of a message processing method for a multi-server load balancing scenario according to an embodiment of the present disclosure is shown.

[0056] Figure 2 A flow chart of a method for processing messages in a multi-server load balancing scenario according to an embodiment of the present disclosure is shown.

[0057] Figure 3 A flowchart of primary server election in a message processing method for a multi-server load balancing scenario according to an embodiment of the present disclosure is shown.

[0058] Figure 4 A flowchart of a method for processing messages in a multi-server load balancing scenario according to another embodiment of the present disclosure is shown.

[0059] Figure 5 A structural block diagram of a message processing device for a multi-server load balancing scenario according to an embodiment of the present disclosure is shown.

[0060] Figure 6 A structural block diagram of a message processing device for a multi-server load balancing scenario according to another embodiment of the present disclosure is shown.

[0061] Figure 7 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown.

[0062] Figure 8 A schematic diagram showing the structure of a computer system suitable for implementing the method according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0063] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings so that those skilled in the art can easily implement them. In addition, for the sake of clarity, parts not related to the description of the exemplary embodiments are omitted in the accompanying drawings.

[0064] In the present disclosure, it should be understood that terms such as "include" or "have" are intended to indicate the presence of features, numbers, steps, behaviors, components, parts, or a combination thereof disclosed in the present specification, and are not intended to exclude the possibility that one or more other features, numbers, steps, behaviors, components, parts, or a combination thereof exist or are added.

[0065] It should also be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0066] In the present disclosure, if it involves operations of obtaining user information or user data or displaying user information or user data to others, the operations are all authorized and confirmed by the user, or actively selected by the user.

[0067] In the Layer 2 network environment of modern data centers, the virtual IP function of traditional load balancing usually adopts the active-standby mode to achieve high availability. The host and the standby are assigned the same virtual IP address, in which the host sends a GARP (Gratuitous ARP) announcement to the switch to declare that it owns the virtual IP address and is willing to accept traffic sent to the virtual IP. In contrast, although the standby is configured with the virtual IP, it does not send any GARP messages and does not participate in processing any messages sent to the VIP. This design ensures that traffic is only directed to the active host. The host and the standby periodically exchange heartbeat signals. Once the standby detects that the host has failed or is not working properly, the standby will immediately start and send a GARP message to the switch to declare itself as the new active host. Subsequently, the switch updates its MAC address table and directs the traffic sent to the virtual IP to the standby, thereby achieving seamless switching of the host.

[0068] This model has some significant problems. First, the backup machine is actually idle during normal operation, wasting computing resources. Second, because all traffic relies on a single host to handle it, it is easy to cause a single-machine bottleneck problem. When traffic demand surges or traffic peaks occur, the host may be unable to handle all traffic due to resource limitations (such as CPU, memory, or network bandwidth), thus affecting the response speed and reliability of the service.

[0069] In addition, when switching between the primary and backup machines, a brief service interruption is inevitable. Although this interruption may only last for a few seconds, all connections on the original host may be affected, resulting in a degraded user experience.

[0070] In order to solve the above technical problems, the present invention discloses a message processing method for a multi-server load balancing scenario, the method is applied to a server in a server group, the server group includes multiple servers, the multiple servers are connected to a switch and have the same virtual IP address, the switch sends a message with a destination of the virtual IP address to a main server among the multiple servers, the method includes: receiving a message; when the message is a network layer message, processing the message on the server; when the message is a transport layer message and the server is the main server, determining a target server for processing the message, including: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, if the server corresponding to the connection information is not retrieved, then The message is assigned a target server according to a preset rule, and the corresponding relationship between the connection information and the target server is recorded in the first connection table; if the target server is not the current server, the message is sent to the target server; the message whose target server is the current server is processed and a response message is sent back to the switch; when the current server is a secondary server, the connection information of the message processed by the current server is recorded in the second connection table; if the current server is a secondary server and is designated as the primary server when the primary server is unavailable, the corresponding second connection table is obtained from other secondary servers in the server group to generate its own first connection table; if the current server is a secondary server and is not designated as the primary server when the primary server is unavailable, the second connection table of the current server is sent to the secondary server designated as the primary server.

[0071] According to the technical solution of the present disclosure, by recording connection information in the first connection table and the second connection table, and when the main server is unavailable, a new main server can be elected in the auxiliary server and the connection table can be shared, so that most connections can be quickly restored, and the connections of most users are not affected by server failures, and there is no need to set up a backup server, thereby reducing the waste of server resources.

[0072] Figure 1 FIG. 1 is a schematic diagram showing the entire process of a method for processing packets in a multi-server load balancing scenario according to an embodiment of the present disclosure. Figure 1As shown, the message processing method is applied to a load balancing scenario, including a switch, server A as a main server, server B and server C as auxiliary servers, and servers A, B, and C form a server group and have the same virtual IP address. When the switch sends a network layer message to the server group, server A in the server group responds to the network layer message, and server A receives all traffic sent by the switch to the virtual IP address. After receiving the message sent by the switch, server A obtains the connection information of the message, retrieves the target server corresponding to the connection information in the first connection table of server A, and if the target server is server B, sends the message to the second connection table of server B for recording and processing by server B, and the processed response message is directly sent to the switch. If the target server corresponding to the connection information is not retrieved, the message is assigned to servers A, B, and C according to the preset rules, and then processed by the corresponding target server, and the generated response message does not need to be forwarded by the main server and is directly sent to the switch.

[0073] Figure 2 A flow chart showing a method for processing packets in a multi-server load balancing scenario according to an embodiment of the present disclosure is shown. Figure 2 As shown, the message processing method of the multi-server load balancing scenario is applied to a server in a server group, the server group includes multiple servers, the multiple servers are connected to a switch and have the same virtual IP address, and the switch sends a message with a destination of the virtual IP address to a main server among the multiple servers, including the following steps S101-S108:

[0074] In step S101, a message is received. The message is a data unit exchanged and transmitted in the network. In the present embodiment, the message includes a network layer message and a transport layer message. The network layer message is used to query the MAC address of the main server in the virtual IP address, or to transmit diagnostic and control information between network devices to help identify network problems. For example, the network layer message may be an ARP message or an ICMP message. The transport layer message is used to transmit actual business data, such as web browsing data, file transfer data, email data, database interaction data, etc. For example, the transport layer message may be a TCP message or a UDP message.

[0075] In step S102, when the message is a network layer message, the message is processed by the present server. As described above, the network layer message is used by the switch to query the MAC address of the server group in the virtual IP address, or to transmit diagnostic and control information between network devices so that the switch can communicate with the server group. The server group includes a main server and multiple auxiliary servers. The main server and the auxiliary servers use the same virtual IP address, and the MAC address of the main server is used as the MAC address bound to the virtual IP address, which is recorded and used by the switch. Therefore, when the switch needs the MAC address of the server group for communication, and the present server is the main server, the present server responds to the network layer message sent by the switch and provides the MAC address of the present server to the switch.

[0076] In step S103, when the message is a transport layer message and the server is a primary server, determining a target server for processing the message includes: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, and if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, and recording a correspondence between the connection information and the target server in the first connection table.

[0077] According to the implementation mode of the present disclosure, the transport layer message is used to transmit actual business data and can be processed by the main server or the auxiliary server. Before the transport layer message is processed, it is necessary to assign the corresponding main server or auxiliary server as the target server for the transport layer message, and send the transport layer message to the target server for processing to achieve the technical effect of load balancing between the servers in the server group. The first connection table is stored in the main server and is used to store the connection information of all messages received by the main server within a preset time period. The connection information includes one or more of the source address, destination address, source port, destination port, and protocol type of the message. When the main server receives the message, it will obtain the source address and port of the message, and record the MAC address and port of the server in the server group that specifically processes the message, so that when the same message is received again in the future, the corresponding server can be found to process the message to ensure the stability of the client connection. If the server does not retrieve the connection information corresponding to the message in the first connection table, it means that the message is received by the server for the first time. In order to meet the load balancing requirements, it is necessary to assign a processing server as the target server for the message received for the first time according to the preset rules, and after determining the target server, record the target server in the connection information corresponding to the message and store it in the first connection table so that it can be queried the next time the same message is received.

[0078] In step S104, if the target server is not the current server, the message is sent to the target server. When the current server retrieves the connection information of the message from the first connection table and finds that the target server in the connection information is not the current server, it means that the message has been received in the past period of time and has been assigned to be processed by other servers, so the message needs to be sent to the target server recorded in the connection information for processing.

[0079] In step S105, the message whose target server is the present server is processed and the response message is sent back to the switch. According to the connection information in the first connection table, if it is determined that the target server in the connection information is the present server, the message is processed by the present server. After the message is processed, a response message is generated and sent directly to the switch. Optionally, when the present server is a secondary server, the response message does not need to be sent to the primary server and then forwarded to the switch by the primary server, thereby improving the message processing efficiency and reducing the resource occupation of the primary server.

[0080] In step S106, when the server is an auxiliary server, the connection information of the message processed by the server is recorded in the second connection table. The second connection table is stored in the auxiliary server and is used to record the connection information of the message sent to the auxiliary server within a preset time period. The connection information includes one or more of the source address, destination address, source port, destination port, and protocol type of the message. When the auxiliary server receives the message, it will receive the source address and port of the message and record the MAC address and port of the auxiliary server so that when the same message is received again later, the message can be directly processed.

[0081] In step S107, if the server is a secondary server and is designated as the primary server when the primary server is unavailable, the corresponding second connection table is obtained from other secondary servers in the server group to generate its own first connection table. In the load balancing application scenario of the server group, when one of the servers in the server group suddenly fails and the server cannot continue to provide services, all connections connected to the server will be interrupted until the server is restored or the connection of the original server is migrated to the backup server, which will cause the connection to be interrupted, causing a bad impact on the user's experience. In the master-slave mode adopted by traditional load balancing technology, all connections in the damaged host are migrated to the backup machine, which will have a temporary interruption effect on all connections of the host. In order to avoid the interruption of all connections caused by the switching of the master and backup machines, this solution sets an architecture of a primary server and multiple secondary servers. When the primary server is unavailable, one of the secondary servers is elected as the new primary server. The new primary server obtains the corresponding second connection table from other servers, and forms its own first connection table based on the second connection tables of other secondary servers and the original second connection table of the new primary server. In this embodiment, the connection information missing from the first connection table in the newly elected primary server is only part of the connections actually processed by the original primary server. As for the connections processed by other servers, since the new first connection table synchronizes the connection information in other original second connection tables, the present server, i.e., the new primary server, can forward the original connections to other servers according to the new first connection table without causing connection interruption, and thus the user experience is not affected.

[0082] Figure 3 FIG. 1 is a flow chart showing the primary server election in the message processing method for a multi-server load balancing scenario according to an embodiment of the present disclosure. Figure 3 As shown, the control end is the control interface of the server group. The server group includes server A, server B, server C, and server D. In the initial state, server A is the main server, and servers B, C, and D are auxiliary servers. The control end periodically sends a health check instruction to the main server. When server A is damaged and unavailable, and the health check instruction is not responded to, server B is selected from multiple auxiliary servers as the new main server. Server B obtains the corresponding second connection table from server C and server D, and merges it with the original second connection table of server B into a new first connection table. Finally, server B reports to the control end that it is the new main server. In this embodiment, the new first connection table generated by server B contains all the connection information of servers B, C, and D, and only lacks the connection information of the original server A. It can be achieved that when the original main server A is damaged, 75% of the connections are not affected. Only the connection of the original server A needs to be reset, and there is no need to set up an idle standby machine. All servers can participate in traffic processing, thereby improving the utilization efficiency of the server group.

[0083] In step S108, if the server is a secondary server and is not designated as the primary server when the primary server is unavailable, the server sends its second connection table to the secondary server designated as the primary server. When the primary server is damaged and the server is a secondary server and is not selected as the primary server, upon receiving a connection table synchronization request for selecting a newly generated primary server, the server sends its second connection table to the new primary server.

[0084] According to an embodiment of the present disclosure, allocating a target server to the message according to a preset rule includes:

[0085] The message hash value is calculated according to the connection information. The message hash value is calculated according to the connection information of the message. For example, the hash value is calculated according to one or more of the source address, destination address, source port, destination port, and protocol type in the connection information.

[0086] Get the number of servers in the server group. The number of servers is the number of all servers in the server group, including the primary server and all secondary servers.

[0087] The message hash value is modulo the number of servers to determine the target server of the transport layer message. Hash value modulo is a distribution method that uses hash values ​​to determine the number of a specific server in a server group, thereby determining the target server and its MAC address. The calculation method is as follows:

[0088] ID=(hash%n); wherein ID is the server number, hash is the message hash value, n is the number of servers, and % is the modulo operation.

[0089] According to an embodiment of the present disclosure, the method further includes, if the server is a primary server and the secondary server is unavailable, performing the following operations:

[0090] When there is an idle server in the server group, the connection information in the first connection table with the auxiliary server as the target server is modified to use the idle server as the target server. The first connection table is a connection table used by the main server, which stores the connection information of all messages processed by the server group, including the connection information of the main server and the connection information of multiple auxiliary servers. When an auxiliary server in the server group fails and is unavailable, and there is an idle server in the server group, the idle server is used to replace the failed auxiliary server, and the target server of the connection information in the first connection table is modified from the failed auxiliary server to the idle server. When this server is the main server, the received message with the failed auxiliary server as the target server is directly forwarded to the idle server, so as to realize the seamless replacement of the auxiliary server and reduce the impact of the server failure on the user experience.

[0091] When there is no idle server in the server group, the connection information in the first connection table with the auxiliary server as the target server is modified to use other servers in the server group as the target server. If the auxiliary server is damaged and unavailable, and there is no idle server in the server group, the connection of the original auxiliary server cannot be migrated to the idle server as a whole, so it is necessary to split the connection of the faulty auxiliary server and assign it to other servers in the server group. The connection information in the first connection table with the target server as the faulty auxiliary server is modified to use other servers in the server group, which can be one or more servers in the other servers. When this server is the primary server and receives a message with the original auxiliary server as the target server, it can be directly forwarded to other servers in the server group, reducing the impact of the damage to the auxiliary server on user services.

[0092] Figure 4 A flow chart showing a method for processing packets in a multi-server load balancing scenario according to another embodiment of the present disclosure is shown. Figure 4 As shown, the method also includes:

[0093] In step S109, the processor utilization of the server is obtained.

[0094] In step S110, when the processor utilization exceeds the preset utilization threshold, the total number of messages per second of the server and the message ratio of the sub-messages per second of the connection information to the total number of messages per second are obtained. The preset utilization threshold is a pre-set warning value of the processor utilization. When the processor utilization reaches the utilization threshold, it means that the load of the server is high and the load of the server needs to be adjusted. The total number of messages per second is the number of all messages processed by the server per second. The message ratio of the sub-messages per second of the connection information to the total number of messages per second is used to measure the ratio of a single connection occupying server resources, and can screen out connections that occupy more server resources.

[0095] In step S111, when the message ratio of the connection information exceeds the preset message ratio threshold, the target server of the connection information is modified to the current server and the idle server. When the message ratio of the connection information exceeds the preset message ratio threshold, it means that the connection corresponding to the connection information occupies too much resources of the current server, which has a great impact on the load of the current server. For example, when the processor utilization rate is 90% and the message ratio of connection information A is 80%, it means that the connection corresponding to connection information A occupies 72% of the processor resources. For a single connection that occupies a high amount of server resources, the connection should be expanded, that is, the target server of the connection information is modified to the current server and the idle server, and multiple servers are used to jointly process the messages sent by the connection, so as to reduce the processor utilization rate of a single server.

[0096] In step S112, when the message ratio of the connection information does not exceed the preset message ratio threshold, one or more target servers of the connection information are modified to the idle server. When the processor of the server exceeds the preset utilization threshold, and the message ratio of no connection information exceeds the preset message ratio threshold, it means that the proportion of server resources used by any connection in the server is not high, and the high load of the server is caused by too many connections being processed. Therefore, the target servers of one or more connection information can be changed to idle servers, and one or more connections can be migrated to idle servers to reduce the load of the server.

[0097] According to an embodiment of the present disclosure, the message is a network layer message, and processing the message on the server includes:

[0098] When the server is a secondary server, the network layer message is dropped. As mentioned above, the primary server and the secondary server use the same virtual IP address, and the MAC address of the primary server is used as the MAC address bound to the virtual IP address, so the network layer message is responded by the primary server in the server group. When the server is a secondary server and receives a network layer message such as an ARP message or an ICMP message, the server performs packet loss processing to ensure that the network layer message is only responded by the primary server.

[0099] According to an embodiment of the present disclosure, the method further includes:

[0100] When the server is the main server and receives a message after receiving a service termination instruction, the following operations are performed:

[0101] Retrieving a server corresponding to the connection information of the message in the first connection table as the target server; if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, the target server does not include the current server;

[0102] If the target server of the message is the present server, processing the message on the present server and deleting the connection information in the first connection table at a preset deletion time;

[0103] If the target server of the message is not the current server, sending the message to the target server;

[0104] After the preset end time is reached, the first connection table is sent to the new main server and the server is shut down;

[0105] The service termination instruction is used to terminate the message processing service of the server after a preset termination time, and the preset deletion time is earlier than the preset termination time.

[0106] In this embodiment, when the server needs to be repaired or moved, the server needs to be shut down, but the services running on the server will be affected by the shutdown of the server. To solve this problem, after receiving the service termination instruction, the server classifies the received message. If the server corresponding to the connection information is not retrieved, it means that the message is received for the first time, and the message and the connection are assigned to other servers other than the server for processing, preventing new connections from entering the server. If the target server of the message is the server, it means that the message and the corresponding connection are the connections being processed by the server, and the server processes the message and deletes the connection information in the first connection table at the preset deletion time. In this way, when the server needs to be shut down, the connection running on the server can be reserved for a period of time to reduce the impact on the existing connection, and the new connection is forwarded to other servers to avoid the newly added connection affecting the termination operation of the server. After the preset termination time arrives, the first connection table of the server is sent to the new main server, so that the connection that still exists before the server is shut down can be transferred to the new main server, minimizing the impact of server changes on existing connections.

[0107] According to an implementation manner of the present disclosure, the primary server and the secondary server include a network card, and the network card can run a fast data path XDP (eXpress Data Path) including an extended Berkeley packet filter eBPF. Through eBPF and XDP, the message processing method of the present disclosure is applied to the network card and XDP. First, the messages received by the primary server and the secondary server are classified and filtered, and then handed over to the server for processing, which can reduce the load of the server and improve the data processing efficiency of the server.

[0108] Figure 5The structural block diagram of the message processing device in the multi-server load balancing scenario according to the embodiment of the present disclosure is shown. The device can be implemented as part or all of the electronic device through software, hardware or a combination of both.

[0109] like Figure 5 As shown, the message processing device 400 of the multi-server load balancing scenario is applied to the servers in the server group, and the server group includes multiple servers. The multiple servers are connected to a switch and have the same virtual IP address. The switch sends the message with the destination as the virtual IP address to the main server among the multiple servers. The device includes: a receiving module 410, a first processing module 420, a determination module 430, a first sending module 440, a second processing module 450, a recording module 460, a generation module 470, and a second sending module 480.

[0110] The receiving module 410 is configured to receive messages. The message is a data unit exchanged and transmitted in the network. In the present embodiment, the message includes a network layer message and a transport layer message. The network layer message is used to query the MAC address of the main server in the virtual IP address, or to transmit diagnostic and control information between network devices to help identify network problems. For example, the network layer message may be an ARP message or an ICMP message. The transport layer message is used to transmit actual business data, such as web browsing data, file transfer data, email data, database interaction data, etc. For example, the transport layer message may be a TCP message or a UDP message.

[0111] The first processing module 420 is configured to process the message on the present server when the message is a network layer message. As described above, the network layer message is used by the switch to query the MAC address of the server group in the virtual IP address, or to transmit diagnostic and control information between network devices so that the switch can communicate with the server group. The server group includes a main server and multiple auxiliary servers. The main server and the auxiliary servers use the same virtual IP address, and the MAC address of the main server is used as the MAC address bound to the virtual IP address, which is recorded and used by the switch. Therefore, when the switch needs the MAC address of the server group for communication, and the present server is the main server, the present server responds to the network layer message sent by the switch and provides the MAC address of the present server to the switch.

[0112] The determination module 430 is configured to determine a target server for processing the message when the message is a transport layer message and the server is a primary server, including: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, and if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, and recording a correspondence between the connection information and the target server in the first connection table.

[0113] According to the implementation mode of the present disclosure, the transport layer message is used to transmit actual business data and can be processed by the main server or the auxiliary server. Before the transport layer message is processed, it is necessary to assign the corresponding main server or auxiliary server as the target server for the transport layer message, and send the transport layer message to the target server for processing to achieve the technical effect of load balancing between the servers in the server group. The first connection table is stored in the main server and is used to store the connection information of all messages received by the main server within a preset time period. The connection information includes one or more of the source address, destination address, source port, destination port, and protocol type of the message. When the main server receives the message, it will obtain the source address and port of the message, and record the MAC address and port of the server in the server group that specifically processes the message, so that when the same message is received again in the future, the corresponding server can be found to process the message to ensure the stability of the client connection. If the server does not retrieve the connection information corresponding to the message in the first connection table, it means that the message is received by the server for the first time. In order to meet the load balancing requirements, it is necessary to assign a processing server as the target server for the message received for the first time according to the preset rules, and after determining the target server, record the target server in the connection information corresponding to the message and store it in the first connection table so that it can be queried the next time the same message is received.

[0114] The first sending module 440 is configured to send the message to the target server if the target server is not the server. When the server retrieves the connection information of the message from the first connection table and finds that the target server in the connection information is not the server, it means that the message has been received in the past period of time and has been assigned to be processed by other servers, so the message needs to be sent to the target server recorded in its connection information.

[0115] The second processing module 450 is configured to process the message that the target server is the server and send the response message back to the switch. According to the connection information in the first connection table, if it is determined that the target server in the connection information is the server, the message is processed by the server. After the message is processed, a response message is generated, and the response message is directly sent to the switch. Optionally, when the server is a secondary server, the response message does not need to be sent to the primary server and then forwarded to the switch by the primary server, thereby improving the message processing efficiency and reducing the resource occupation of the primary server.

[0116] The recording module 460 is configured to record the connection information of the message processed by the server in the second connection table when the server is the auxiliary server. The second connection table is stored in the auxiliary server and is used to record the connection information of the message sent to the auxiliary server within a preset time period. The connection information includes one or more of the source address, destination address, source port, destination port, and protocol type of the message. When the auxiliary server receives the message, it will receive the source address and port of the message and record the MAC address and port of the auxiliary server so that when the same message is received again later, the message can be directly processed.

[0117] The generation module 470 is configured to obtain the corresponding second connection table from other auxiliary servers in the server group to generate its own first connection table if the server is an auxiliary server and is designated as the main server when the main server is unavailable. In the load balancing application scenario of the server group, when one of the servers in the server group suddenly fails and the server cannot continue to provide services, all connections connected to the server will be interrupted until the server is restored or the connection of the original server is migrated to the backup server, which will cause the connection to be interrupted, causing a bad impact on the user's experience. In the master-slave mode adopted by traditional load balancing technology, migrating all connections in the damaged host to the backup machine will have a temporary interruption effect on all connections of the host. In order to avoid the interruption of all connections caused by the switching of the master and backup machines, this solution sets an architecture of a main server and multiple auxiliary servers. When the main server is unavailable, one of the auxiliary servers is selected as the main server, that is, this server. This server obtains the corresponding second connection table from other servers, and forms its own first connection table based on the second connection table of other auxiliary servers and the original second connection table of this server. In this embodiment, the connection information missing from the first connection table in the newly elected primary server is only part of the connections actually processed by the original primary server. As for the connections processed by other servers, since the new first connection table synchronizes the connection information in other original second connection tables, the present server, i.e., the new primary server, can forward the original connections to other servers according to the new first connection table without causing connection interruption, and thus the user experience is not affected.

[0118] The second sending module 480 is configured to send its second connection table to the auxiliary server designated as the main server if the server is an auxiliary server and is not designated as the main server when the main server is unavailable. When the main server is damaged and the server is an auxiliary server and is not selected as the main server, the server sends its second connection table to the new main server when receiving a connection table synchronization request for selecting a new main server.

[0119] According to an embodiment of the present disclosure, the determination module 430 includes:

[0120] The first calculation submodule is configured to calculate a message hash value according to the connection information. The message hash value is calculated according to the connection information of the message. For example, the hash value is calculated according to one or more of the source address, destination address, source port, destination port, and protocol type in the connection information.

[0121] The acquisition submodule is configured to acquire the number of servers in the server group. The number of servers is the number of all servers in the server group, including the main server and all auxiliary servers.

[0122] The second calculation submodule is configured to perform a modulo calculation on the message hash value and the number of servers to determine the target server of the transport layer message. Hash value modulo is a distribution method that uses the hash value to determine the number of a specific server in the server group, thereby determining the target server and its MAC address. The calculation method is as follows:

[0123] ID=(hash%n); wherein ID is the server number, hash is the message hash value, n is the number of servers, and % is the modulo operation.

[0124] According to an embodiment of the present disclosure, if the server is a primary server and the secondary server is unavailable, the device further includes:

[0125] The modification module is configured to modify the connection information in the first connection table with the auxiliary server as the target server to the idle server as the target server when there is an idle server in the server group. The first connection table is a connection table used by the main server, which stores the connection information of all messages processed by the server group, including the connection information of the main server and the connection information of multiple auxiliary servers. When the auxiliary server in the server group fails and is unavailable, and there is an idle server in the server group, the idle server is used to replace the unavailable auxiliary server, and the target server of the connection information in the first connection table is modified from the original auxiliary server to the idle server. When this server is the main server, the received message with the original auxiliary server as the target server is directly forwarded to the idle server, so as to realize the seamless replacement of the auxiliary server and reduce the impact of server failure on user experience.

[0126] When there is no idle server in the server group, the connection information in the first connection table with the auxiliary server as the target server is modified to use other servers in the server group as the target server. If the auxiliary server is damaged and unavailable, and there is no idle server in the server group, the connection of the original auxiliary server cannot be migrated to the idle server as a whole, so it is necessary to split the connection of the original auxiliary server and assign it to other servers in the server group. The connection information in the first connection table with the target server as the original auxiliary server is modified to use other servers in the server group, which can be one or more servers in the other servers. When this server is the main server and receives a message with the original auxiliary server as the target server, it can be directly forwarded to other servers in the server group, reducing the impact of the damage to the auxiliary server on user services.

[0127] Figure 6 FIG. 2 is a block diagram showing a structure of a message processing device for a multi-server load balancing scenario according to another embodiment of the present disclosure. Figure 6 As shown, the device also includes:

[0128] The first acquisition module 490 is configured to acquire the processor utilization of the server.

[0129] The second acquisition module 410 is configured to obtain the total number of messages per second of the server and the message ratio of the sub-messages per second of the connection information to the total number of messages per second when the processor utilization exceeds the preset utilization threshold. The preset utilization threshold is a pre-set warning value of the processor utilization. When the processor utilization reaches the utilization threshold, it means that the load of the server is high and the load of the server needs to be adjusted. The total number of messages per second is the number of all messages processed by the server per second. The message ratio of the sub-messages per second of the connection information to the total number of messages per second is used to measure the ratio of a single connection occupying server resources, and can screen out connections that occupy more server resources.

[0130] The first modification module 411 is configured to modify the target server of the connection information to the current server and the idle server when the message ratio of the connection information exceeds the preset message ratio threshold. When the message ratio of the connection information exceeds the preset message ratio threshold, it means that the connection corresponding to the connection information occupies too much resources of the current server, which has a great impact on the load of the current server. For example, when the processor utilization rate is 90% and the message ratio of connection information A is 80%, it means that the connection corresponding to connection information A occupies 72% of the processor resources. For a single connection that occupies a high amount of server resources, the connection should be expanded, that is, the target server of the connection information should be modified to the current server and the idle server, and multiple servers are used to jointly process the messages sent by the connection to reduce the processor utilization of a single server.

[0131] The second modification module 412 is configured to modify one or more target servers of the connection information to the idle server when the message ratio of the connection information does not exceed the preset message ratio threshold. When the processor of the server exceeds the preset utilization threshold, and the message ratio of no connection information exceeds the preset message ratio threshold, it means that the proportion of server resources used by any connection in the server is not high, and the high load of the server is caused by too many connections being processed. Therefore, the target servers of one or more connection information can be changed to idle servers, and one or more connections can be migrated to idle servers to reduce the load of the server.

[0132] According to an embodiment of the present disclosure, the message is a network layer message, and processing the message on the server includes:

[0133] When the server is a secondary server, the network layer message is dropped. As mentioned above, the primary server and the secondary server use the same virtual IP address, and the MAC address of the primary server is used as the MAC address bound to the virtual IP address, so the network layer message is responded by the primary server in the server group. When the server is a secondary server and receives a network layer message such as an ARP message or an ICMP message, the server performs packet loss processing to ensure that the network layer message is only responded by the primary server.

[0134] According to an embodiment of the present disclosure, the device further includes:

[0135] a retrieval module configured to retrieve a server corresponding to the connection information of the message in the first connection table as the target server; if no server corresponding to the connection information is retrieved, assign a target server to the message according to a preset rule, and the target server does not include the current server;

[0136] A third processing module is configured to process the message on the server if the target server of the message is the server, and delete the connection information in the first connection table at a preset deletion time;

[0137] A second sending module is configured to send the message to the target server if the target server of the message is not the current server;

[0138] A third sending module is configured to send the first connection table to a new primary server and shut down the server after a preset end time is reached;

[0139] The service termination instruction is used to terminate the message processing service of the server after a preset termination time, and the preset deletion time is earlier than the preset termination time.

[0140] In this embodiment, when the server needs to be repaired or moved, the server needs to be shut down, but the services running on the server will be affected by the shutdown of the server. To solve this problem, after receiving the service termination instruction, the server classifies the received message. If the server corresponding to the connection information is not retrieved, it means that the message is received for the first time, and the message and the connection are assigned to other servers other than the server for processing, preventing new connections from entering the server. If the target server of the message is the server, it means that the message and the corresponding connection are the connections being processed by the server, and the server processes the message and deletes the connection information in the first connection table at the preset deletion time. In this way, when the server needs to be shut down, the connection running on the server can be reserved for a period of time to reduce the impact on the existing connection, and the new connection is forwarded to other servers to avoid the newly added connection affecting the termination operation of the server. After the preset termination time arrives, the first connection table of the server is sent to the new main server, so that the connection that still exists before the server is shut down can be transferred to the new main server, minimizing the impact of server changes on existing connections.

[0141] The present disclosure also discloses an electronic device, Figure 7 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown.

[0142] like Figure 7 As shown, the electronic device includes a memory and a processor, wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method according to the embodiment of the present disclosure. The method is applied to a server in a server group, the server group includes multiple servers, the multiple servers are connected to a switch and have the same virtual IP address, the switch sends a message with the destination of the virtual IP address to a main server among the multiple servers, and the method includes:

[0143] Receive messages;

[0144] When the message is a network layer message, processing the message on the server;

[0145] When the message is a transport layer message and the server is the primary server, determining a target server for processing the message includes: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, and if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, and recording a corresponding relationship between the connection information and the target server in the first connection table;

[0146] If the target server is not the current server, sending the message to the target server;

[0147] Process the message whose target server is this server and send the response message back to the switch;

[0148] When the server is a secondary server, the connection information of the message processed by the server is recorded in the second connection table;

[0149] If the server is a secondary server and is designated as the primary server when the primary server is unavailable, the server obtains the corresponding second connection table from other secondary servers in the server group to generate its own first connection table;

[0150] If the server is a secondary server and is not designated as the primary server when the primary server is unavailable, the server sends its own second connection table to the secondary server designated as the primary server.

[0151] The allocating a target server to the message according to a preset rule includes:

[0152] Calculate a message hash value according to the connection information;

[0153] Obtain the number of servers in the server group;

[0154] The message hash value is modulo the number of servers to determine the target server of the transport layer message.

[0155] The method further includes, if the server is a primary server and the secondary server is unavailable, performing the following operations:

[0156] When there is an idle server in the server group, modify the connection information in the first connection table that uses the auxiliary server as the target server to use the idle server as the target server;

[0157] When there is no idle server in the server group, the connection information in the first connection table that uses the auxiliary server as the target server is modified to use other servers in the server group as the target server.

[0158] The method further comprises:

[0159] Get the processor utilization of this server;

[0160] When the processor utilization exceeds a preset utilization threshold, obtaining a message ratio of a total number of messages per second of the server, a sub-number of messages per second of the connection information, and the total number of messages per second;

[0161] When the message ratio of the connection information exceeds a preset message ratio threshold, modifying the target server of the connection information to the current server and an idle server;

[0162] When the message ratio of the connection information does not exceed a preset message ratio threshold, one or more target servers of the connection information are modified to be the idle servers.

[0163] If the message is a network layer message, the server processes the message, including:

[0164] When the server is a secondary server, the network layer message is subjected to packet loss processing.

[0165] The method further comprises:

[0166] When the server is the main server and receives a message after receiving a service termination instruction, the following operations are performed:

[0167] Retrieving a server corresponding to the connection information of the message in the first connection table as the target server; if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, the target server does not include the current server;

[0168] If the target server of the message is the present server, processing the message on the present server and deleting the connection information in the first connection table at a preset deletion time;

[0169] If the target server of the message is not the current server, sending the message to the target server;

[0170] After the preset end time is reached, the first connection table is sent to the new main server and the server is shut down;

[0171] The service termination instruction is used to terminate the message processing service of the server after a preset termination time, and the preset deletion time is earlier than the preset termination time.

[0172] Figure 8 A schematic diagram showing the structure of a computer system suitable for implementing the method according to an embodiment of the present disclosure is shown.

[0173] like Figure 8As shown, the computer system includes a processing unit, which can perform the various methods in the above-mentioned embodiments according to the program stored in the read-only memory (ROM) or the program loaded from the storage part into the random access memory (RAM). In the RAM, various programs and data required for the operation of the computer system are also stored. The processing unit, ROM and RAM are connected to each other through a bus. The input / output (I / O) interface is also connected to the bus.

[0174] The following components are connected to the I / O interface: an input part including a keyboard, a mouse, etc.; an output part including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage part including a hard disk, etc.; and a communication part including a network interface card such as a LAN card, a modem, etc. The communication part performs a communication process via a network such as the Internet. The drive is also connected to the I / O interface as needed. Removable media, such as disks, optical disks, magneto-optical disks, semiconductor memories, etc., are installed on the drive as needed so that the computer program read therefrom is installed into the storage part as needed. Among them, the processing unit can be implemented as a processing unit such as a CPU, a GPU, a TPU, an FPGA, an NPU, etc.

[0175] In particular, according to an embodiment of the present disclosure, the method described above can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program tangibly contained on a machine-readable medium, and the computer program includes a program code for executing the above method. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part, and / or installed from a removable medium.

[0176] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0177] The units or modules involved in the embodiments described in the present disclosure may be implemented by software or programmable hardware. The units or modules described may also be set in a processor, and the names of these units or modules do not constitute limitations on the units or modules themselves in some cases.

[0178] As another aspect, the present disclosure further provides a computer-readable storage medium, which may be a computer-readable storage medium included in the electronic device or computer system in the above embodiment; or a computer-readable storage medium that exists independently and is not assembled into a device. The computer-readable storage medium stores one or more programs, and the programs are used by one or more processors to execute the method described in the present disclosure.

[0179] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present disclosure is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other.

Claims

1. A message processing method for a multi-server load balancing scenario, characterized in that: The method is applied to a server in a server group, the server group includes a plurality of servers, the plurality of servers are connected to a switch and have the same virtual IP address, the switch sends a message with the destination of the virtual IP address to a main server among the plurality of servers, the method includes: Receive messages; When the message is a network layer message, processing the message on the server; When the message is a transport layer message and the server is the primary server, determining a target server for processing the message includes: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, and if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, and recording a corresponding relationship between the connection information and the target server in the first connection table; If the target server is not the current server, sending the message to the target server; Process the message whose target server is this server and send the response message back to the switch; When the server is a secondary server, the connection information of the message processed by the server is recorded in the second connection table; If the server is a secondary server and is designated as the primary server when the primary server is unavailable, the server obtains the corresponding second connection table from other secondary servers in the server group to generate its own first connection table; If the server is a secondary server and is not designated as the primary server when the primary server is unavailable, the server sends its own second connection table to the secondary server designated as the primary server.

2. The method according to claim 1, characterized in that The allocating a target server to the message according to a preset rule includes: Calculate a message hash value according to the connection information; Obtain the number of servers in the server group; The message hash value is modulo the number of servers to determine the target server of the transport layer message.

3. The method according to claim 1, characterized in that The method further includes, if the server is a primary server and the secondary server is unavailable, performing the following operations: When there is an idle server in the server group, modify the connection information in the first connection table that uses the auxiliary server as the target server to use the idle server as the target server; When there is no idle server in the server group, the connection information in the first connection table that uses the auxiliary server as the target server is modified to use other servers in the server group as the target server.

4. The method according to claim 1, characterized in that: The method further comprises: Get the processor utilization of this server; When the processor utilization exceeds a preset utilization threshold, obtaining a message ratio of a total number of messages per second of the server, a sub-number of messages per second of the connection information, and the total number of messages per second; When the message ratio of the connection information exceeds a preset message ratio threshold, modifying the target server of the connection information to the current server and an idle server; When the message ratio of the connection information does not exceed a preset message ratio threshold, one or more target servers of the connection information are modified to be the idle servers.

5. The method according to claim 1, characterized in that If the message is a network layer message, the server processes the message, including: When the server is a secondary server, the network layer message is subjected to packet loss processing.

6. The method according to claim 1, characterized in that The method further comprises: When the server is the main server and receives a message after receiving a service termination instruction, the following operations are performed: Retrieving a server corresponding to the connection information of the message in the first connection table as the target server; if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, the target server does not include the current server; If the target server of the message is the present server, processing the message on the present server and deleting the connection information in the first connection table at a preset deletion time; If the target server of the message is not the current server, sending the message to the target server; After the preset end time is reached, the first connection table is sent to the new main server and the server is shut down; The service termination instruction is used to terminate the message processing service of the server after a preset termination time, and the preset deletion time is earlier than the preset termination time.

7. A message processing device for a multi-server load balancing scenario, characterized in that: The device is applied to a server in a server group, the server group includes multiple servers, the multiple servers are connected to a switch and have the same virtual IP address, the switch sends a message with the destination of the virtual IP address to a main server among the multiple servers, and the device includes: A receiving module, configured to receive messages; A first processing module is configured to process the message on the server when the message is a network layer message; a determination module configured to determine a target server for processing the message when the message is a transport layer message and the server is a primary server, including: obtaining connection information of the message; retrieving a server corresponding to the connection information in a first connection table as the target server, and if no server corresponding to the connection information is retrieved, assigning a target server to the message according to a preset rule, and recording a correspondence between the connection information and the target server in the first connection table; A first sending module, configured to send the message to the target server if the target server is not the current server; The second processing module is configured to process the message that the target server is the current server and send a response message back to the switch; a recording module, configured to record connection information of messages processed by the server in the second connection table when the server is a secondary server; a generating module configured to obtain corresponding second connection tables from other secondary servers in the server group to generate its own first connection table if the server is a secondary server and is designated as the primary server when the primary server is unavailable; The second sending module is configured to send its own second connection table to the auxiliary server designated as the main server if the server is an auxiliary server and is not designated as the main server when the main server is unavailable.

8. The device according to claim 7, characterized in that The determining module comprises: A first calculation submodule is configured to calculate a message hash value according to the connection information; An acquisition submodule, configured to acquire the number of servers in the server group; The second calculation submodule is configured to perform a modulo calculation on the message hash value and the number of servers to determine a target server of the transport layer message.

9. An electronic device, characterized in that: The method comprises a memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method steps described in any one of claims 1-6.

10. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by a processor, the method steps described in any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Load balancing method and system and storage medium

    CN109818997A

  • Message transmission method, device and system

    CN113691589A

  • Server allocation method and device, electronic equipment and computer readable storage medium

    CN118200321A

  • Message processing method and device and electronic equipment

    CN118413483A

  • Communication failure recover method of parallel-connecte server system

    KR1020150124642A