Search

CN-121984971-A - Client load balancing method and business client

CN121984971ACN 121984971 ACN121984971 ACN 121984971ACN-121984971-A

Abstract

The application discloses a client load balancing method which comprises the steps of obtaining a server list, selecting a first server from an initial default client, traversing second to Nth servers, selecting the ith server from the traversed ith server according to probability P i =1/i, taking the selected server as a candidate server for establishing a connection relation with the client, selecting the first server to establish the connection relation with the client under the condition that the traversed second to Nth servers are not taken as the candidate server after traversing the second to Nth servers, and selecting the last server to establish the connection relation with the client under the condition that at least one server is selected as the candidate server in the traversed second to Nth servers. The method always selects the candidate server with the largest sequencing sequence number for connection, and ensures that only old to new migration occurs when the server expands.

Inventors

  • HAN TAO
  • ZHAO JING
  • XU XIAOJING
  • HUANG DONG

Assignees

  • 杭州佰鹿信息科技有限公司

Dates

Publication Date
20260505
Application Date
20251230

Claims (10)

  1. 1. A method for client load balancing, the method comprising: obtaining a server list, wherein the server list comprises the number N of servers and the ordering of the servers; selecting a first server by the client by initial defaulting, traversing the second to Nth servers, selecting the ith server by probability P i =1/i for the traversed ith server, and taking the selected server as a candidate server for establishing a connection relation with the client; and selecting a candidate server from the second to N servers, wherein the server ranking is positioned at the last server and establishes a connection relation with the client under the condition that the second to N servers are not used as the candidate server after the second to N servers are traversed.
  2. 2. The client load balancing method of claim 1, further comprising: under the condition that the number of the servers is increased, inserting the newly added servers into the tail end of the original server list on the basis of the original server list; Traversing the newly added server, selecting the ith server according to the probability P i = 1/i, and taking the selected newly added server as a candidate server for establishing a connection relation with the client; After traversing the newly added server, maintaining the connection relation between the client and the original server under the condition that the candidate server is not added, and modifying the client to establish the connection relation with the server which is arranged at the last in the newly added candidate server under the condition that the candidate server is added.
  3. 3. The method for client load balancing according to claim 1 or 2, wherein, The selecting the ith server with probability P i =1/i includes: initializing a pseudo-random sequence generator by taking the unique characteristic value of the client as a seed, wherein the pseudo-random sequence generator has decisive function; generating a pseudo random number of a corresponding server through the pseudo random sequence generator, wherein the value range of any pseudo random number is more than 0 and less than 1; And under the condition that the pseudo random number corresponding to the ith server is smaller than 1/i, selecting the ith server, wherein the ith server is used as a candidate server for establishing a connection relation with the client, otherwise, the ith server is not selected.
  4. 4. A client load balancing method according to claim 3, characterized in that the method further comprises: After the unique characteristic value of the client is subjected to numerical processing, the numerical processing result is used as a seed, and the pseudo-random sequence generator is initialized, wherein the result obtained by the numerical processing of the unique characteristic value of the client is fixed.
  5. 5. The client load balancing method of claim 4, further comprising, Carrying out numeric processing on the unique characteristic value of the client through a hash algorithm, and recording a numeric processing result to a nonvolatile storage area of equipment; In the case where it is necessary to initialize the pseudo random sequence generator with the result of the digitizing process as a seed, the result of the digitizing process is read from the device nonvolatile memory area.
  6. 6. The client load balancing method of claim 4, further comprising, And mapping the unique characteristic value of the client with a numerical element to form a key value pair through a self-defined mapping scheme so as to realize the numerical processing of the unique characteristic value of the client, wherein the numerical elements corresponding to different clients meet the condition that the value parts of the numerical elements tend to be average.
  7. 7. A method for client load balancing, the method comprising: obtaining a server list, wherein the server list comprises the number N of servers and the ordering of the servers; Traversing the servers, selecting an ith server according to the probability of 1/(N-i+1), stopping traversing under the condition of selecting the servers, and selecting the last server if the N-1 servers are not selected after traversing; and establishing a connection relation between the selected server and the client.
  8. 8. The client load balancing method of claim 7, wherein the method comprises: selecting the ith server with a probability of 1/(N-i+1) includes: initializing a pseudo-random sequence generator by taking the unique characteristic value of the client as a seed, wherein the pseudo-random sequence generator has decisive function; generating a pseudo random number of a corresponding server through the pseudo random sequence generator, wherein the value range of any pseudo random number is more than 0 and less than 1; and selecting the ith server under the condition that the pseudo random number corresponding to the ith server is less than 1/(N-i+1), otherwise, selecting the ith server.
  9. 9. A service client, the service client comprising: a communication unit, configured to obtain a server list, where the server list includes a number N of servers and a ranking of servers; The processing unit is configured to initially default the client to select a first server, traverse second to nth servers, select the ith server according to probability P i = 1/i for the traversed ith server, and take the selected server as a candidate server for establishing a connection relation with the client; and selecting a candidate server from the second to N servers, wherein the server ranking is positioned at the last server and establishes a connection relation with the client under the condition that the second to N servers are not used as the candidate server after the second to N servers are traversed.
  10. 10. A service client, the service client comprising: a communication unit, configured to obtain a server list, where the server list includes a number N of servers and a ranking of servers; The processing unit is configured to traverse the servers, select the ith server according to the probability of 1/(N-i+1), terminate the traversal under the condition of selecting the servers, select the last server if the N-1 servers are not selected after the traversal, and establish a connection relationship between the selected server and the client; wherein selecting the ith server with a probability of 1/(N-i+1) includes: initializing a pseudo-random sequence generator by taking the unique characteristic value of the client as a seed, wherein the pseudo-random sequence generator has decisive function; generating a pseudo random number of a corresponding server through the pseudo random sequence generator, wherein the value range of any pseudo random number is more than 0 and less than 1; and selecting the ith server under the condition that the pseudo random number corresponding to the ith server is less than 1/(N-i+1), otherwise, selecting the ith server.

