Message processing method and device for multi-server load balancing scenario, electronic equipment and readable storage medium
By recording the first and second connection tables of connection information in the server group, dynamically electing the master server and sharing the connection table, the problems of resource waste and service interruption in traditional multi-server load balancing are solved, and efficient load balancing and fast connection recovery are achieved.
Patent Information
- Application Number
- CN202411685093.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2044-11-22
AI Technical Summary
In traditional multi-server load balancing, the backup server is idle during normal operation, wasting computing resources. In addition, the reliance on a single host to handle traffic can easily lead to single-server bottlenecks and service interruptions, affecting response speed and reliability.
By recording the first and second connection tables of connection information in the server group, the primary server is dynamically elected, and the connection table is shared among the secondary servers when the primary server is unavailable, load balancing and rapid connection recovery are achieved, avoiding the waste of backup servers.
It reduces server resource waste, improves load balancing efficiency, reduces the impact of service interruptions on user experience, and maintains the stability of most connections.
Smart Images

Figure CN119583322B_ABST
Abstract
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, traditional load balancing's virtual IP functionality typically uses a master-slave model to achieve high availability. Both the master and slave are assigned the same virtual IP address. The master sends a GARP (Gratuitous ARP) announcement to the switch, declaring its ownership of the virtual IP address and its willingness to accept traffic destined for it. Conversely, the slave, while configured with the virtual IP, does not send any GARP messages and does not participate in processing any packets destined for the VIP. This design ensures that traffic is directed only to the active master. The master and slave periodically exchange heartbeat signals. If the slave detects a master failure or malfunction, it immediately starts up and sends a GARP message to the switch, declaring itself the new active master. The switch then updates its MAC address table to redirect traffic destined for the virtual IP address to the slave, thus enabling master failover.
[0003] This model has some significant problems. First, the backup server is effectively idle during normal operation, wasting computing resources. Second, because all traffic relies on a single host to handle it, it can easily lead to single-server bottlenecks. When traffic demand surges or peaks occur, the host may be unable to handle all traffic due to resource constraints (such as CPU, memory, or network bandwidth), affecting service responsiveness and reliability.
[0004] Furthermore, when switching between the primary and backup servers, a brief service interruption is inevitable. While this interruption may only last a few seconds, all connections on the original server 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 packets in a multi-server load balancing scenario. The method is applied to a server in a server group, wherein the server group includes multiple servers connected to a switch and having the same virtual IP address. The switch sends a packet destined for the virtual IP address to a master server among the multiple servers. The method includes:
[0007] Receive messages;
[0008] When the message is a network layer message, processing the message on the local server;
[0009] When the message is a transport layer message and the current server is the primary server, determining a target server for processing the message includes: obtaining connection information of the message; searching a first connection table for a server corresponding to the connection information as the target server; if no server corresponding to the connection information is found, 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;
[0010] If the target server is not the current server, sending the message to the target server;
[0011] Processes the message whose target server is the current server and sends 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 corresponding second connection tables 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] Perform a modulo calculation on the message hash value and 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 current server is the 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 target servers.
[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 the total number of messages per second of the server, the number of sub-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, if the message is a network layer message, 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 primary 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 not including the current server;
[0032] If the target server of the message is the current server, processing the message on the current 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 expiration time is reached, the first connection table is sent to the new primary server and the current 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 including multiple servers connected to a switch and having the same virtual IP address, the switch sending a message destined for the virtual IP address to a master server among the multiple 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, when the message is a transport layer message and the current server is a primary server, determine a target server for processing the message, comprising: obtaining connection information of the message; searching a first connection table for a server corresponding to the connection information 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, 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] a second processing module configured to process a message indicating 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 secondary server designated as the primary server if the server is a secondary server and is not designated as the primary server when the primary 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 the 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 master server among the multiple servers, the method includes: receiving a message; when the message is a network layer message, processing the message on the current server; when the message is a transport layer message and the current server is the master 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; The switch allocates 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 current server, sends the message to the target server; processes the message whose target server is the current server and sends a response message back to the switch; when the current server is a secondary server, records the connection information of the message processed by the current server 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, obtains the corresponding second connection table 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, sends its own second connection table to the secondary server designated as the primary server.
[0052] According to the technical solution disclosed herein, by recording connection information in the first connection table and the second connection table, and when the primary server is unavailable, a new primary server can be elected from the secondary server and the connection table can be shared. This allows most connections to be quickly restored, keeping the connections of most users unaffected by server failures, eliminating the need to set up a backup server, and reducing server resource waste.
[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 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 in a multi-server load balancing scenario according to an embodiment of the present disclosure is shown.
[0056] Figure 2 A flowchart of a method for processing packets in a multi-server load balancing scenario according to an embodiment of the present disclosure is shown.
[0057] Figure 3 A flowchart of master 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 packets 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 in 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, actions, components, parts, or combinations thereof disclosed in the present specification, and are not intended to exclude the possibility that one or more other features, numbers, steps, actions, components, parts, or combinations thereof exist or are added.
[0065] It should also be noted that, in the absence of conflict, the embodiments and features of 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 this disclosure, if it involves operations of obtaining user information or user data or displaying user information or user data to others, such operations are all authorized and confirmed by the user, or actively selected by the user.
[0067] In modern data center Layer 2 network environments, traditional load balancing typically uses a master-slave model for virtual IP functionality to achieve high availability. Both the master and slave servers are assigned the same virtual IP address. The master sends a GARP (Gratuitous ARP) advertisement to the switch, declaring its ownership of the virtual IP address and its willingness to accept traffic destined for it. In contrast, the slave server, while configured with the virtual IP, does not send any GARP messages and does not participate in processing any packets destined for the VIP. This design ensures that traffic is directed only to the active master. The master and slave servers periodically exchange heartbeat signals. If the slave server detects a master failure or malfunction, it immediately starts up and sends a GARP message to the switch, announcing itself as the new active master. The switch then updates its MAC address table to redirect traffic destined for the virtual IP address to the slave server, achieving seamless master failover.
[0068] This model has some significant problems. First, the backup server is effectively idle during normal operation, wasting computing resources. Second, because all traffic relies on a single host to handle it, it can easily lead to single-server bottlenecks. When traffic demand surges or peaks occur, the host may be unable to handle all traffic due to resource constraints (such as CPU, memory, or network bandwidth), affecting service responsiveness and reliability.
[0069] Furthermore, when switching between the primary and backup servers, a brief service interruption is inevitable. While this interruption may only last a few seconds, all connections on the original server 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 being applied to servers in a server group, the server group including multiple servers, the multiple 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 master server among the multiple servers, the method comprising: receiving a message; when the message is a network layer message, processing the message on the current server; when the message is a transport layer message and the current server is the master server, determining a target server for processing the message, comprising: 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, then The switch allocates a target server to the message according to a preset rule, 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 current server, sends the message to the target server; processes the message whose target server is the current server and sends a response message back to the switch; when the current server is a secondary server, records the connection information of the message processed by the current server 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, obtains the corresponding second connection table 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, sends its own second connection table to the secondary server designated as the primary server.
[0071] According to the technical solution disclosed herein, by recording connection information in the first connection table and the second connection table, and when the primary server is unavailable, a new primary server can be elected from the secondary server and the connection table can be shared. This allows most connections to be quickly restored, keeping the connections of most users unaffected by server failures, eliminating the need to set up a backup server, and reducing server resource waste.
[0072] Figure 1 FIG. 1 is a schematic diagram showing the entire process of a message processing method for 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 the primary server, and server B and server C as secondary servers. 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 and searches for the target server corresponding to the connection information in server A's first connection table. If the target server is server B, the message is sent to server B's second connection table for recording and processing by server B. The processed response message is sent directly to the switch. If the target server corresponding to the connection information is not retrieved, the message is distributed to servers A, B, and C according to preset rules, and then processed by the corresponding target server. The generated response message does not need to be forwarded by the primary server and is sent directly to the switch.
[0073] Figure 2 Flowchart showing a method for processing packets in a multi-server load balancing scenario according to an embodiment of the present disclosure. Figure 2 As shown, the message processing method of the multi-server load balancing scenario is applied to a server in a server group, wherein 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 destined for the virtual IP address to a master 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 this 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 primary 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 can 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 can be a TCP message or a UDP message.
[0075] In step S102, when the packet is a network layer packet, the packet is processed by the server. As described above, the network layer packet is used for the switch to query the MAC address of the server group in the virtual IP address, or is used for the delivery of diagnostic and control information between network devices, so that the switch communicates with the server group. The server group includes a primary server and a plurality of secondary servers, the primary server and the secondary servers use the same virtual IP address, and the MAC address of the primary server is bound as the MAC address of 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 server is the primary server, the server answers the network layer packet sent by the switch, and provides the MAC address of the server to the switch.
[0076] In step S103, when the packet is a transport layer packet and the server is the primary server, a target server for processing the packet is determined, including: obtaining connection information of the packet; searching for a server corresponding to the connection information in a first connection table as the target server, if no server corresponding to the connection information is searched, assigning a target server for the packet according to a preset rule, and recording a corresponding relationship between the connection information and the target server in the first connection table.
[0077] According to the embodiment of the present disclosure, the transport layer packet is used for transmitting actual service data, and can be processed by the primary server or the secondary server. Before processing, the transport layer packet needs to be assigned with a corresponding primary server or secondary server as a target server, and the transport layer packet is sent to the target server for processing, so as to realize the technical effect of load balancing among the servers in the server group. The first connection table is stored in the primary server, and is used for storing connection information of all packets received by the primary server within a preset time period. The connection information includes one or more of a source address, a destination address, a source port, a destination port, and a protocol type of the packet. When the primary server receives the packet, the source address and the port of the packet are obtained, and the MAC address and the port of the server in the server group which specifically processes the packet are recorded, so that the corresponding server can be found to process the packet when the same packet is received again in the future, so as to ensure the stability of the client connection. If the server does not search for the connection information of the packet in the first connection table, it means that the packet is received for the first time by the server. In order to meet the load balancing requirement, a processing server needs to be assigned as a target server for the packet received for the first time according to a preset rule, and the target server is recorded in the connection information of the packet and stored in the first connection table after the target server is determined, so as to be queried when the same packet is received next time.
[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 some time ago and assigned to another server for processing. Therefore, 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 current server is processed and a response message is sent back to the switch. Based on the connection information in the first connection table, if the target server is determined to be the current server, the current server processes the message. After processing the message, a response message is generated and sent directly to the switch. Optionally, if the current 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 message processing efficiency and reducing resource usage on the primary server.
[0080] In step S106, if the server is a secondary server, the connection information of the message processed by the server is recorded in the second connection table. The second connection table is stored on the secondary server and is used to record the connection information of the messages sent to the secondary server within a preset time period. The connection information includes one or more of the message's source address, destination address, source port, destination port, and protocol type. When the secondary server receives a message, it receives the message's source address and port and records the secondary server's MAC address and port so that it can directly process the message when it receives the same message again.
[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 the other secondary servers in the server group to generate its own first connection table. In a load balancing application scenario of a server group, when a sudden failure of one of the servers in the server group causes the server to be unable to continue providing services, all connections to the server will be interrupted until the server is restored or the connection of the original server is migrated to the backup server. This will cause connection interruption and have a negative impact on the user experience. In the master-slave mode adopted by traditional load balancing technology, migrating all connections from the damaged host to the backup server will cause a temporary interruption of all connections of the host. To avoid the interruption of all connections caused by the master-slave switch, this solution sets up an architecture of one 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 the other servers and forms its own first connection table based on the second connection tables of the 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 of the newly elected primary server only refers to the connections actually handled by the original primary server. As for the connections handled by other servers, since the new first connection table synchronizes the connection information in the other original second connection tables, the current server, i.e., the new primary server, can forward the original connections to the other servers according to the new first connection table without causing connection interruptions, thereby maintaining the user experience.
[0082] Figure 3 FIG. 1 is a flow chart showing the master 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 terminal is the control interface of the server group. The server group includes server A, server B, server C, and server D. Initially, server A is the primary server, and servers B, C, and D are secondary servers. The control terminal periodically sends health check instructions to the primary server. If server A becomes damaged and unavailable, and the health check instructions are not responded to, server B is elected from multiple secondary servers as the new primary server. Server B obtains the corresponding second connection table from servers C and D, and merges it with server B's original second connection table to form a new first connection table. Finally, server B reports to the control terminal that it is the new primary server. In this embodiment, the new first connection table generated by server B contains all the connection information for servers B, C, and D, missing only the connection information for the original server A. This ensures that 75% of the connections are unaffected if the original primary server A fails. Only the connection for the original server A needs to be reset. There is no need to set up an idle backup server, and all servers can participate in traffic processing, improving the utilization efficiency of the server group.
[0083] In step S108, if the server is a secondary server and has not been designated as the primary server when the primary server is unavailable, the server sends its secondary connection table to the secondary server designated as the primary server. If the primary server is damaged and the server is a secondary server and has not been selected as the primary server, upon receiving a connection table synchronization request to elect a new 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 based on the connection information. The message hash value is calculated based on the connection information of the message. For example, the hash value is calculated based on 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 total number of 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 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:
[0088] ID=(hash%n); where 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 current 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 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 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 will be directly forwarded to the idle server, realizing seamless replacement of the auxiliary server and reducing the impact of server failure on 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 the connection of the faulty auxiliary server needs to be split and allocated to other servers in the server group. The connection information in the first connection table with the target server being 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 FIG. 1 is a flow chart showing a method for processing packets in a multi-server load balancing scenario according to another embodiment of the present disclosure. Figure 4 As shown, the method further 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 for the processor utilization. When the processor utilization reaches the utilization threshold, it indicates that the load on 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 a large amount of 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 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 of a single server.
[0096] In step S112, when the message ratio of the connection information does not exceed the preset message ratio threshold, the target server of one or more of the connection information is changed to the idle server. When the processor of the current server exceeds the preset utilization threshold and the message ratio of no connection information exceeds the preset message ratio threshold, it indicates that the proportion of server resources used by any connection in the current server is not high, and the high load of the current server is caused by processing too many connections. Therefore, the target server of one or more connection information can be changed to an idle server, and one or more connections can be migrated to the idle server to reduce the load of the current server.
[0097] According to an embodiment of the present disclosure, if the message is a network layer message, processing the message on the server includes:
[0098] When this server is a secondary server, the network layer message is discarded. As mentioned above, the primary and secondary servers use the same virtual IP address, and the primary server's MAC address is used as the MAC address bound to the virtual IP address. Therefore, the network layer message is responded to by the primary server in the server group. When this server is a secondary server and receives a network layer message such as an ARP message or ICMP message, this server performs packet discarding to ensure that the network layer message is responded to only by the primary server.
[0099] According to an embodiment of the present disclosure, the method further includes:
[0100] When the server is the primary 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 not including the current server;
[0102] If the target server of the message is the current server, processing the message on the current 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 expiration time is reached, the first connection table is sent to the new primary server and the current 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 a server requires maintenance or relocation, it needs to be shut down. However, ongoing services on the server will be affected by the server shutdown. To address this issue, upon receiving a service termination instruction, the server classifies the received message. If no server corresponding to the connection information is found, indicating that the message is being received for the first time, the message and connection are assigned to a server other than the server itself, preventing new connections from entering the server. If the message's destination server is the server itself, indicating that the message and the corresponding connection are currently being processed by the server, the server processes the message and deletes the connection information from the first connection table at a preset deletion time. In this way, when the server needs to be shut down, connections currently running on the server are retained for a period of time, minimizing the impact on existing connections. New connections are forwarded to other servers, preventing newly added connections from affecting the server's termination. After the preset termination time arrives, the server's first connection table is sent to the new primary server, migrating any connections that existed before the server shutdown to the new primary server, minimizing the impact of server changes on existing connections.
[0107] According to an embodiment of the present disclosure, the primary server and the secondary server include a network card, which can run the fast data path XDP (eXpress Data Path) including the 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. The messages received by the primary server and the secondary server are first classified and filtered, and then handed over to the server for processing, which can reduce the server load and improve the server's data processing efficiency.
[0108] Figure 5A 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. The device can be implemented as part or all of an 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 the 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 this 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 can 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 can 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 and the server group can communicate. The server group includes a primary server and multiple secondary servers. The primary server and the secondary servers 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 and 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 primary 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] Determination module 430 is configured to, when the message is a transport layer message and the current server is a primary server, determine a target server for processing the message, including: obtaining connection information of the message; searching a first connection table for a server corresponding to the connection information 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, and recording the correspondence between the connection information and the target server in the first connection table.
[0113] According to the embodiment 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. After the target server is determined, the target server is recorded in the connection information corresponding to the message and stored 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 current 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 indicates that the message has been received some time ago and assigned to another server for processing. Therefore, the message needs to be sent to the target server listed in the connection information.
[0115] The second processing module 450 is configured to process the packet whose target server is the server and send the response packet back to the switch. According to the connection information in the first connection table, if it is judged that the target server in the connection information is the server, the packet is processed by the server. After the packet is processed, the response packet is generated and sent directly to the switch. Alternatively, when the server is a secondary server, the response packet does not need to be sent to the primary server and then forwarded to the switch by the primary server, thereby improving the packet 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 packet processed by the server in the second connection table when the server is a secondary server. The second connection table is stored in the secondary server and is used to record the connection information of the packet sent to the secondary server within a preset time period. The connection information includes one or more of the source address, the destination address, the source port, the destination port and the protocol type of the packet. When the secondary server receives the packet, the source address and the port of the packet are received, and the MAC address and the port of the secondary server are recorded, so that the packet can be directly processed when the same packet is received again in the future.
[0117] The generating module 470 is configured to obtain 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 designated as a primary server when the primary 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 cannot continue to provide services, all connections connected with the server will be interrupted until the server is recovered or the connections of the original server are migrated to the backup server, which will cause the connection interruption and affect the user experience. In the master-slave mode used in the traditional load balancing technology, all connections in the damaged master are migrated to the backup, which will cause temporary interruption of all connections of the master. In order to avoid the interruption of all connections caused by the switching of the master and the backup, the present scheme sets up an architecture of one primary server and multiple secondary servers. When the primary server is unavailable, one of the secondary servers is selected as the primary server, i.e. the server. The server obtains the corresponding second connection table from other servers, and forms its own first connection table according to the second connection table of other secondary servers and the original second connection table of the server. In the present embodiment, the missing connection information in the first connection table of the newly elected primary server is only part of the connections actually processed by the original primary server. For the connections processed by other servers, since the new first connection table synchronizes the connection information in the original second connection table of other servers, the new primary server can forward the original connection to other servers according to the new first connection table, without causing connection interruption, so that the user experience is not affected.
[0118] Second sending module 480 is configured to send its second connection table to the designated secondary server if the current server is a secondary server and has not been designated as the primary server when the primary server is unavailable. If the primary server fails and the current server is a secondary server and has not been selected as the primary server, upon receiving a connection table synchronization request to elect a new primary server, the current server sends its second connection table to the new primary server.
[0119] According to an embodiment of the present disclosure, the determining module 430 includes:
[0120] The first calculation submodule is configured to calculate a message hash value based on the connection information. The message hash value is calculated based on the connection information of the message, for example, based on 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 primary server and all secondary 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); where 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 current server is a primary server and the secondary server is unavailable, the apparatus 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 will be 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.
[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 the connection of the original auxiliary server needs to be split and allocated 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. 1 shows a structural block diagram 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 a preset utilization threshold. The preset utilization threshold is a pre-set warning value for the processor utilization. When the processor utilization reaches the utilization threshold, it indicates that the load on 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 server resources occupied by a single connection, and can screen out connections that occupy a large amount of 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 and 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 should be used to jointly process the messages sent by the connection, so as to reduce the processor utilization rate of a single server.
[0131] The second modification module 412 is configured to modify the target servers of one or more connection information to idle servers when the message ratio of the connection information does not exceed a preset message ratio threshold. When the processor utilization of the current server exceeds a preset threshold and the message ratio of no connection information exceeds the preset message ratio threshold, it indicates that any connection in the current server is not utilizing a high proportion of server resources and the high load of the current server is due to processing too many connections. Therefore, the target servers of one or more connection information can be modified to idle servers, and one or more connections can be migrated to the idle servers to reduce the load on the current server.
[0132] According to an embodiment of the present disclosure, if the message is a network layer message, processing the message on the server includes:
[0133] When this server is a secondary server, the network layer message is discarded. As mentioned above, the primary and secondary servers use the same virtual IP address, and the primary server's MAC address is used as the MAC address bound to the virtual IP address. Therefore, the network layer message is responded to by the primary server in the server group. When this server is a secondary server and receives a network layer message such as an ARP message or ICMP message, this server performs packet discarding to ensure that the network layer message is responded to only 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, the target server not including the current server;
[0136] a third processing module configured to process the message on the current server if the target server of the message is the current server, and delete the connection information in the first connection table at a preset deletion time;
[0137] a second sending module, 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, 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 a server requires maintenance or relocation, it needs to be shut down. However, ongoing services on the server will be affected by the server shutdown. To address this issue, upon receiving a service termination instruction, the server classifies the received message. If no server corresponding to the connection information is found, indicating that the message is being received for the first time, the message and connection are assigned to a server other than the server itself, preventing new connections from entering the server. If the message's destination server is the server itself, indicating that the message and the corresponding connection are currently being processed by the server, the server processes the message and deletes the connection information from the first connection table at a preset deletion time. In this way, when the server needs to be shut down, connections currently running on the server are retained for a period of time, minimizing the impact on existing connections. New connections are forwarded to other servers, preventing newly added connections from affecting the server's termination. After the preset termination time arrives, the server's first connection table is sent to the new primary server, migrating any connections that existed before the server shutdown to the new primary 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 a method according to an embodiment of the present disclosure. The method is applied to a server in a server group, wherein 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 destined for the virtual IP address to a master 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 local server;
[0145] When the message is a transport layer message and the current server is the primary server, determining a target server for processing the message includes: obtaining connection information of the message; searching a first connection table for a server corresponding to the connection information as the target server; if no server corresponding to the connection information is found, 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;
[0146] If the target server is not the current server, sending the message to the target server;
[0147] Processes the message whose target server is the current server and sends 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 corresponding second connection tables 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] 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] Perform a modulo calculation on the message hash value and 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 target servers.
[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 the total number of messages per second of the server, the number of sub-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 primary 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 not including the current server;
[0168] If the target server of the message is the current server, processing the message on the current 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 expiration time is reached, the first connection table is sent to the new primary server and the current 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 execute the various methods in the above-mentioned embodiments according to a program stored in a read-only memory (ROM) or a program loaded from a storage portion into a 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 via a bus. An 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), a speaker, etc.; 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 magnetic 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 embodiments of the present disclosure, the methods described above can be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for executing the methods described above. In such embodiments, the computer program can be downloaded and installed from a network via a communication component and / or installed from a removable medium.
[0176] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation 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, program segment or part of code, and the module, program segment or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that 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 using a dedicated hardware-based system that performs the specified function or operation, or can be implemented using a combination of dedicated hardware and computer instructions.
[0177] The units or modules involved in the embodiments described in this disclosure may be implemented by software or programmable hardware. The units or modules described may also be provided in a processor, and the names of these units or modules do not, in certain circumstances, constitute limitations on the units or modules themselves.
[0178] As another aspect, the present disclosure further provides a computer-readable storage medium. This computer-readable storage medium may be included in the electronic device or computer system described in the above embodiments, or may be a standalone computer-readable storage medium not incorporated into the device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the methods described in the present disclosure.
[0179] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of the invention herein is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the inventive concept. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this disclosure.
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 including multiple servers, the multiple servers connected to a switch and having the same virtual IP address, the switch sending a message destined for the virtual IP address to a master server among the multiple servers, the method comprising: Receive messages; When the message is a network layer message, processing the message on the local server; When the message is a transport layer message and the current server is the primary server, determining a target server for processing the message includes: obtaining connection information of the message; searching a first connection table for a server corresponding to the connection information as the target server; if no server corresponding to the connection information is found, 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; If the target server is not the current server, sending the message to the target server; Processes the message whose target server is the current server and sends 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 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 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 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; Perform a modulo calculation on the message hash value and 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 target servers.
4. The method according to claim 1, wherein 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 the total number of messages per second of the server, the number of sub-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, wherein 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 primary 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 not including the current server; If the target server of the message is the current server, processing the message on the current 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 expiration time is reached, the first connection table is sent to the new primary server and the current 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 including multiple servers, the multiple servers being connected to a switch and having the same virtual IP address, the switch sending a message destined for the virtual IP address to a master server among the multiple servers, the device including: 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, when the message is a transport layer message and the current server is a primary server, determine a target server for processing the message, comprising: obtaining connection information of the message; searching a first connection table for a server corresponding to the connection information 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, 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; a second processing module configured to process a message indicating 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 secondary server designated as the primary server if the server is a secondary server and is not designated as the primary server when the primary server is unavailable.
8. The device according to claim 7, characterized in that The determining module includes: 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 the 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 to 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