Description

Client load balancing method and business client Technical Field The present application relates to the field of server allocation, and in particular, to a client load balancing method and a service client. Background In the related art, client load balancing is usually performed by a hash method, that is, a client unique feature (such as a device number) is mapped to a specific server directly through a hash function, and the method has certainty, but has significant defects in the scenario of dynamic change of the number of servers, namely when a server cluster expands or contracts, a large number of connected clients are remapped to different servers due to the change of the cardinality of hash modular operation, even if the remapping has no practical benefit for load balancing, unnecessary connection interruption, data migration and system jitter are generated, and the continuity and stability of the service are affected. Disclosure of Invention The embodiment of the application provides a client load balancing method, which can realize accurate load balancing. In a first aspect, the present application provides a client load balancing method, where the method includes: acquiring a server list, wherein the server list comprises the number N of servers and the ordering of the server list; The method comprises the steps that a first server is selected by an initial default client, second to Nth servers are traversed, the ith server is selected by probability P i =1/i for the traversed ith server, and the selected server is used as a candidate server for establishing a connection relation with the client; After traversing the second to Nth servers, selecting a first server to establish a connection relationship with the client under the condition that the traversed second to Nth servers are not used as candidate servers; and in the second through N servers, selecting the candidate server under the condition that at least one server is selected as the candidate server, and establishing a connection relation between the last server and the client by the server sequencing. In one embodiment, the method further comprises: under the condition that the number of the servers is increased, inserting the newly added servers into the tail end of the original server list on the basis of the original server list; Traversing the newly added server, selecting an ith server according to the probability P i = 1/i, and taking the selected newly added server as a candidate server for establishing a connection relation with the client; And under the condition that the candidate servers are increased, modifying the client to establish a connection relationship with the server in the newly added candidate servers, wherein the server is arranged at the last in the sequence. In one embodiment, selecting the ith server with probability P i =1/i includes: Initializing a pseudo-random sequence generator by taking a unique characteristic value of a client as a seed, wherein the pseudo-random sequence generator has decisive function; generating pseudo random numbers of the corresponding servers through a pseudo random sequence generator, wherein the value range of any pseudo random number is more than 0 and less than 1; And selecting the ith server as a candidate server for establishing a connection relation with the client under the condition that the pseudo random number corresponding to the ith server is smaller than 1/i, otherwise, not selecting the ith server. In one embodiment, the method further comprises: After the unique characteristic value of the client is subjected to numerical processing, the numerical processing result is used as a seed, and a pseudo-random sequence generator is initialized, wherein the result obtained by the numerical processing of the unique characteristic value of the client is fixed. In one embodiment, the method further comprises, Carrying out numeric processing on the unique characteristic value of the client through a hash algorithm, and recording the numeric processing result to a nonvolatile storage area of the equipment; In the case where it is necessary to initialize the pseudo random sequence generator with the result of the digitizing process as a seed, the result of the digitizing process is read from the nonvolatile memory area of the device. In one embodiment, the method further comprises, And mapping the unique characteristic value of the client with a numerical element to form a key value pair through a custom mapping scheme so as to realize the numerical processing of the unique characteristic value of the client, wherein the numerical elements corresponding to different clients meet the condition that the value parts of the numerical elements tend to be average. In one embodiment, the method includes: acquiring a server list, wherein the server list comprises the number N of servers and the order of the servers; Traversing the servers, selecting an ith server according to the probabi