WO2023050901A1 - Load balancing method and apparatus, device, computer storage medium and program - Google Patents

Load balancing method and apparatus, device, computer storage medium and program Download PDF

Info

Publication number
WO2023050901A1
WO2023050901A1 PCT/CN2022/099587 CN2022099587W WO2023050901A1 WO 2023050901 A1 WO2023050901 A1 WO 2023050901A1 CN 2022099587 W CN2022099587 W CN 2022099587W WO 2023050901 A1 WO2023050901 A1 WO 2023050901A1
Authority
WO
WIPO (PCT)
Prior art keywords
server
client
load
target
load value
Prior art date
Application number
PCT/CN2022/099587
Other languages
French (fr)
Chinese (zh)
Inventor
杨利国
欧阳宇腾
邱路达
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2023050901A1 publication Critical patent/WO2023050901A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/12Avoiding congestion; Recovering from congestion
    • H04L47/125Avoiding congestion; Recovering from congestion by balancing the load, e.g. traffic engineering
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • H04L67/1008Server selection for load balancing based on parameters of servers, e.g. available memory or workload

Definitions

  • the present application relates to the technical field of cloud computing of financial technology (Fintech), involving but not limited to a load balancing method, device, electronic equipment, computer storage medium and computer program product.
  • the present application provides a load balancing method, device, electronic equipment, computer storage medium, and computer program product, which can solve the problem of server overload in the related art when transmitting messages based on TCP long connections.
  • An embodiment of the present application provides a load balancing method, the method comprising:
  • the server list includes at least two servers
  • each client After determining that each client establishes a TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server, determine whether The target server that satisfies the set load balancing conditions;
  • Target client is one of the multiple clients.
  • the searching for a target client connected to the target server includes:
  • the target server According to the amount of messages sent by each of the at least two clients to the target server, from among the at least two clients, determine the client that sends the smallest amount of messages as the target client, or , determining any client whose message volume is less than or equal to the first set threshold as the target client.
  • the target server is a server that does not meet the set load balancing conditions in the current network, it is necessary to adjust the load value of the target server to achieve a balanced state;
  • the amount of messages sent by each client is determined, therefore, based on the amount of messages sent by each client to the target server, the target client can be determined in a targeted manner; in addition, from each client connected to the target server , select the client with the smallest amount of messages sent or less than a certain threshold as the target client, which can effectively prevent the jitter problem during the subsequent load adjustment of the target server and ensure the stability of the system.
  • the determining the target server that does not meet the set load balancing condition according to the load value of each server obtained again includes:
  • the server with the highest load value and the server with the lowest load value are obtained; when it is determined that the load difference between the server with the highest load value and the server with the lowest load value is greater than a second set threshold, The server with the highest load value is determined as the target server that does not meet the set load balancing condition; or,
  • the adjusting the server list of the target client includes:
  • the server with the highest load value in the server list of the target client is removed, and a server with the lowest current load value is added to the server list of the target client.
  • the method also includes:
  • the load determination parameters include the number of connections of the server, the server's last statistics At least one of the periodic processing message volume and the last time the server was assigned to the client;
  • the acquisition of the load value of each server in the current network includes:
  • the load value of each server in the current network is determined according to the load determination parameters reported by each server in the current network.
  • the load determination parameters when the load determination parameters include the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the time when the server was allocated to the client last time, the load determination parameters further include connection The weight value of the number, the weight value of the processing message volume, and the weight value of the time parameter;
  • the determining the load value of each server in the current network according to the load determination parameters reported by each server in the current network includes:
  • the time parameter weight value determines the load value of each server in the current network.
  • the load value of each server in the current network can be obtained more accurately.
  • the method also includes:
  • Whether to continue to adjust the server list in the current statistical period is determined according to the relationship between the adjusted session ratio and the fourth set threshold.
  • the number of adjustments to the server list in the current statistical cycle is controlled by adjusting the session ratio of the current statistical cycle, which can prevent the problem of poor system stability caused by large-scale server connection adjustments.
  • the determining whether to continue adjusting the server list in the current statistical period according to the size relationship between the adjusted session ratio and the fourth set threshold includes:
  • the number of adjustments to the server list in the current statistical cycle is controlled, so as to achieve load balancing in the current statistical cycle and ensure that the system stability.
  • the embodiment of the present application also proposes a load balancing device, the device includes a first determination module, a second determination module and an adjustment module, wherein,
  • the first determining module is configured to obtain the load value of each server in the current network after receiving the connection request sent by each client in the plurality of clients; determine the load value of each server according to the load value of each server A server list of the client, sending a corresponding server list to each client; the server list includes at least two servers;
  • the second determination module is configured to reacquire the load value of each server in the current network after determining that each client establishes a TCP long connection with each server in the corresponding server list;
  • the load value of the server determines the target server that does not meet the set load balancing conditions;
  • An adjustment module configured to search for a target client connected to the target server, and adjust the server list of the target client; the target client is one of the plurality of clients.
  • An embodiment of the present application provides an electronic device, the device includes a memory, a processor, and a computer program stored on the memory and operable on the processor, and the processor implements one or more of the aforementioned technologies when executing the program The load balancing method provided by the solution.
  • An embodiment of the present application provides a computer storage medium, where the computer storage medium stores a computer program; after the computer program is executed, the load balancing method provided by the foregoing one or more technical solutions can be implemented.
  • the embodiment of the present application also provides a computer program product, including computer readable code, when the computer readable code is run in the electronic device, the processor in the electronic device executes to implement the aforementioned one or more The load balancing method provided by the technical solution.
  • the embodiment of the present application proposes a load balancing method, device, electronic equipment, computer storage medium and computer program product.
  • the method includes: after receiving a connection request sent by each client among multiple clients, obtaining the current network The load value of each server; according to the load value of each server, determine the server list of each client, and send the corresponding server list to each client; the server list includes at least two server; after determining that each client establishes a TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server , determine the target server that does not meet the set load balancing conditions; find the target client connected to the target server, adjust the server list of the target client; the target client is one of the multiple clients end.
  • the list of servers that each client is allowed to connect can be determined; that is, the client can be connected to To multiple servers with lower load values, so that the client's business volume can be sent to different servers for processing in a more balanced manner.
  • the client after the client establishes a connection with the server, if it is found that the target server does not meet the set load balancing conditions, then adjust the server list of the target client connected to the target server to achieve the purpose of controlling the overall load of the entire server cluster, Maintain the dynamic balance of the load value of each server to effectively solve the problem of server overload.
  • FIG. 1a is a schematic structural diagram of a load balancing in the related art
  • FIG. 1b is a schematic structural diagram of another load balancing in the related art
  • FIG. 2a is a schematic flow diagram of a load balancing method in an embodiment of the present application.
  • FIG. 2b is a schematic structural diagram of a load balancing adjustment in an embodiment of the present application.
  • FIG. 2c is a schematic flow diagram of another load balancing method according to an embodiment of the present application.
  • FIG. 2d is a schematic structural diagram of another load balancing adjustment in the embodiment of the present application.
  • FIG. 3 is a schematic diagram of the composition and structure of a load balancing device according to an embodiment of the present application
  • FIG. 4 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • the term “comprising”, “comprising” or any other variation thereof is intended to cover a non-exclusive inclusion, so that a method or device comprising a series of elements not only includes the explicitly stated elements, but also include other elements not explicitly listed, or also include elements inherent in implementing the method or apparatus.
  • an element defined by the phrase “comprising a " does not exclude the presence of additional related elements (such as steps in the method or A unit in an apparatus, for example, a unit may be part of a circuit, part of a processor, part of a program or software, etc.).
  • the load balancing method provided in the embodiment of the present application includes a series of steps, but the load balancing method provided in the embodiment of the present application is not limited to the steps described.
  • the load balancing device provided in the embodiment of the present application includes a A series of modules, but the load balancing device provided by the embodiment of the present application is not limited to include the explicitly recorded modules, and may also include modules that need to be set up to obtain relevant task data or process based on task data.
  • the embodiments of the present application can be applied to a computer system composed of servers, and can operate together with many other general-purpose or special-purpose computing system environments or configurations.
  • the server may be a distributed cloud computing technology environment including a small computer system, a large computer system, and so on.
  • program modules may include routines, programs, objects, components, logic, data structures, etc., that perform particular tasks or implement particular abstract data types.
  • the computer system/server can be practiced in distributed cloud computing environments where tasks are performed by remote processing devices that are linked through a communications network.
  • program modules may be located in both local and remote computing system storage media including storage devices.
  • TCP-based connections include long connections and short connections.
  • TCP long connections will be used to ensure low system throughput and delay.
  • the reverse proxy server may also have problems with the capacity of the network card or the upper limit of the number of connections.
  • the load balancing method can be realized by using a processor in the load balancing device, and the processor can be an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (Digital Signal Processor, DSP), digital signal processing device (Digital Signal Processing Device, DSPD), programmable logic device (Programmable Logic Device, PLD), field programmable logic gate array (Field Programmable Gate Array, FPGA), central processing unit (Central Processing Unit , CPU), controller, microcontroller, microprocessor at least one.
  • ASIC Application Specific Integrated Circuit
  • DSP Digital Signal Processor
  • DSP digital signal Processing Device
  • DSPD Digital Signal Processing Device
  • PLD programmable logic device
  • FPGA field programmable logic gate array
  • CPU Central Processing Unit
  • controller microcontroller, microprocessor at least one.
  • FIG. 2a is a schematic flow diagram of a load balancing method in the embodiment of the present application, as shown in Figure 2a, the method includes the following steps:
  • Step 200 After receiving the connection request sent by each of the multiple clients, obtain the load value of each server in the current network; determine the server list of each client according to the load value of each server, and send each The client sends a corresponding server list; the server list includes at least two servers.
  • the client is used to access specific business data and forward the business data to the back-end server for subsequent further processing;
  • the server belongs to the back-end processing module and is used to process the business data forwarded by the client .
  • the load balancing method is a method of balancing the load value of each server in the current network when the client establishes a TCP long connection with the server; Before each client establishes a TCP long connection with the server, the client does not know which servers are available in the current network; therefore, when each client needs to send business data to the server, it needs to first send a connection request to the scheduling module. In this way, The scheduling module can then receive the connection request sent by each client in the multiple clients.
  • the scheduling module by introducing the scheduling module, the complexity of connection management between each client and the server can be reduced; the scheduling module will be described in detail in conjunction with FIG. 2b below.
  • FIG. 2b is a schematic structural diagram of a load balancing adjustment in the embodiment of the present application, as shown in Figure 2b, the structural diagram includes: client 1, client 2, server 1 to server n, and a scheduling module; wherein, the scheduling module One end of the scheduling module is connected to client 1 and client 2 respectively, and is responsible for receiving the connection requests sent by these two clients; the other end of the scheduling module is respectively connected to n servers in the current network to collect The data related to its own load reported by the server; client 1 is connected to server 1 and server 2, and client 2 is connected to server 2 and server 3; that is, the client can connect to multiple servers at the same time.
  • the embodiment of the present application does not need to introduce a reverse proxy server, but each client directly connects to the corresponding server, That is, there is no need to connect to each server through the reverse proxy server, so it can solve the problem of high difficulty in implementing load balancing due to the upper limit of the network card capacity or connection number of the reverse proxy server in the related technology; in addition, the embodiment of the present application allows The client connects to multiple server nodes at the same time; in this way, when one of the servers is abnormal, the client can continue to process business through other server nodes, that is, it will not affect the business during the disconnection between the client and the abnormal server, ensuring the server's High availability; further, when a server is offline, upgraded, restarted, etc. changes or abnormalities occur, the expansion of the server can also be quickly completed in the embodiment of the application, which can solve the problem of related technologies due to the limited processing capacity of the reverse proxy server.
  • the client connects to multiple server nodes at the same time; in this way, when one of the servers is abnormal, the
  • the above method may further include: before the scheduling module receives the connection request sent by each client among the plurality of clients, receiving load determination parameters reported by each server in the current network.
  • the load determination parameter may include at least one of the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the last time the server was assigned to the client; The number of connections between the server and the client during the statistical period.
  • the statistical cycle and timing time can be preset in the server, so that the server can count the load determination parameters in each statistical cycle, and when the timing time arrives, the load determination parameters in the last statistical cycle closest to the timing time The load determination parameters are reported to the scheduling module.
  • obtaining the load value of each server in the current network may include: the scheduling module determines the load value of each server in the current network in each statistical period according to the load determination parameters reported by each server in the current network.
  • the load determination parameters when the load determination parameters include the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the time when the server was allocated to the client last time, the load determination parameters also include the weight value of the number of connections, Process message volume weight value and time parameter weight value.
  • the weight value of the number of connections, the weight value of the processed message volume, and the weight value of the time parameter may be set according to actual scenarios, which are not limited in this embodiment of the present application.
  • determining the load value of each server in the current network may include: according to the number of connections of the server reported by each server in the current network and the weight value of the connection number, The amount of messages processed by the server in the last statistical cycle and the weight value of the amount of processed messages, the time when the server was assigned to the client last time and the weight value of time parameters determine the load value of each server in the current network.
  • the scheduling module after the scheduling module receives the load determination parameters regularly reported by each server in the current network, it can obtain the load value Lr of each server in the last statistical period according to the server load evaluation formula (1).
  • Abs represents the calculated absolute value
  • C represents the number of server connections
  • Min(C) represents the connection number with the smallest value among the connections of all servers in the current network
  • ⁇ C represents the tolerance value of the number of server connections. If the difference in the number of connections is less than this value, it can be considered that the number of connections on the server is balanced
  • WC indicates the weight of the number of connections in the server load evaluation formula, corresponding to the weight of the number of connections above.
  • M represents the amount of messages processed by the server in the last statistical cycle
  • Min(M) represents the amount of messages processed with the least amount of messages among all servers in the last statistical cycle
  • ⁇ M represents the tolerance value of the amount of messages processed.
  • WM indicates the weight value of the processed message volume in the server load evaluation formula, which corresponds to the above weight value of the processed message volume.
  • the embodiment of the present application does not limit the values of the above parameters included in the formula (1), and may be set according to actual scenarios. It can be seen that when the server has more connections, the server load value is higher; when the server processes more messages, the server load value is higher; when the server was assigned to the client last time, the closer to the current time , the higher the server load value.
  • the scheduling module can determine the number of servers that each client is allowed to connect to according to the importance of each client's business or the business volume , denoted as cn; here, when the importance of a certain client’s business or business volume is high, the client can be allowed to connect to a larger number of servers; when the importance of a certain client’s business or business volume is low , the client can be allowed to access a smaller number of servers.
  • the scheduling module before the scheduling module receives the connection request sent by each of the multiple clients, it can obtain the load value of each server in the last statistical period according to the formula (1); for example, According to the load value of each server, the implementation manner of determining the server list of each client may be: the scheduling module selects cn servers with lower load values as the server list of each client according to the load value of each server;
  • the server list of each client includes at least two servers, so that when the connection between the client and one of the servers is abnormal, the high availability of the service can still be guaranteed.
  • the server list may include multiple servers, but not all servers in the current network. In this way, the problem of too high connection number of each server caused by connecting all servers can be effectively avoided.
  • the scheduling module obtains the server list of each client, it sends the corresponding server list to each client; in this way, each client can establish a TCP long connection with each server in the corresponding server list.
  • Step 201 After determining that each client establishes a TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server, determine that the Set the target server for load balancing conditions.
  • each client after determining that each client establishes a TCP long connection with each server in the corresponding server list, each client will poll and send business data to each server that has established a TCP long connection; the following uses a
  • the client and two servers are taken as an example for description.
  • the load determination parameters include the amount of processing messages corresponding to the server connection session, the amount of processing messages corresponding to this server, the number of connections to this server, and the time when this server is assigned to client 1; then when the timing time arrives, Server 1 reports the above-mentioned load determination data to the scheduling module; in this way, the scheduling module can reacquire the load value of server 1 according to the formula (1); here, the acquisition process of server 2 load value is similar to the above-mentioned acquisition process, which is not mentioned here. Let me repeat. In this way, the scheduling module can reacquire the load value of each server in the current network.
  • determining the target server that does not meet the set load balancing condition may include: sorting the load value of each server obtained again to obtain the sorting result; Sort the results to determine the target servers that do not meet the set load balancing conditions.
  • the reacquired load value of each server it can be sorted according to the order of the load value from high to low to obtain the sorting result; then, according to the sorting result, determine the target server that does not meet the set load balancing condition .
  • an implementation manner of determining a target server that does not meet the set load balancing condition according to the sorting result may be: from the sorting result, obtain the server with the highest load value and the server with the lowest load value; When the load difference between the server with the highest load value and the server with the lowest load value is greater than the second set threshold, the server with the highest load value is determined as the target server that does not satisfy the set load balancing condition.
  • the server with the highest load value and the server with the lowest load value from the sorting results, first calculate the load difference between the server with the highest load value and the server with the lowest load value; If it is determined according to the comparison result that the load difference is greater than the second set threshold, it means that there are target servers that do not meet the set load balancing conditions, and the server with the highest load value is determined to be unsatisfied.
  • Set the target server for load balancing conditions on the contrary, if it is determined according to the comparison result that the load difference is less than or equal to the second set threshold, it means that there is no target server that does not meet the set load balancing conditions at this time, that is, the currently established All servers with TCP persistent connections meet the load balancing conditions.
  • another implementation manner of determining a target server that does not meet the set load balancing condition according to the sorting result may be: determining any server whose load value is greater than the third set threshold in the sorting result as not meeting Set the target server for load balancing conditions.
  • server 1 can be determined as not meeting the set load
  • the target server of the load balancing condition may also determine the server 2 as the target server that does not meet the set load balancing condition.
  • the load values in the sorting results are all less than or equal to the third set threshold, it means that there is no target server that does not meet the set load balancing conditions at this time, that is, all servers currently establishing TCP long connections meet the load Equilibrium conditions.
  • the values of the second set threshold and the third set threshold may be determined according to actual conditions, which is not limited in this embodiment of the present application.
  • Step 202 Search for a target client connected to the target server, and adjust the server list of the target client; the target client is one of the multiple clients.
  • the target server that does not meet the set load balancing conditions is obtained according to the above step 201, all clients that have established TCP long connections with the target server are obtained, and the server list that needs to be adjusted is searched from these clients.
  • the target client; here, adjusting the server list represents a load balancing adjustment.
  • searching for a target client connected to the target server may include: acquiring at least two clients that establish a TCP long connection with the target server; The message volume, from at least two clients, determines the target client.
  • the scheduling module may determine the target client from multiple clients establishing TCP connections with the target server according to the amount of messages sent by each client to the target server.
  • the target server is a server that does not meet the set load balancing conditions in the current network, it is necessary to adjust the load value of the target server to achieve a balanced state;
  • the amount of messages sent by each client is determined. Therefore, based on the amount of messages sent by each client to the target server, the target client can be determined in a targeted manner.
  • determining the target client from the at least two clients according to the amount of messages sent from each of the at least two clients to the target server may include: according to each of the at least two clients The amount of messages sent by the client to the target server. From at least two clients, the client with the smallest amount of messages sent is determined as the target client, or any client whose amount of messages sent is less than or equal to the first set threshold determined as the target client.
  • the client that sends the smallest amount of messages or less than a certain threshold is selected as the target client, which can effectively prevent the subsequent load on the target server
  • the jitter problem during adjustment ensures the stability of the system.
  • the implementation manner of determining the target client may also be: from all clients establishing connection sessions with the target server, find out the client with the smallest connection session load, and determine the client as the target client; here , the connection session load Las of each client that establishes a connection session with the target server can be determined by formula (2).
  • WAT means the weight value of the time parameter in the client connection session load evaluation formula
  • t means the time when the client connects to the target server
  • t1 means the time of the client's last session adjustment, that is, the last time the client connected
  • MC indicates the amount of messages that need to be processed by this connection session in the latest statistical period, that is, the amount of messages sent by the client to the target server that needs to be processed by the target server.
  • the embodiment of the present application does not limit the values of the above parameters included in the formula (2), and may be set according to actual scenarios. It can be seen from formula (2) that if the number of messages processed by the target server is more, the connection session load of the corresponding client is higher, and if the time from the latest session adjustment is closer, the connection session load of the corresponding client is higher.
  • connection session load of each client that establishes a connection session with the target server is obtained according to formula (2), the client with the smallest connection session load is determined as the target client, or the connection session load is less than or equal to the set The client with the given value is identified as the target client.
  • the server list of the target client is obtained, and the server list is adjusted to realize load balancing among the servers.
  • adjusting the server list of the target client may include: removing the server with the highest load value from the server list of the target client, and adding a server with the lowest load value to the server list of the target client.
  • the server with the highest load value in the server list is removed, that is, the target server in the server list is removed, and a new one with the lowest current load value is added. server.
  • the target server is a server with a high load value in the current network, and its data processing capability is low. If it is not removed, but continues to process the business data sent by the target client, it is very likely that the target server will crash due to overload. In this case, the processing capacity of the entire server cluster is affected; in the embodiment of this application, by adjusting the connection between the target client and the target server to the connection between the target client and the server with the lowest current load value, the target server no longer processes the target client In this way, the overload problem of the target server can be effectively solved, and the possibility of the target server crashing due to overload can be reduced; in addition, since the connection session load between the target client and the target server is minimal, this adjustment method can also Effectively prevent the vibration problem during the adjustment process and ensure the stability of the system.
  • the above method may further include: adding 1 to the number of adjustments each time the server list is adjusted within the current statistical period; calculating the total number of adjustments to the server list within the current statistical period According to the ratio of the total number of connections of each server, the adjusted session proportion of the current statistical period is obtained; according to the relationship between the adjusted session proportion and the fourth threshold value, it is determined whether to continue to adjust the server list in the current statistical period.
  • the number of adjustments to the server list in the current statistical period is controlled by adjusting the session ratio of the current statistical period, which can prevent the problem of poor system stability caused by large-scale server connection adjustments.
  • every time the adjustment of the server list is completed means that every time the load balancing adjustment is completed; here, in the current statistical period, every time the adjustment of the server list is completed, the adjustment number is incremented by 1; Exemplarily, the current The total number of adjustments to the server list in the statistical period is recorded as AT, and the total number of connections to each server in the current network is recorded as CT, so the proportion of adjusted sessions in the current statistical period is AT/CT. Next, it is determined whether to continue to adjust the server list in the current statistical period according to the relationship between the adjusted session proportion and the fourth set threshold.
  • determining whether to continue adjusting the server list in the current statistical period may include: determining that the adjusted session ratio is greater than or equal to the fourth set threshold , wait for the end of the current statistical period; when it is determined that the proportion of adjusted sessions is less than the fourth set threshold and it is determined that there are target servers that do not meet the set load balancing conditions, continue to adjust the server list in the current statistical period.
  • the value of the adjusted session ratio AT/CT is greater than or equal to the fourth set threshold, wait for the end of the current statistical period; that is, no load balancing adjustment is performed in this message statistical period to prevent the system from appearing in a large area. Connection flapping.
  • the value of the adjusted session ratio AT/CT is less than the fourth set threshold, then evaluate again whether the load among the servers in the current network is balanced, that is, determine whether there is a server that does not meet the set load balancing conditions. If the target server is unbalanced, if it is, continue to the next round of adjustment until the entire system achieves load balance again; otherwise, it means that the current statistical cycle has achieved load balance.
  • the value of the fourth set threshold is not limited, and can be set according to the actual scene.
  • the number of adjustments to the server list in the current statistical cycle is controlled, so as to achieve load balancing in the current statistical cycle and ensure that the system stability.
  • the embodiment of the present application proposes a load balancing method, device, electronic equipment, computer storage medium and computer program product.
  • the method includes: after receiving a connection request sent by each client among multiple clients, obtaining The load value of each server; according to the load value of each server, determine the server list of each client, and send the corresponding server list to each client; the server list includes at least two servers; after determining each client After establishing a TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server, determine the target server that does not meet the set load balancing conditions; Find the target client connected to the target server, and adjust the server list of the target client; the target client is one of the multiple clients.
  • the list of servers that each client is allowed to connect can be determined; that is, the client can be connected to To multiple servers with lower load values, so that the client's business volume can be sent to different servers for processing in a more balanced manner.
  • the client after the client establishes a connection with the server, if it is found that the target server does not meet the set load balancing conditions, then adjust the server list of the target client connected to the target server to achieve the purpose of controlling the overall load of the entire server cluster, Maintain the dynamic balance of the load value of each server to effectively solve the problem of server overload.
  • Fig. 2c is a schematic flow diagram of another load balancing method according to the embodiment of the present application. As shown in Fig. 2c, the flow may include:
  • Step A1 The server reports load determination parameters.
  • server 1 to server n respectively report to the scheduling module the load determination parameters in the latest statistical period;
  • the load determination parameters may include the number of server connections, the amount of messages processed by the server in the last statistical period, the last time the server was The time allotted to the client and the amount of messages processed for each connection session of the server.
  • Step A2 The client sends a connection request to the scheduling module.
  • the client needs to send service data to the server, it needs to send a connection request to the scheduling module.
  • Step A3 The scheduling module distributes the server list to the client.
  • the scheduling module determines the load value of each server according to the load determination parameters reported by each server, and then assigns corresponding server list, and send the corresponding server list to the client.
  • Step A4 The client establishes a connection with each server in the server list at the same time.
  • the server list of the client includes the server 1 and the server 2, that is, the client establishes a TCP long connection with the server 1 and the server 2 at the same time.
  • Step A5 The client polls to send business data.
  • the client after determining that the client establishes the TCP long connection with the server 1 and the server 2, the client sends service data to the server 1 and the server 2 that have established the TCP long connection in a polling manner.
  • any server when any server receives the business data sent by the client, it will count the load determination parameters of the latest statistical period, and report the above load determination data to the scheduling module at regular intervals; in this way, the scheduling module can determine the load based on the load. Data, reacquire the load value of each server in the current network; and according to the reacquired load value, determine whether the server connected to the client meets the load balancing conditions, if not, adjust the server list of the client, so that the server with the client Each server connected to the end is in a balanced state.
  • the newly added monitoring module is connected between the scheduling module and each server, so that each The statistics and monitoring of the load determination parameters of each server, and report the load determination parameters of each server obtained from the statistics to the scheduling module; then control the list of servers connected to the client through the scheduling module; that is, complete the server part through the monitoring module tasks, which can improve the processing capacity of the entire server cluster.
  • Fig. 3 is a schematic diagram of the composition and structure of a load balancing device according to an embodiment of the present application. As shown in Fig. 3 , the device includes a first determination module 300, a second determination module 301 and an adjustment module 302, wherein,
  • the first determination module 300 is configured to obtain the load value of each server in the current network after receiving the connection request sent by each client in the plurality of clients; determine the load value of each server according to the load value of each server A server list of a client, and a corresponding server list is issued to each client; the server list includes at least two servers;
  • the second determination module 301 is configured to reacquire the load value of each server in the current network after determining that each client establishes a transmission control protocol TCP long connection with each server in the corresponding server list; Get the load value of each server to determine the target server that does not meet the set load balancing conditions;
  • the adjustment module 302 is configured to search for a target client connected to the target server, and adjust the server list of the target client; the target client is one of the multiple clients.
  • the adjustment module 302 is configured to find the target client connected to the target server, including:
  • the target server According to the amount of messages sent by each of the at least two clients to the target server, from among the at least two clients, determine the client that sends the smallest amount of messages as the target client, or , determining any client whose message volume is less than or equal to the first set threshold as the target client.
  • the second determination module 301 is configured to determine the target server that does not meet the set load balancing condition according to the re-acquired load value of each server, including:
  • the server with the highest load value and the server with the lowest load value are obtained; when it is determined that the load difference between the server with the highest load value and the server with the lowest load value is greater than a second set threshold, The server with the highest load value is determined as the target server that does not meet the set load balancing condition; or,
  • the adjustment module 302 is configured to adjust the server list of the target client, including:
  • the server with the highest load value in the server list of the target client is removed, and a server with the lowest current load value is added to the server list of the target client.
  • the device further includes a receiving module configured to:
  • the load determination parameters include the number of connections of the server, the server's last statistics At least one of the periodic processing message volume and the last time the server was assigned to the client;
  • the first determining module 300 is configured to obtain the load value of each server in the current network, including:
  • the load value of each server in the current network is determined according to the load determination parameters reported by each server in the current network.
  • the load determination parameters when the load determination parameters include the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the time when the server was allocated to the client last time, the load determination parameters further include connection The weight value of the number, the weight value of the processing message volume, and the weight value of the time parameter;
  • the first determination module 300 is configured to determine the load value of each server in the current network according to the load determination parameters reported by each server in the current network, including:
  • the time parameter weight value determines the load value of each server in the current network.
  • the adjustment module 302 is further configured to:
  • Whether to continue to adjust the server list in the current statistical period is determined according to the relationship between the adjusted session ratio and the fourth set threshold.
  • the adjustment module 302 is configured to determine whether to continue adjusting the server list in the current statistical period according to the relationship between the adjustment session ratio and the fourth set threshold, including:
  • the above-mentioned first determination module 300, second determination module 301, adjustment module 302 and receiving module can all be realized by a processor located in an electronic device, and the processor can be ASIC, DSP, DSPD, PLD, FPGA , CPU, controller, microcontroller, microprocessor at least one.
  • each functional module in this embodiment may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units can be implemented in the form of hardware or in the form of software function modules.
  • the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium.
  • the technical solution of this embodiment is essentially or The contribution made by related technologies or all or part of the technical solution can be embodied in the form of software products, the computer software products are stored in a storage medium, and include several instructions to make a computer device (which can be a personal computer) , server, or network device, etc.) or a processor (processor) executes all or part of the steps of the method in this embodiment.
  • the aforementioned storage medium includes: various media that can store program codes such as U disk, mobile hard disk, read-only memory (Read Only Memory, ROM), RAM, magnetic disk or optical disk.
  • the computer program instructions corresponding to a load balancing method in this embodiment can be stored on a storage medium such as an optical disk, a hard disk, or a USB flash drive.
  • a storage medium such as an optical disk, a hard disk, or a USB flash drive.
  • FIG. 4 shows an electronic device 400 provided by an embodiment of the present application, which may include: a memory 401 and a processor 402; wherein,
  • memory 401 configured to store computer programs and data
  • the processor 402 is configured to execute a computer program stored in a memory, so as to implement any one of the load balancing methods in the foregoing embodiments.
  • the above-mentioned memory 401 can be a volatile memory (volatile memory), such as RAM; or a non-volatile memory (non-volatile memory), such as ROM, flash memory (flash memory), hard disk (Hard Disk Drive, HDD) or solid-state drive (Solid-State Drive, SSD); or a combination of the above-mentioned types of memory, and provide instructions and data to the processor 402.
  • volatile memory such as RAM
  • non-volatile memory such as ROM, flash memory (flash memory), hard disk (Hard Disk Drive, HDD) or solid-state drive (Solid-State Drive, SSD); or a combination of the above-mentioned types of memory, and provide instructions and data to the processor 402.
  • the aforementioned processor 402 may be at least one of ASIC, DSP, DSPD, PLD, FPGA, CPU, controller, microcontroller, and microprocessor. It can be understood that, for different load balancing devices, the electronic device used to implement the above processor function may also be other, which is not specifically limited in this embodiment of the present application.
  • the embodiment of the present application also provides a computer program product, the computer program product carries a program code, and the instructions included in the program code can be used to execute the load balancing method described in the above method embodiment, for details, please refer to the above method embodiment , which will not be repeated here.
  • the above-mentioned computer program product may be specifically implemented by means of hardware, software or a combination thereof.
  • the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (Software Development Kit, SDK) etc. wait.
  • a software development kit Software Development Kit, SDK
  • the functions or modules included in the device provided by the embodiments of the present application can be used to execute the methods described in the above method embodiments, and its specific implementation can refer to the descriptions of the above method embodiments. For brevity, here No longer.
  • the embodiments of the present application may be provided as methods, systems, or computer program products. Accordingly, the present application may take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) having computer-usable program code embodied therein.
  • a computer-usable storage media including but not limited to disk storage and optical storage, etc.

Abstract

Embodiments of the present application provide a load balancing method and apparatus, an electronic device, a computer storage medium and a computer program product. The method comprises: after receiving a connection request sent by each client among a plurality of clients, acquiring a load value of each server in a current network; determining a server list of each client according to the load value of each server, and issuing a corresponding server list to each client, the server list comprising at least two servers; after determining that each client establishes a TCP long connection with each server in the corresponding server list, reacquiring a load value of each server in the current network; according to the reacquired load value of each server, determining a target server that does not meet a set load balancing condition; and finding a target client connected to the target server, and adjusting the server list of the target client, the target client being one client among the plurality of clients. The method may effectively solve the problem of server overload.

Description

一种负载均衡方法、装置、设备、计算机存储介质和程序A load balancing method, device, equipment, computer storage medium and program
相关申请的交叉引用Cross References to Related Applications
本申请基于申请号为202111165088.9、申请日为2021年09月30日的中国专利申请提出,申请人为深圳前海微众银行股份有限公司,申请名称为“一种负载均衡方法、装置、设备和计算机存储介质”的技术方案,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。This application is based on a Chinese patent application with application number 202111165088.9 and an application date of September 30, 2021. The applicant is Shenzhen Qianhai WeBank Co., Ltd., and the application name is "a load balancing method, device, equipment and computer storage medium” and claim the priority of this Chinese patent application. The entire content of this Chinese patent application is hereby incorporated into this application as a reference.
技术领域technical field
本申请涉及金融科技(Fintech)的云计算技术领域,涉及但不限于一种负载均衡方法、装置、电子设备、计算机存储介质和计算机程序产品。The present application relates to the technical field of cloud computing of financial technology (Fintech), involving but not limited to a load balancing method, device, electronic equipment, computer storage medium and computer program product.
背景技术Background technique
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技转变,但由于金融行业的安全性、实时性要求,也对技术提出了更高的要求。With the development of computer technology, more and more technologies are applied in the financial field, and the traditional financial industry is gradually transforming into financial technology. However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology.
相关技术中,针对负载均衡,存在基于硬件的F5设备、基于软件的Nginx(engine x)、Linux虚拟服务器(Linux Virtual Server,LVS)等几种典型的负载均衡方案;然而,上述方案在使用传输控制协议(Transmission Control Protocol,TCP)长连接的情况下,难以确保负载均衡器后面的各个服务器节点所处理的消息量是相对均衡的;即,很可能存在将很多业务量高的业务网际互连协议(Internet Protocol,IP)同时发送到同一个处理服务器节点上,造成服务器过载的问题,进而,影响整个服务器集群的处理能力。In related technologies, for load balancing, there are several typical load balancing schemes such as hardware-based F5 equipment, software-based Nginx (engine x), and Linux Virtual Server (Linux Virtual Server, LVS); In the case of Transmission Control Protocol (TCP) long connections, it is difficult to ensure that the amount of messages processed by each server node behind the load balancer is relatively balanced; Protocol (Internet Protocol, IP) is sent to the same processing server node at the same time, causing the problem of server overload, which in turn affects the processing capacity of the entire server cluster.
发明内容Contents of the invention
本申请提供一种负载均衡方法、装置、电子设备、计算机存储介质和计算机程序产品,可以解决相关技术中在基于TCP长连接进行消息传输时的服务器过载问题。The present application provides a load balancing method, device, electronic equipment, computer storage medium, and computer program product, which can solve the problem of server overload in the related art when transmitting messages based on TCP long connections.
本申请的技术方案是这样实现的:The technical scheme of the present application is realized like this:
本申请实施例提供了一种负载均衡方法,所述方法包括:An embodiment of the present application provides a load balancing method, the method comprising:
接收到多个客户端中每个客户端发送的连接请求后,获取当前网络中每个服务器的负载值;根据所述每个服务器的负载值,确定所述每个客户端的服务器清单,向所述每个客户端下发对应的服务器清单;所述服务器清单中包括至少两个服务器;After receiving the connection request sent by each client in the multiple clients, obtain the load value of each server in the current network; determine the server list of each client according to the load value of each server, and send to the Each client sends a corresponding server list; the server list includes at least two servers;
在确定所述每个客户端与对应的服务器清单中每个服务器建立TCP长连接后,重新获取所述当前网络中每个服务器的负载值;根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器;After determining that each client establishes a TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server, determine whether The target server that satisfies the set load balancing conditions;
查找与所述目标服务器连接的目标客户端,调整所述目标客户端的服务器清单;所述目标客户端为所述多个客户端中的一个客户端。Searching for a target client connected to the target server, and adjusting the server list of the target client; the target client is one of the multiple clients.
在一些实施例中,所述查找与所述目标服务器连接的目标客户端,包括:In some embodiments, the searching for a target client connected to the target server includes:
获取与所述目标服务器建立TCP长连接的至少两个客户端;Obtain at least two clients establishing TCP long connections with the target server;
根据所述至少两个客户端中每个客户端向所述目标服务器发送的消息量,从所述至少两个客户端中,将发送消息量最小的客户端确定为所述目标客户端,或者,将发送消息量小于或等于第一设定阈值的任一客户端确定为所述目标客户端。According to the amount of messages sent by each of the at least two clients to the target server, from among the at least two clients, determine the client that sends the smallest amount of messages as the target client, or , determining any client whose message volume is less than or equal to the first set threshold as the target client.
可以理解地,由于目标服务器是当前网络中不满足设定负载均衡条件的服务器,因而,需要对目标服务器的负载值进行调整使其达到均衡状态;而目标服务器的负载值是由其连接的每个客户端发送的消息量确定的,因而,基于每个客户端向所述目标服务器发送的消息量,可以有针对性地确定目标客户端;另外,从与目标服务器连接的每个客户端中,选择发送消息量最小或小于某一设定阈值的客户端作为目标客户端,可以有效防止后续对目标服务器进行负载调整时的抖动问题,确保系统的稳定性。Understandably, since the target server is a server that does not meet the set load balancing conditions in the current network, it is necessary to adjust the load value of the target server to achieve a balanced state; The amount of messages sent by each client is determined, therefore, based on the amount of messages sent by each client to the target server, the target client can be determined in a targeted manner; in addition, from each client connected to the target server , select the client with the smallest amount of messages sent or less than a certain threshold as the target client, which can effectively prevent the jitter problem during the subsequent load adjustment of the target server and ensure the stability of the system.
在一些实施例中,所述根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器,包括:In some embodiments, the determining the target server that does not meet the set load balancing condition according to the load value of each server obtained again includes:
对所述重新获取的每个服务器的负载值进行排序,得到排序结果;Sorting the load values of each server obtained again to obtain a sorting result;
从所述排序结果中,得到负载值最高的服务器与负载值最低的服务器;在确定所述负载值最高的服务器与所述负载值最低的服务器的负载差值大于第二设定阈值时,将所述负载值最高的服务器确定为不满足所述设定负载均衡条件的目标服务器;或者,From the sorting results, the server with the highest load value and the server with the lowest load value are obtained; when it is determined that the load difference between the server with the highest load value and the server with the lowest load value is greater than a second set threshold, The server with the highest load value is determined as the target server that does not meet the set load balancing condition; or,
将所述排序结果中负载值大于第三设定阈值的任一服务器确定为不满足所述设定负载均衡条件的目标服务器。Determining any server with a load value greater than a third set threshold in the sorting result as a target server that does not satisfy the set load balancing condition.
可以看出,本申请实施例,在获取到每个服务器的负载值后,通过对每个服务器的负载值进行排序,可以更加直观地从排序结果中确定出不满足设定负载均衡条件的目标服务器。另外,通过将负载值最高或大于某一设定阈值的服务器确定为目标服务器,以进行后续的负载均衡调整,可以避免因为该目标服务器处理能力低下,而影响整个服务器集群的处理能力。It can be seen that in the embodiment of the present application, after obtaining the load value of each server, by sorting the load value of each server, it is possible to more intuitively determine the target that does not meet the set load balancing conditions from the sorting results. server. In addition, by determining the server with the highest load value or greater than a certain threshold as the target server for subsequent load balancing adjustments, it is possible to avoid affecting the processing capacity of the entire server cluster due to the low processing capacity of the target server.
在一些实施例中,所述调整所述目标客户端的服务器清单,包括:In some embodiments, the adjusting the server list of the target client includes:
将所述目标客户端的服务器清单中负载值最高的服务器移除,并向所述目标客户端的服务器清单中新增一个当前负载值最低的服务器。The server with the highest load value in the server list of the target client is removed, and a server with the lowest current load value is added to the server list of the target client.
可以看出,本申请实施例通过将目标客户端的服务器清单中负载值最高的服务器移除,可以降低因该服务器继续处理目标客户端的业务数据而 出现过载的风险。It can be seen that in the embodiment of the present application, by removing the server with the highest load value from the server list of the target client, the risk of overload due to the server continuing to process the business data of the target client can be reduced.
在一些实施例中,所述方法还包括:In some embodiments, the method also includes:
在接收所述多个客户端中每个客户端发送的连接请求之前,接收所述当前网络中每个服务器上报的负载确定参数;所述负载确定参数包括服务器的连接数、服务器在上一统计周期的处理消息量以及服务器上次被分配给客户端的时间中的至少一项;Before receiving the connection request sent by each client in the multiple clients, receive the load determination parameters reported by each server in the current network; the load determination parameters include the number of connections of the server, the server's last statistics At least one of the periodic processing message volume and the last time the server was assigned to the client;
所述获取当前网络中每个服务器的负载值,包括:The acquisition of the load value of each server in the current network includes:
根据所述当前网络中每个服务器上报的负载确定参数,确定当前网络中每个服务器的负载值。The load value of each server in the current network is determined according to the load determination parameters reported by each server in the current network.
可以看出,本申请实施例,基于当前网络中每个服务器上报的负载确定参数,可以准确地得到每个服务器的负载值。It can be seen that in this embodiment of the present application, based on the load determination parameters reported by each server in the current network, the load value of each server can be accurately obtained.
在一些实施例中,在所述负载确定参数包括服务器的连接数、服务器在上一统计周期的处理消息量以及服务器上次被分配给客户端的时间的情况下,所述负载确定参数还包括连接数权重值、处理消息量权重值、以及时间参数权重值;In some embodiments, when the load determination parameters include the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the time when the server was allocated to the client last time, the load determination parameters further include connection The weight value of the number, the weight value of the processing message volume, and the weight value of the time parameter;
所述根据所述当前网络中每个服务器上报的负载确定参数,确定当前网络中每个服务器的负载值,包括:The determining the load value of each server in the current network according to the load determination parameters reported by each server in the current network includes:
根据所述当前网络中每个服务器上报的服务器的连接数与所述连接数权重值、服务器在上一统计周期的处理消息量与处理消息量权重值、服务器上次被分配给客户端的时间与时间参数权重值,确定当前网络中每个服务器的负载值。According to the number of server connections reported by each server in the current network and the weight value of the number of connections, the amount of messages processed by the server in the last statistical period and the weight value of the amount of messages processed, the time when the server was assigned to the client last time and The time parameter weight value determines the load value of each server in the current network.
可以看出,本申请实施例,通过对负载确定参数中包括的参数作进一步限定,可以更加准确地得到当前网络中每个服务器的负载值。It can be seen that in the embodiment of the present application, by further limiting the parameters included in the load determination parameters, the load value of each server in the current network can be obtained more accurately.
在一些实施例中,所述方法还包括:In some embodiments, the method also includes:
在当前统计周期内,每完成一次服务器清单的调整,对调整次数执行加1操作;In the current statistical period, every time the adjustment of the server list is completed, the number of adjustments will be increased by 1;
计算所述当前统计周期内调整所述服务器清单的总调整次数与所述当前网路中每个服务器的总连接数的比值,得到所述当前统计周期的调整会话占比;Calculating the ratio of the total number of times of adjusting the server list in the current statistical period to the total number of connections of each server in the current network to obtain the proportion of adjusted sessions in the current statistical period;
根据所述调整会话占比与第四设定阈值的大小关系,确定是否继续调整所述当前统计周期内的服务器清单。Whether to continue to adjust the server list in the current statistical period is determined according to the relationship between the adjusted session ratio and the fourth set threshold.
可以看出,本申请实施例,通过当前统计周期的调整会话占比对当前统计周期的服务器清单的调整次数进行控制,可以防止因出现大面积的服务器连接调整而导致系统稳定性差的问题。It can be seen that in this embodiment of the application, the number of adjustments to the server list in the current statistical cycle is controlled by adjusting the session ratio of the current statistical cycle, which can prevent the problem of poor system stability caused by large-scale server connection adjustments.
在一些实施例中,所述根据所述调整会话占比与第四设定阈值的大小关系,确定是否继续调整所述当前统计周期内的服务器清单,包括:In some embodiments, the determining whether to continue adjusting the server list in the current statistical period according to the size relationship between the adjusted session ratio and the fourth set threshold includes:
在确定所述调整会话占比大于或等于所述第四设定阈值时,等待所述当前统计周期结束;When it is determined that the adjusted session proportion is greater than or equal to the fourth set threshold, waiting for the end of the current statistics period;
在确定所述调整会话占比小于所述第四设定阈值、且确定存在不满足设定负载均衡条件的目标服务器时,继续调整所述当前统计周期内的服务器清单。When it is determined that the adjusted session proportion is less than the fourth set threshold and it is determined that there is a target server that does not meet the set load balancing condition, continue to adjust the server list in the current statistical period.
可以看出,本申请实施例,通过调整会话占比与第四设定阈值的大小关系,对当前统计周期的服务器清单的调整次数进行控制,实现在当前统计周期负载均衡的同时还可以确保系统的稳定性。It can be seen that in the embodiment of the present application, by adjusting the relationship between the session ratio and the fourth threshold, the number of adjustments to the server list in the current statistical cycle is controlled, so as to achieve load balancing in the current statistical cycle and ensure that the system stability.
本申请实施例还提出了一种负载均衡装置,所述装置包括第一确定模块、第二确定模块和调整模块,其中,The embodiment of the present application also proposes a load balancing device, the device includes a first determination module, a second determination module and an adjustment module, wherein,
第一确定模块,配置为接收到多个客户端中每个客户端发送的连接请求后,获取当前网络中每个服务器的负载值;根据所述每个服务器的负载值,确定所述每个客户端的服务器清单,向所述每个客户端下发对应的服务器清单;所述服务器清单中包括至少两个服务器;The first determining module is configured to obtain the load value of each server in the current network after receiving the connection request sent by each client in the plurality of clients; determine the load value of each server according to the load value of each server A server list of the client, sending a corresponding server list to each client; the server list includes at least two servers;
第二确定模块,配置为在确定所述每个客户端与对应的服务器清单中每个服务器建立TCP长连接后,重新获取所述当前网络中每个服务器的负载值;根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器;The second determination module is configured to reacquire the load value of each server in the current network after determining that each client establishes a TCP long connection with each server in the corresponding server list; The load value of the server determines the target server that does not meet the set load balancing conditions;
调整模块,配置为查找与所述目标服务器连接的目标客户端,调整所述目标客户端的服务器清单;所述目标客户端为所述多个客户端中的一个客户端。An adjustment module, configured to search for a target client connected to the target server, and adjust the server list of the target client; the target client is one of the plurality of clients.
本申请实施例提供一种电子设备,所述设备包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现前述一个或多个技术方案提供的负载均衡方法。An embodiment of the present application provides an electronic device, the device includes a memory, a processor, and a computer program stored on the memory and operable on the processor, and the processor implements one or more of the aforementioned technologies when executing the program The load balancing method provided by the solution.
本申请实施例提供一种计算机存储介质,所述计算机存储介质存储有计算机程序;所述计算机程序被执行后能够实现前述一个或多个技术方案提供的负载均衡方法。An embodiment of the present application provides a computer storage medium, where the computer storage medium stores a computer program; after the computer program is executed, the load balancing method provided by the foregoing one or more technical solutions can be implemented.
本申请实施例还提供了一种计算机程序产品,包括计算机可读代码,当所述计算机可读代码在电子设备中运行时,所述电子设备中的处理器执行用于实现前述一个或多个技术方案提供的负载均衡方法。The embodiment of the present application also provides a computer program product, including computer readable code, when the computer readable code is run in the electronic device, the processor in the electronic device executes to implement the aforementioned one or more The load balancing method provided by the technical solution.
本申请实施例提出了一种负载均衡方法、装置、电子设备、计算机存储介质和计算机程序产品,所述方法包括:接收到多个客户端中每个客户端发送的连接请求后,获取当前网络中每个服务器的负载值;根据所述每个服务器的负载值,确定所述每个客户端的服务器清单,向所述每个客户端下发对应的服务器清单;所述服务器清单中包括至少两个服务器;在确定所述每个客户端与对应的服务器清单中每个服务器建立TCP长连接后,重新获取所述当前网络中每个服务器的负载值;根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器;查找与所述目标服务器连接的目标客户端,调整所述目标客户端的服务器清单;所述目标客户端为所述多个客户端中的一个客户端。The embodiment of the present application proposes a load balancing method, device, electronic equipment, computer storage medium and computer program product. The method includes: after receiving a connection request sent by each client among multiple clients, obtaining the current network The load value of each server; according to the load value of each server, determine the server list of each client, and send the corresponding server list to each client; the server list includes at least two server; after determining that each client establishes a TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server , determine the target server that does not meet the set load balancing conditions; find the target client connected to the target server, adjust the server list of the target client; the target client is one of the multiple clients end.
可以看出,本申请实施例中,在客户端与服务器建立连接之前,通过获取当前网络中每个服务器的负载值,可以确定允许每个客户端连接的服务器清单;即,可以将客户端连接到多个负载值较低的服务器上,使得该客户端的业务量更加均衡的发送到不同的服务器上进行处理。进一步地,在客户端与服务器建立连接之后,如果发现不满足设定负载均衡条件的目标服务器,则调整与该目标服务器连接的目标客户端的服务器清单,达到控制整个服务器集群的综合负载的目的,保持每个服务器负载值的动态均衡,有效解决服务器过载的问题。It can be seen that in the embodiment of the present application, before the client establishes a connection with the server, by obtaining the load value of each server in the current network, the list of servers that each client is allowed to connect can be determined; that is, the client can be connected to To multiple servers with lower load values, so that the client's business volume can be sent to different servers for processing in a more balanced manner. Further, after the client establishes a connection with the server, if it is found that the target server does not meet the set load balancing conditions, then adjust the server list of the target client connected to the target server to achieve the purpose of controlling the overall load of the entire server cluster, Maintain the dynamic balance of the load value of each server to effectively solve the problem of server overload.
附图说明Description of drawings
图1a是相关技术中的一种负载均衡的结构示意图;FIG. 1a is a schematic structural diagram of a load balancing in the related art;
图1b是相关技术中的另一种负载均衡的结构示意图;FIG. 1b is a schematic structural diagram of another load balancing in the related art;
图2a是本申请实施例中的一种负载均衡方法的流程示意图;FIG. 2a is a schematic flow diagram of a load balancing method in an embodiment of the present application;
图2b是本申请实施例中的一种负载均衡调整的结构示意图;FIG. 2b is a schematic structural diagram of a load balancing adjustment in an embodiment of the present application;
图2c为本申请实施例的另一种负载均衡方法的流程示意图;FIG. 2c is a schematic flow diagram of another load balancing method according to an embodiment of the present application;
图2d是本申请实施例中的另一种负载均衡调整的结构示意图;FIG. 2d is a schematic structural diagram of another load balancing adjustment in the embodiment of the present application;
图3是本申请实施例的负载均衡装置的组成结构示意图;FIG. 3 is a schematic diagram of the composition and structure of a load balancing device according to an embodiment of the present application;
图4是本申请实施例提供的电子设备的结构示意图。FIG. 4 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
具体实施方式Detailed ways
以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所提供的实施例仅仅用以解释本申请,并不用于限定本申请。另外,以下所提供的实施例是用于实施本申请的部分实施例,而非提供实施本申请的全部实施例,在不冲突的情况下,本申请实施例记载的技术方案可以任意组合的方式实施。The present application will be described in further detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the embodiments provided here are only used to explain the present application, and are not intended to limit the present application. In addition, the embodiments provided below are some embodiments for implementing the application, rather than providing all the embodiments for implementing the application. In the case of no conflict, the technical solutions described in the embodiments of the application can be combined in any manner implement.
需要说明的是,在本申请实施例中,术语“包括”、“包含”或者其任何其它变体意在涵盖非排他性的包含,从而使得包括一系列要素的方法或者装置不仅包括所明确记载的要素,而且还包括没有明确列出的其它要素,或者是还包括为实施方法或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个......”限定的要素,并不排除在包括该要素的方法或者装置中还存在另外的相关要素(例如方法中的步骤或者装置中的单元,例如的单元可以是部分电路、部分处理器、部分程序或软件等等)。It should be noted that, in the embodiments of the present application, the term "comprising", "comprising" or any other variation thereof is intended to cover a non-exclusive inclusion, so that a method or device comprising a series of elements not only includes the explicitly stated elements, but also include other elements not explicitly listed, or also include elements inherent in implementing the method or apparatus. Without further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional related elements (such as steps in the method or A unit in an apparatus, for example, a unit may be part of a circuit, part of a processor, part of a program or software, etc.).
本文中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,I和/或J,可以表示:单独存在I,同时存在I和J,单独存在J这三种情况。另外,本文中术语“至少一种”表示多种中的任意一种或多种中的至少两种的任意组合,例如,包括I、J、R中的至少一种,可以表示包括从I、J和R构成的集合中选择的任意一个或多个元素。The term "and/or" in this article is just an association relationship describing associated objects, which means that there can be three kinds of relationships, for example, I and/or J, which can mean: I exists alone, I and J exist at the same time, and I exist alone J these three situations. In addition, the term "at least one" herein means any one of a variety or any combination of at least two of the more, for example, including at least one of I, J, R, may mean including from I, Any one or more elements selected from the set formed by J and R.
例如,本申请实施例提供的负载均衡方法包含了一系列的步骤,但是 本申请实施例提供的负载均衡方法不限于所记载的步骤,同样地,本申请实施例提供的负载均衡装置包括了一系列模块,但是本申请实施例提供的负载均衡装置不限于包括所明确记载的模块,还可以包括为获取相关任务数据、或基于任务数据进行处理时所需要设置的模块。For example, the load balancing method provided in the embodiment of the present application includes a series of steps, but the load balancing method provided in the embodiment of the present application is not limited to the steps described. Similarly, the load balancing device provided in the embodiment of the present application includes a A series of modules, but the load balancing device provided by the embodiment of the present application is not limited to include the explicitly recorded modules, and may also include modules that need to be set up to obtain relevant task data or process based on task data.
本申请实施例可以应用于服务端组成的计算机系统中,并可以与众多其它通用或专用计算系统环境或配置一起操作。这里,服务端可以是包括小型计算机系统﹑大型计算机系统的分布式云计算技术环境,等等。The embodiments of the present application can be applied to a computer system composed of servers, and can operate together with many other general-purpose or special-purpose computing system environments or configurations. Here, the server may be a distributed cloud computing technology environment including a small computer system, a large computer system, and so on.
服务端等电子设备可以通过程序模块的执行实现相应的功能。通常,程序模块可以包括例程、程序、目标程序、组件、逻辑、数据结构等等,它们执行特定的任务或者实现特定的抽象数据类型。计算机系统/服务端可以在分布式云计算环境中实施,分布式云计算环境中,任务是由通过通信网络链接的远程处理设备执行的。在分布式云计算环境中,程序模块可以位于包括存储设备的本地或远程计算系统存储介质上。Electronic devices such as the server can realize corresponding functions through the execution of program modules. Generally, program modules may include routines, programs, objects, components, logic, data structures, etc., that perform particular tasks or implement particular abstract data types. The computer system/server can be practiced in distributed cloud computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed cloud computing environment, program modules may be located in both local and remote computing system storage media including storage devices.
目前,基于TCP的连接有长连接和短连接,其中对处理消息量大、实时性要求高的场景,都会选择使用TCP长连接来保证系统的吞吐率和时延低。At present, TCP-based connections include long connections and short connections. For scenarios with a large amount of messages to be processed and high real-time requirements, TCP long connections will be used to ensure low system throughput and delay.
对于大多数应用场景,采用基于硬件的F5设备,或基于软件的Nginx、LVS等几种典型的负载均衡方案是可以很好满足的,但也有例外,如果希望在使用TCP长连接的情况下,确保负载均衡器后面的各个服务器节点处理的消息量相对均衡,采用上述方案是难以实现的。For most application scenarios, hardware-based F5 devices, or software-based Nginx, LVS and other typical load balancing solutions can be well satisfied, but there are exceptions. If you want to use TCP long-term connections, It is difficult to ensure that the amount of messages processed by each server node behind the load balancer is relatively balanced by using the above scheme.
这是因为不同类型的业务,其数据传输的量级往往是相差很大的,有些业务的IP实例的处理量可能只有几笔业务,而有些业务的IP实例可能会有几十万,甚至上百万的业务量,所以对于这两类业务的IP实例,不管采集何种负载均衡的调度算法,一旦负载均衡调度器做完决策后,业务IP根据负载均衡调度器分配的服务器连接成功后,负载均衡调度器就不再干预业务IP与服务器间的数据交换,因此,难免会导致服务器节点处理的消息量存在较大的差别,这可能存在很多业务量高的IP会同时发送到同一个处理服务器节点上的情况,造成服务器过载;下面通过图1a进行说明,如图1a所示,客户端1和客户端2传输的数据流量都是3Kb/s,但是客户端3和客户端4传输的数据流量是1Mb/s;负载均衡调度器按连接数来分配,服务器1和服务器2都分到了两个连接,但是这两个服务器处理的消息量完全不在一量级上。This is because the magnitude of data transmission for different types of businesses often varies greatly. Some business IP instances may only handle a few transactions, while some business IP instances may have hundreds of thousands, or even over 100,000 transactions. Millions of business volume, so for the IP instances of these two types of business, no matter what kind of load balancing scheduling algorithm is collected, once the load balancing scheduler makes a decision and the business IP is successfully connected to the server assigned by the load balancing scheduler, The load balancing scheduler will no longer intervene in the data exchange between the business IP and the server. Therefore, it will inevitably lead to a large difference in the amount of messages processed by the server node. This may cause many IPs with high business volume to be sent to the same processing server at the same time. The situation on the server node caused the server to be overloaded; as shown in Figure 1a, the data traffic transmitted by client 1 and client 2 is 3Kb/s, but the data traffic transmitted by client 3 and client 4 is The data traffic is 1Mb/s; the load balancing scheduler allocates according to the number of connections. Both server 1 and server 2 are allocated two connections, but the amount of messages processed by these two servers is not at the same level at all.
相关技术中,对于基于TCP长连接的负载均衡,也有主流的解决方案,其核心思路可以参照图1b;通过引入反向代理服务器,并建立反向代理服务器与每个客户端之间的连接,保持客户端与服务器之间的TCP长连接会话,然后使用一定的负载均衡算法,将消息转发给后端的服务器集群(服务器1至服务器n);这里,使用的负载均衡算法有:平均负载、轮询负载、优先群组等。In related technologies, there are also mainstream solutions for load balancing based on TCP long connections, and its core idea can be referred to in Figure 1b; by introducing a reverse proxy server and establishing a connection between the reverse proxy server and each client, Keep the TCP long connection session between the client and the server, and then use a certain load balancing algorithm to forward the message to the back-end server cluster (server 1 to server n); here, the load balancing algorithms used are: average load, round-robin Inquiry load, priority group, etc.
可以看出,上述方案虽然可以解决TCP长连接情况下,服务器的负载均衡问题,但是该方案存在以下缺点:It can be seen that although the above solution can solve the load balancing problem of the server in the case of TCP long connection, the solution has the following disadvantages:
1)在其中一个服务器异常时,需要客户端重新连接反向代理服务器,这样会影响客户端与服务器断连期间的业务。1) When one of the servers is abnormal, the client needs to reconnect to the reverse proxy server, which will affect the business during the disconnection between the client and the server.
2)反向代理服务器也有可能存在网卡容量或是连接数上限的问题。2) The reverse proxy server may also have problems with the capacity of the network card or the upper limit of the number of connections.
3)反向代理服务器的处理能力不够时,难以完成服务器的扩容。3) When the processing capacity of the reverse proxy server is not enough, it is difficult to complete the expansion of the server.
可见,通过引入反向代理服务器虽然可以解决TCP长连接情况下,服务器的负载均衡问题,但是因为上述缺点使得该方案具有一定的难度。It can be seen that although the introduction of a reverse proxy server can solve the problem of server load balancing in the case of TCP long connections, the above-mentioned shortcomings make this solution difficult.
针对上述技术问题,提出以下各实施例。In view of the above technical problems, the following embodiments are proposed.
在本申请的一些实施例中,负载均衡方法可以利用负载均衡装置中的处理器实现,上述处理器可以为特定用途集成电路(Application Specific Integrated Circuit,ASIC)、数字信号处理器(Digital Signal Processor,DSP)、数字信号处理装置(Digital Signal Processing Device,DSPD)、可编程逻辑装置(Programmable Logic Device,PLD)、现场可编程逻辑门阵列(Field Programmable Gate Array,FPGA)、中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器中的至少一种。In some embodiments of the present application, the load balancing method can be realized by using a processor in the load balancing device, and the processor can be an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (Digital Signal Processor, DSP), digital signal processing device (Digital Signal Processing Device, DSPD), programmable logic device (Programmable Logic Device, PLD), field programmable logic gate array (Field Programmable Gate Array, FPGA), central processing unit (Central Processing Unit , CPU), controller, microcontroller, microprocessor at least one.
图2a是本申请实施例中的一种负载均衡方法的流程示意图,如图2a所示,该方法包括如下步骤:Figure 2a is a schematic flow diagram of a load balancing method in the embodiment of the present application, as shown in Figure 2a, the method includes the following steps:
步骤200:接收到多个客户端中每个客户端发送的连接请求后,获取当前网络中每个服务器的负载值;根据每个服务器的负载值,确定每个客户端的服务器清单,向每个客户端下发对应的服务器清单;服务器清单中包括至少两个服务器。Step 200: After receiving the connection request sent by each of the multiple clients, obtain the load value of each server in the current network; determine the server list of each client according to the load value of each server, and send each The client sends a corresponding server list; the server list includes at least two servers.
示例性地,客户端用来接入具体的业务数据,并将业务数据转发给后端的服务器,做后续进一步的处理;服务器属于后端处理模块,用于对客户端转发的业务数据进行加工处理。Exemplarily, the client is used to access specific business data and forward the business data to the back-end server for subsequent further processing; the server belongs to the back-end processing module and is used to process the business data forwarded by the client .
本申请实施例中,负载均衡方法是在客户端与服务器建立TCP长连接的情况下,对当前网络中各服务器的负载值进行均衡的一种方法;示例性地,在多个客户端中的每个客户端与服务器建立TCP长连接之前,客户端并不清楚当前网络中哪些服务器可用;因而,当每个客户端需要向服务器发送业务数据时,需要先向调度模块发送连接请求,这样,调度模块便可接收到多个客户端中每个客户端发送的连接请求。这里,通过引入调度模块,可以降低每个客户端与服务器之间的连接管理复杂度;下面结合图2b对调度模块进行具体说明。In the embodiment of the present application, the load balancing method is a method of balancing the load value of each server in the current network when the client establishes a TCP long connection with the server; Before each client establishes a TCP long connection with the server, the client does not know which servers are available in the current network; therefore, when each client needs to send business data to the server, it needs to first send a connection request to the scheduling module. In this way, The scheduling module can then receive the connection request sent by each client in the multiple clients. Here, by introducing the scheduling module, the complexity of connection management between each client and the server can be reduced; the scheduling module will be described in detail in conjunction with FIG. 2b below.
图2b是本申请实施例中的一种负载均衡调整的结构示意图,如图2b所示,该结构图包括:客户端1、客户端2、服务器1至服务器n以及调度模块;其中,调度模块的一端分别与客户端1、客户端2连接,负责接收这两个客户端发送的连接请求;调度模块的另一端分别与当前网络中的n个服务器连接,用于收集n个服务器中每个服务器上报的与自身负载情况相 关的数据;客户端1与服务器1和服务器2连接,客户端2与服务器2和服务器3连接;即,客户端可以同时连接多个服务器。Figure 2b is a schematic structural diagram of a load balancing adjustment in the embodiment of the present application, as shown in Figure 2b, the structural diagram includes: client 1, client 2, server 1 to server n, and a scheduling module; wherein, the scheduling module One end of the scheduling module is connected to client 1 and client 2 respectively, and is responsible for receiving the connection requests sent by these two clients; the other end of the scheduling module is respectively connected to n servers in the current network to collect The data related to its own load reported by the server; client 1 is connected to server 1 and server 2, and client 2 is connected to server 2 and server 3; that is, the client can connect to multiple servers at the same time.
可以看出,与相关技术中需要在客户端与服务器之间引入反向代理服务器相比,本申请实施例不需要引入反向代理服务器,而是由每个客户端直接与对应服务器进行连接,即,不需要通过反向代理服务器与每个服务器连接,因而可以解决相关技术因反向代理服务器存在网卡容量或连接数上限,导致负载均衡实现难度较高的问题;另外,本申请实施例允许客户端同时连接多个服务器节点;这样,在其中一个服务器异常时,客户端还可以通过其它服务器节点继续进行业务处理,即,不会影响客户端与异常服务器断连期间的业务,确保服务器的高可用;进一步地,在某个服务器出现下线、升级、重启等变更或异常时,本申请实施例中还可以快速完成服务器的扩容,可以解决相关技术因反向代理服务器处理能力有限,导致服务器扩容难度较高的问题。It can be seen that, compared with the need to introduce a reverse proxy server between the client and the server in the related art, the embodiment of the present application does not need to introduce a reverse proxy server, but each client directly connects to the corresponding server, That is, there is no need to connect to each server through the reverse proxy server, so it can solve the problem of high difficulty in implementing load balancing due to the upper limit of the network card capacity or connection number of the reverse proxy server in the related technology; in addition, the embodiment of the present application allows The client connects to multiple server nodes at the same time; in this way, when one of the servers is abnormal, the client can continue to process business through other server nodes, that is, it will not affect the business during the disconnection between the client and the abnormal server, ensuring the server's High availability; further, when a server is offline, upgraded, restarted, etc. changes or abnormalities occur, the expansion of the server can also be quickly completed in the embodiment of the application, which can solve the problem of related technologies due to the limited processing capacity of the reverse proxy server. The problem of high difficulty in server expansion.
在一些实施例中,上述方法还可以包括:在调度模块接收多个客户端中每个客户端发送的连接请求之前,接收当前网络中每个服务器上报的负载确定参数。In some embodiments, the above method may further include: before the scheduling module receives the connection request sent by each client among the plurality of clients, receiving load determination parameters reported by each server in the current network.
示例性地,负载确定参数可以包括服务器的连接数、服务器在上一统计周期的处理消息量以及服务器上次被分配给客户端的时间中的至少一项;这里,服务器的连接数表示在上一统计周期内服务器与客户端之间的连接数。Exemplarily, the load determination parameter may include at least one of the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the last time the server was assigned to the client; The number of connections between the server and the client during the statistical period.
示例性地,可以在服务器中预先设置统计周期和定时时间,这样,服务器可以统计每个统计周期内的负载确定参数,并在定时时间到来时,将距离定时时间最近的上一统计周期内的负载确定参数上报给调度模块。Exemplarily, the statistical cycle and timing time can be preset in the server, so that the server can count the load determination parameters in each statistical cycle, and when the timing time arrives, the load determination parameters in the last statistical cycle closest to the timing time The load determination parameters are reported to the scheduling module.
示例性地,获取当前网络中每个服务器的负载值,可以包括:调度模块根据当前网络中每个服务器上报的负载确定参数,确定当前网络中每个服务器在每个统计周期的负载值。Exemplarily, obtaining the load value of each server in the current network may include: the scheduling module determines the load value of each server in the current network in each statistical period according to the load determination parameters reported by each server in the current network.
在一些实施例中,在负载确定参数包括服务器的连接数、服务器在上一统计周期的处理消息量以及服务器上次被分配给客户端的时间的情况下,负载确定参数还包括连接数权重值、处理消息量权重值、以及时间参数权重值。In some embodiments, when the load determination parameters include the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the time when the server was allocated to the client last time, the load determination parameters also include the weight value of the number of connections, Process message volume weight value and time parameter weight value.
这里,连接数权重值、处理消息量权重值、以及时间参数权重值的取值可以根据实际场景进行设置,本申请实施例对此不作限定。Here, the weight value of the number of connections, the weight value of the processed message volume, and the weight value of the time parameter may be set according to actual scenarios, which are not limited in this embodiment of the present application.
示例性地,根据当前网络中每个服务器上报的负载确定参数,确定当前网络中每个服务器的负载值,可以包括:根据当前网络中每个服务器上报的服务器的连接数与连接数权重值、服务器在上一统计周期的处理消息量与处理消息量权重值、服务器上次被分配给客户端的时间与时间参数权重值,确定当前网络中每个服务器的负载值。Exemplarily, according to the load determination parameters reported by each server in the current network, determining the load value of each server in the current network may include: according to the number of connections of the server reported by each server in the current network and the weight value of the connection number, The amount of messages processed by the server in the last statistical cycle and the weight value of the amount of processed messages, the time when the server was assigned to the client last time and the weight value of time parameters determine the load value of each server in the current network.
示例性地,当调度模块接收到当前网络中每个服务器定时上报的负载 确定参数后,可以根据服务器负载评估公式(1),得到上一统计周期内每个服务器的负载值Lr。Exemplarily, after the scheduling module receives the load determination parameters regularly reported by each server in the current network, it can obtain the load value Lr of each server in the last statistical period according to the server load evaluation formula (1).
Lr=Abs(C-Min(C)-ΔC)*WC+Abs(M-Min(M)-ΔM)*WM+WT/(T-T1)%LMR   (1)Lr=Abs(C-Min(C)-ΔC)*WC+Abs(M-Min(M)-ΔM)*WM+WT/(T-T1)%LMR (1)
这里,Abs表示计算的绝对值;C表示服务器的连接数;Min(C)表示当前网络中所有服务器的连接数中,值最小的连接数;ΔC表示服务器连接数容差值,如果服务器间的连接数差值小于此值,即可认为服务器的连接数是均衡的;WC表示连接数在服务器负载评估公式中所占的权重值,对应上述连接数权重值。M表示服务器在上一统计周期的处理消息量;Min(M)表示在上一统计周期,所有服务器中处理消息量最少的处理消息量;ΔM表示处理消息量容差值,如果服务器间的处理消息量差值小于此值,即可认为服务器处理的消息是均衡的;WM表示处理消息量在服务器负载评估公式中所占的权重值,对应上述处理消息量权重值。T表示当前系统时间;T1表示服务器上次有被分配给客户端的时间;WT表示时间参数在服务器负载评估公式中所占的权重值,对应上述时间参数权重值;LMR表示时间参数在服务器负载评估公式中被允许的最大值。Here, Abs represents the calculated absolute value; C represents the number of server connections; Min(C) represents the connection number with the smallest value among the connections of all servers in the current network; ΔC represents the tolerance value of the number of server connections. If the difference in the number of connections is less than this value, it can be considered that the number of connections on the server is balanced; WC indicates the weight of the number of connections in the server load evaluation formula, corresponding to the weight of the number of connections above. M represents the amount of messages processed by the server in the last statistical cycle; Min(M) represents the amount of messages processed with the least amount of messages among all servers in the last statistical cycle; ΔM represents the tolerance value of the amount of messages processed. If the message volume difference is less than this value, it can be considered that the messages processed by the server are balanced; WM indicates the weight value of the processed message volume in the server load evaluation formula, which corresponds to the above weight value of the processed message volume. T indicates the current system time; T1 indicates the last time the server was assigned to the client; WT indicates the weight value of the time parameter in the server load evaluation formula, corresponding to the weight value of the above time parameter; LMR indicates the time parameter in the server load evaluation The maximum value allowed in the formula.
需要说明的是,本申请实施例对公式(1)包括的上述参数的取值不作限定,可以根据实际场景进行设置。可以看出,当服务器的连接越多时,服务器的负载值越高;当服务器的处理消息量越多时,服务器的负载值越高;当服务器上次被分配给客户端的时间距离当前时间越近时,服务器的负载值越高。It should be noted that the embodiment of the present application does not limit the values of the above parameters included in the formula (1), and may be set according to actual scenarios. It can be seen that when the server has more connections, the server load value is higher; when the server processes more messages, the server load value is higher; when the server was assigned to the client last time, the closer to the current time , the higher the server load value.
可以看出,本申请实施例,基于当前网络中每个服务器上报的负载确定参数,可以准确地得到每个服务器的负载值。It can be seen that in this embodiment of the present application, based on the load determination parameters reported by each server in the current network, the load value of each server can be accurately obtained.
示例性地,在调度模块接收到多个客户端中每个客户端发送的连接请求后,可以根据每个客户端归属业务的重要程度或业务量情况,确定允许每个客户端连接服务器的数目,记作cn;这里,当某一客户端归属业务的重要程度或业务量较高时,可以允许该客户端连接较多数目的服务器;当某一客户端归属业务的重要程度或业务量较低时,可以允许该客户端接入较少数目的服务器。Exemplarily, after the scheduling module receives the connection request sent by each of the multiple clients, it can determine the number of servers that each client is allowed to connect to according to the importance of each client's business or the business volume , denoted as cn; here, when the importance of a certain client’s business or business volume is high, the client can be allowed to connect to a larger number of servers; when the importance of a certain client’s business or business volume is low , the client can be allowed to access a smaller number of servers.
本申请实施例中,调度模块在接收到多个客户端中每个客户端发送的连接请求之前,便可根据公式(1)得到上一统计周期内每个服务器的负载值;示例性地,根据每个服务器的负载值,确定每个客户端的服务器清单的实现方式,可以为:调度模块根据每个服务器的负载值,从中选择负载值较低的cn个服务器作为每个客户端的服务器清单;这里,每个客户端的服务器清单中包括至少两个服务器,这样在客户端与其中一个服务器的连接出现异常时,仍能保证服务的高可用。In the embodiment of the present application, before the scheduling module receives the connection request sent by each of the multiple clients, it can obtain the load value of each server in the last statistical period according to the formula (1); for example, According to the load value of each server, the implementation manner of determining the server list of each client may be: the scheduling module selects cn servers with lower load values as the server list of each client according to the load value of each server; Here, the server list of each client includes at least two servers, so that when the connection between the client and one of the servers is abnormal, the high availability of the service can still be guaranteed.
示例性地,服务器清单可以包括多个服务器,但并不包括当前网络中所有的服务器,这样,可以有效避免因为连接所有服务器导致的每个服务器的连接数过高的问题。Exemplarily, the server list may include multiple servers, but not all servers in the current network. In this way, the problem of too high connection number of each server caused by connecting all servers can be effectively avoided.
示例性地,在调度模块得到每个客户端的服务器清单后,向每个客户端下发对应的服务器清单;这样,每个客户端便可与对应服务器清单中的每个服务器建立TCP长连接。Exemplarily, after the scheduling module obtains the server list of each client, it sends the corresponding server list to each client; in this way, each client can establish a TCP long connection with each server in the corresponding server list.
步骤201:在确定每个客户端与对应的服务器清单中每个服务器建立TCP长连接后,重新获取当前网络中每个服务器的负载值;根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器。Step 201: After determining that each client establishes a TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server, determine that the Set the target server for load balancing conditions.
示例性地,在确定每个客户端与对应的服务器清单中每个服务器建立TCP长连接后,每个客户端会轮询的向已建立TCP长连接的每个服务器发送业务数据;下面以一个客户端、两个服务器为例进行说明。Exemplarily, after determining that each client establishes a TCP long connection with each server in the corresponding server list, each client will poll and send business data to each server that has established a TCP long connection; the following uses a The client and two servers are taken as an example for description.
示例性地,当客户端1轮询的向已建立TCP长连接的服务器1和服务器2发送业务数据时,一旦服务器1接收到该客户端发送的业务数据,便会统计最近一个统计周期的负载确定参数,该负载确定参数包括此服务器连接会话对应的处理消息量、此服务器对应的处理消息量、此服务器的连接数以及此服务器被分配给客户端1的时间;然后在定时时间到来时,服务器1将上述负载确定数据上报给调度模块;这样,调度模块便可根据公式(1)重新获取到服务器1的负载值;这里,服务器2负载值的获取过程与上述获取过程类似,此处不再赘述。如此,调度模块可以重新获取当前网络中每个服务器的负载值。For example, when client 1 polls to send business data to server 1 and server 2 that have established a TCP long connection, once server 1 receives the business data sent by the client, it will count the load of the latest statistical period Determine the parameters, the load determination parameters include the amount of processing messages corresponding to the server connection session, the amount of processing messages corresponding to this server, the number of connections to this server, and the time when this server is assigned to client 1; then when the timing time arrives, Server 1 reports the above-mentioned load determination data to the scheduling module; in this way, the scheduling module can reacquire the load value of server 1 according to the formula (1); here, the acquisition process of server 2 load value is similar to the above-mentioned acquisition process, which is not mentioned here. Let me repeat. In this way, the scheduling module can reacquire the load value of each server in the current network.
可以看出,在客户端与对应服务器清单中每个服务器的数据传输过程中,每个服务器的负载值是动态变化的;每个服务器会定时上报最近一个统计周期的负载确定参数;这样,调度模块便可重新确定当前各个服务器的负载值。而这种动态获取负载确定参数实现负载均衡的方式,能够有效避免因某个服务器处理能力低下,而影响整个服务器集群的处理能力。It can be seen that during the data transmission process between the client and each server in the corresponding server list, the load value of each server changes dynamically; each server will regularly report the load determination parameters of the latest statistical cycle; thus, the scheduling The module can re-determine the current load value of each server. And this method of dynamically obtaining load determination parameters to realize load balancing can effectively avoid the processing capacity of the entire server cluster being affected due to the low processing capacity of a certain server.
在一些实施例中,根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器,可以包括:对重新获取的每个服务器的负载值进行排序,得到排序结果;根据排序结果,确定不满足设定负载均衡条件的目标服务器。In some embodiments, according to the load value of each server obtained again, determining the target server that does not meet the set load balancing condition may include: sorting the load value of each server obtained again to obtain the sorting result; Sort the results to determine the target servers that do not meet the set load balancing conditions.
示例性地,对于重新获取的每个服务器的负载值,可以按照负载值从高到低的顺序进行排序,得到排序结果;进而,根据该排序结果,确定不满足设定负载均衡条件的目标服务器。Exemplarily, for the reacquired load value of each server, it can be sorted according to the order of the load value from high to low to obtain the sorting result; then, according to the sorting result, determine the target server that does not meet the set load balancing condition .
可以看出,本申请实施例,在获取到每个服务器的负载值后,通过对每个服务器的负载值进行排序,可以更加直观地从排序结果中确定出不满足设定负载均衡条件的目标服务器。It can be seen that in the embodiment of the present application, after obtaining the load value of each server, by sorting the load value of each server, it is possible to more intuitively determine the target that does not meet the set load balancing conditions from the sorting results. server.
示例性地,对于根据排序结果,确定不满足设定负载均衡条件的目标服务器的一种实现方式,可以为:从排序结果中,得到负载值最高的服务器与负载值最低的服务器;在确定负载值最高的服务器与负载值最低的服务器的负载差值大于第二设定阈值时,将负载值最高的服务器确定为不满足设定负载均衡条件的目标服务器。Exemplarily, an implementation manner of determining a target server that does not meet the set load balancing condition according to the sorting result may be: from the sorting result, obtain the server with the highest load value and the server with the lowest load value; When the load difference between the server with the highest load value and the server with the lowest load value is greater than the second set threshold, the server with the highest load value is determined as the target server that does not satisfy the set load balancing condition.
示例性地,从排序结果中得到负载值最高的服务器与负载值最低的服务器后,首先计算负载值最高的服务器与负载值最低的服务器的负载差值;再将该负载差值与第二设定阈值进行比较,得到比较结果;如果根据比较结果确定该负载差值大于第二设定阈值,则说明存在不满足设定负载均衡条件的目标服务器,并将负载值最高的服务器确定为不满足设定负载均衡条件的目标服务器;反之,如果根据比较结果确定该负载差值小于或等于第二设定阈值,则说明此时不存在不满足设定负载均衡条件的目标服务器,即,当前建立TCP长连接的所有服务器均满足负载均衡条件。Exemplarily, after obtaining the server with the highest load value and the server with the lowest load value from the sorting results, first calculate the load difference between the server with the highest load value and the server with the lowest load value; If it is determined according to the comparison result that the load difference is greater than the second set threshold, it means that there are target servers that do not meet the set load balancing conditions, and the server with the highest load value is determined to be unsatisfied. Set the target server for load balancing conditions; on the contrary, if it is determined according to the comparison result that the load difference is less than or equal to the second set threshold, it means that there is no target server that does not meet the set load balancing conditions at this time, that is, the currently established All servers with TCP persistent connections meet the load balancing conditions.
示例性地,对于根据排序结果,确定不满足设定负载均衡条件的目标服务器的另一种实现方式,可以为:将排序结果中负载值大于第三设定阈值的任一服务器确定为不满足设定负载均衡条件的目标服务器。Exemplarily, another implementation manner of determining a target server that does not meet the set load balancing condition according to the sorting result may be: determining any server whose load value is greater than the third set threshold in the sorting result as not meeting Set the target server for load balancing conditions.
示例性地,假设排序结果中大于第三设定阈值的服务器包括服务器1和服务器2,且它们之间的负载值关系为服务器1>服务器2,则可以将服务器1确定为不满足设定负载均衡条件的目标服务器,也可以将服务器2确定为不满足设定负载均衡条件的目标服务器。Exemplarily, assuming that servers greater than the third set threshold in the sorting result include server 1 and server 2, and the load value relationship between them is server 1>server 2, then server 1 can be determined as not meeting the set load The target server of the load balancing condition may also determine the server 2 as the target server that does not meet the set load balancing condition.
示例性地,如果排序结果中负载值均小于或等于第三设定阈值,则说明此时不存在不满足设定负载均衡条件的目标服务器,即,当前建立TCP长连接的所有服务器均满足负载均衡条件。Exemplarily, if the load values in the sorting results are all less than or equal to the third set threshold, it means that there is no target server that does not meet the set load balancing conditions at this time, that is, all servers currently establishing TCP long connections meet the load Equilibrium conditions.
这里,对于上述第二设定阈值和第三设定阈值的取值可以根据实际情况进行确定,本申请实施例对此不作限定。Here, the values of the second set threshold and the third set threshold may be determined according to actual conditions, which is not limited in this embodiment of the present application.
可以看出,本申请实施例,通过将负载值最高或大于某一设定阈值的服务器确定为目标服务器,以进行后续的负载均衡调整,可以避免因为该目标服务器处理能力低下,而影响整个服务器集群的处理能力。It can be seen that in this embodiment of the present application, by determining the server with the highest load value or greater than a certain threshold as the target server for subsequent load balancing adjustments, it is possible to avoid affecting the entire server due to the low processing capacity of the target server The processing power of the cluster.
步骤202:查找与目标服务器连接的目标客户端,调整目标客户端的服务器清单;目标客户端为多个客户端中的一个客户端。Step 202: Search for a target client connected to the target server, and adjust the server list of the target client; the target client is one of the multiple clients.
本申请实施例中,在根据上述步骤201得到不满足设定负载均衡条件的目标服务器后,获取与该目标服务器建立TCP长连接的所有客户端,并从这些客户端中查找需要调整服务器清单的目标客户端;这里,调整服务器清单表示负载均衡调整。In the embodiment of this application, after the target server that does not meet the set load balancing conditions is obtained according to the above step 201, all clients that have established TCP long connections with the target server are obtained, and the server list that needs to be adjusted is searched from these clients. The target client; here, adjusting the server list represents a load balancing adjustment.
在一些实施例中,查找与目标服务器连接的目标客户端,可以包括:获取与目标服务器建立TCP长连接的至少两个客户端;根据至少两个客户端中每个客户端向目标服务器发送的消息量,从至少两个客户端中,确定目标客户端。In some embodiments, searching for a target client connected to the target server may include: acquiring at least two clients that establish a TCP long connection with the target server; The message volume, from at least two clients, determines the target client.
示例性地,由于目标服务器在处理不同客户端发送的消息量(业务数据)时,会向调度模块定时上报最近一个统计周期,该目标服务器所有连接各自对应的处理消息量;即,与目标服务器建立TCP连接的每个客户端发送的消息量。进而,调度模块可以根据每个客户端向目标服务器发送的消息量,从与目标服务器建立TCP连接的多个客户端中,确定目标客户端。Exemplarily, since the target server will regularly report the latest statistical period to the scheduling module when processing the message volume (business data) sent by different clients, the respective processing message volumes of all connections of the target server; The amount of messages sent by each client establishing a TCP connection. Furthermore, the scheduling module may determine the target client from multiple clients establishing TCP connections with the target server according to the amount of messages sent by each client to the target server.
可以理解地,由于目标服务器是当前网络中不满足设定负载均衡条件的服务器,因而,需要对目标服务器的负载值进行调整使其达到均衡状态;而目标服务器的负载值是由其连接的每个客户端发送的消息量确定的,因而,基于每个客户端向目标服务器发送的消息量,可以有针对性地确定目标客户端。Understandably, since the target server is a server that does not meet the set load balancing conditions in the current network, it is necessary to adjust the load value of the target server to achieve a balanced state; The amount of messages sent by each client is determined. Therefore, based on the amount of messages sent by each client to the target server, the target client can be determined in a targeted manner.
在一些实施例中,根据至少两个客户端中每个客户端向目标服务器发送的消息量,从至少两个客户端中,确定目标客户端,可以包括:根据至少两个客户端中每个客户端向目标服务器发送的消息量,从至少两个客户端中,将发送消息量最小的客户端确定为目标客户端,或者,将发送消息量小于或等于第一设定阈值的任一客户端确定为目标客户端。In some embodiments, determining the target client from the at least two clients according to the amount of messages sent from each of the at least two clients to the target server may include: according to each of the at least two clients The amount of messages sent by the client to the target server. From at least two clients, the client with the smallest amount of messages sent is determined as the target client, or any client whose amount of messages sent is less than or equal to the first set threshold determined as the target client.
可以看出,本申请实施例,从与目标服务器连接的每个客户端中,选择发送消息量最小或小于某一设定阈值的客户端作为目标客户端,可以有效防止后续对目标服务器进行负载调整时的抖动问题,确保系统的稳定性。It can be seen that in the embodiment of the present application, from each client connected to the target server, the client that sends the smallest amount of messages or less than a certain threshold is selected as the target client, which can effectively prevent the subsequent load on the target server The jitter problem during adjustment ensures the stability of the system.
示例性地,确定目标客户端的实现方式,还可以为:从与目标服务器建立连接会话的所有客户端中,找出连接会话负载最小的客户端,并将该客户端确定为目标客户端;这里,与目标服务器建立连接会话的每个客户端的连接会话负载Las可以通过公式(2)进行确定。Exemplarily, the implementation manner of determining the target client may also be: from all clients establishing connection sessions with the target server, find out the client with the smallest connection session load, and determine the client as the target client; here , the connection session load Las of each client that establishes a connection session with the target server can be determined by formula (2).
Las=WAT/(t-t1)+MC      (2)Las=WAT/(t-t1)+MC (2)
这里,WAT表示指时间参数在Client连接会话负载评估公式中所占的权重值;t表示客户端连接目标服务器的时间;t1表示客户端上次会话调整的时间,即,客户端上次连接其它目标服务器的时间;MC表示最近一个统计周期,此连接会话需要处理的消息量,即,客户端向目标服务器发送的需要目标服务器处理的消息量。Here, WAT means the weight value of the time parameter in the client connection session load evaluation formula; t means the time when the client connects to the target server; t1 means the time of the client's last session adjustment, that is, the last time the client connected The time of the target server; MC indicates the amount of messages that need to be processed by this connection session in the latest statistical period, that is, the amount of messages sent by the client to the target server that needs to be processed by the target server.
需要说明的是,本申请实施例对公式(2)包括的上述参数的取值不作限定,可以根据实际场景进行设置。从公式(2)可以看出,如果目标服务器处理的消息数越多,则对应客户端的连接会话负载越高,如果距离最近一次会话调整的时间越近,则对应客户端的连接会话负载越高。It should be noted that the embodiment of the present application does not limit the values of the above parameters included in the formula (2), and may be set according to actual scenarios. It can be seen from formula (2) that if the number of messages processed by the target server is more, the connection session load of the corresponding client is higher, and if the time from the latest session adjustment is closer, the connection session load of the corresponding client is higher.
示例性地,在根据公式(2)得到与目标服务器建立连接会话的每个客户端的连接会话负载后,将连接会话负载最小的客户端确定为目标客户端,或,将连接会话负载小于等于设定值的客户端确定为目标客户端。Exemplarily, after the connection session load of each client that establishes a connection session with the target server is obtained according to formula (2), the client with the smallest connection session load is determined as the target client, or the connection session load is less than or equal to the set The client with the given value is identified as the target client.
本申请实施例中,在根据上述步骤得到目标客户端后,获取目标客户端的服务器清单,对该服务器清单进行调整,实现服务器之间的负载均衡。In the embodiment of the present application, after the target client is obtained according to the above steps, the server list of the target client is obtained, and the server list is adjusted to realize load balancing among the servers.
在一些实施例中,调整目标客户端的服务器清单,可以包括:将目标客户端的服务器清单中负载值最高的服务器移除,并向目标客户端的服务器清单中新增一个当前负载值最低的服务器。In some embodiments, adjusting the server list of the target client may include: removing the server with the highest load value from the server list of the target client, and adding a server with the lowest load value to the server list of the target client.
示例性地,在得到目标客户端的服务器清单后,将该服务器清单中负载值最高的服务器移除,也就是说,将该服务器清单中的目标服务器移除,并新增一个当前负载值最低的服务器。Exemplarily, after obtaining the server list of the target client, the server with the highest load value in the server list is removed, that is, the target server in the server list is removed, and a new one with the lowest current load value is added. server.
这是因为目标服务器是当前网络中负载值较高的服务器,数据处理能力低下,如果不对其进行移除,而是继续处理目标客户端发送的业务数据,很可能发生因目标服务器过载而死机的情况,影响整个服务器集群的处理能力;本申请实施例中,通过将目标客户端与目标服务器的连接调整为目标客户端与当前负载值最低的服务器的连接,使得目标服务器不再处理目标客户端发送的业务数据,这样,可以有效解决目标服务器的过载问题,降低目标服务器因过载而死机的可能性;另外,由于目标客户端与目标服务器的连接会话负载最小,因而,这种调整方式还可以有效防止调整过程中的抖动问题,确保系统的稳定性。This is because the target server is a server with a high load value in the current network, and its data processing capability is low. If it is not removed, but continues to process the business data sent by the target client, it is very likely that the target server will crash due to overload. In this case, the processing capacity of the entire server cluster is affected; in the embodiment of this application, by adjusting the connection between the target client and the target server to the connection between the target client and the server with the lowest current load value, the target server no longer processes the target client In this way, the overload problem of the target server can be effectively solved, and the possibility of the target server crashing due to overload can be reduced; in addition, since the connection session load between the target client and the target server is minimal, this adjustment method can also Effectively prevent the vibration problem during the adjustment process and ensure the stability of the system.
可以看出,本申请实施例通过将目标客户端的服务器清单中负载值最高的服务器移除,可以降低因该服务器继续处理目标客户端的业务数据而出现过载的风险。It can be seen that in the embodiment of the present application, by removing the server with the highest load value from the server list of the target client, the risk of overload due to the server continuing to process the business data of the target client can be reduced.
在一些实施例中,上述方法还可以包括:在当前统计周期内,每完成一次服务器清单的调整,对调整次数执行加1操作;计算当前统计周期内调整服务器清单的总调整次数与当前网路中每个服务器的总连接数的比值,得到当前统计周期的调整会话占比;根据调整会话占比与第四设定阈值的大小关系,确定是否继续调整当前统计周期内的服务器清单。In some embodiments, the above method may further include: adding 1 to the number of adjustments each time the server list is adjusted within the current statistical period; calculating the total number of adjustments to the server list within the current statistical period According to the ratio of the total number of connections of each server, the adjusted session proportion of the current statistical period is obtained; according to the relationship between the adjusted session proportion and the fourth threshold value, it is determined whether to continue to adjust the server list in the current statistical period.
本申请实施例,通过当前统计周期的调整会话占比对当前统计周期的服务器清单的调整次数进行控制,可以防止因出现大面积的服务器连接调整而导致系统稳定性差的问题。In this embodiment of the present application, the number of adjustments to the server list in the current statistical period is controlled by adjusting the session ratio of the current statistical period, which can prevent the problem of poor system stability caused by large-scale server connection adjustments.
示例性地,每完成一次服务器清单的调整表示每完成一次负载均衡调整;这里,在当前统计周期内,每完成一次服务器清单的调整,对调整次数执行加1操作;示例性地,可以将当前统计周期内服务器清单的总调整次数记作AT,当前网路中每个服务器的总连接数记作CT,则当前统计周期的调整会话占比为AT/CT。接着,根据调整会话占比与第四设定阈值的大小关系,确定是否继续调整当前统计周期内的服务器清单。Exemplarily, every time the adjustment of the server list is completed means that every time the load balancing adjustment is completed; here, in the current statistical period, every time the adjustment of the server list is completed, the adjustment number is incremented by 1; Exemplarily, the current The total number of adjustments to the server list in the statistical period is recorded as AT, and the total number of connections to each server in the current network is recorded as CT, so the proportion of adjusted sessions in the current statistical period is AT/CT. Next, it is determined whether to continue to adjust the server list in the current statistical period according to the relationship between the adjusted session proportion and the fourth set threshold.
在一些实施例中,根据调整会话占比与第四设定阈值的大小关系,确定是否继续调整当前统计周期内的服务器清单,可以包括:在确定调整会话占比大于或等于第四设定阈值时,等待当前统计周期结束;在确定调整会话占比小于第四设定阈值、且确定存在不满足设定负载均衡条件的目标服务器时,继续调整当前统计周期内的服务器清单。In some embodiments, according to the size relationship between the adjusted session ratio and the fourth set threshold, determining whether to continue adjusting the server list in the current statistical period may include: determining that the adjusted session ratio is greater than or equal to the fourth set threshold , wait for the end of the current statistical period; when it is determined that the proportion of adjusted sessions is less than the fourth set threshold and it is determined that there are target servers that do not meet the set load balancing conditions, continue to adjust the server list in the current statistical period.
示例性地,在确定调整会话占比AT/CT的值大于或等于第四设定阈值时,等待当前统计周期结束;即,在此消息统计周期不再进行负载均衡调整,防止系统出现大面积连接抖动。反之,在确定调整会话占比AT/CT的值小于第四设定阈值时,则再一次评估当前网络中各个服务器之间的负载是否均衡,即,确定是否存在不满足设定负载均衡条件的目标服务器如果不均衡,如果是,则继续下一轮调整,直到整个系统再次达到负载均衡;反之,则说明当前统计周期已达到负载均衡。这里,对第四设定阈值的取 值不作限定,可以根据实际场景进行设置。Exemplarily, when it is determined that the value of the adjusted session ratio AT/CT is greater than or equal to the fourth set threshold, wait for the end of the current statistical period; that is, no load balancing adjustment is performed in this message statistical period to prevent the system from appearing in a large area. Connection flapping. Conversely, when it is determined that the value of the adjusted session ratio AT/CT is less than the fourth set threshold, then evaluate again whether the load among the servers in the current network is balanced, that is, determine whether there is a server that does not meet the set load balancing conditions. If the target server is unbalanced, if it is, continue to the next round of adjustment until the entire system achieves load balance again; otherwise, it means that the current statistical cycle has achieved load balance. Here, the value of the fourth set threshold is not limited, and can be set according to the actual scene.
可以看出,本申请实施例,通过调整会话占比与第四设定阈值的大小关系,对当前统计周期的服务器清单的调整次数进行控制,实现在当前统计周期负载均衡的同时还可以确保系统的稳定性。It can be seen that in the embodiment of the present application, by adjusting the relationship between the session ratio and the fourth threshold, the number of adjustments to the server list in the current statistical cycle is controlled, so as to achieve load balancing in the current statistical cycle and ensure that the system stability.
本申请实施例提出了一种负载均衡方法、装置、电子设备、计算机存储介质和计算机程序产品,该方法包括:接收到多个客户端中每个客户端发送的连接请求后,获取当前网络中每个服务器的负载值;根据每个服务器的负载值,确定每个客户端的服务器清单,向每个客户端下发对应的服务器清单;服务器清单中包括至少两个服务器;在确定每个客户端与对应的服务器清单中每个服务器建立TCP长连接后,重新获取当前网络中每个服务器的负载值;根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器;查找与目标服务器连接的目标客户端,调整目标客户端的服务器清单;目标客户端为多个客户端中的一个客户端。可以看出,本申请实施例中,在客户端与服务器建立连接之前,通过获取当前网络中每个服务器的负载值,可以确定允许每个客户端连接的服务器清单;即,可以将客户端连接到多个负载值较低的服务器上,使得该客户端的业务量更加均衡的发送到不同的服务器上进行处理。进一步地,在客户端与服务器建立连接之后,如果发现不满足设定负载均衡条件的目标服务器,则调整与该目标服务器连接的目标客户端的服务器清单,达到控制整个服务器集群的综合负载的目的,保持每个服务器负载值的动态均衡,有效解决服务器过载的问题。The embodiment of the present application proposes a load balancing method, device, electronic equipment, computer storage medium and computer program product. The method includes: after receiving a connection request sent by each client among multiple clients, obtaining The load value of each server; according to the load value of each server, determine the server list of each client, and send the corresponding server list to each client; the server list includes at least two servers; after determining each client After establishing a TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server, determine the target server that does not meet the set load balancing conditions; Find the target client connected to the target server, and adjust the server list of the target client; the target client is one of the multiple clients. It can be seen that in the embodiment of the present application, before the client establishes a connection with the server, by obtaining the load value of each server in the current network, the list of servers that each client is allowed to connect can be determined; that is, the client can be connected to To multiple servers with lower load values, so that the client's business volume can be sent to different servers for processing in a more balanced manner. Further, after the client establishes a connection with the server, if it is found that the target server does not meet the set load balancing conditions, then adjust the server list of the target client connected to the target server to achieve the purpose of controlling the overall load of the entire server cluster, Maintain the dynamic balance of the load value of each server to effectively solve the problem of server overload.
为了能够更加体现本申请的目的,在本申请上述实施例的基础上,进行进一步的说明。In order to better reflect the purpose of the present application, further description will be made on the basis of the above-mentioned embodiments of the present application.
图2c为本申请实施例的另一种负载均衡方法的流程示意图,如图2c所示,该流程可以包括:Fig. 2c is a schematic flow diagram of another load balancing method according to the embodiment of the present application. As shown in Fig. 2c, the flow may include:
步骤A1:服务器上报负载确定参数。Step A1: The server reports load determination parameters.
示例性地,服务器1至服务器n分别向调度模块上报最近一个统计周期内的负载确定参数;该负载确定参数可以包括服务器的连接数、服务器在上一统计周期的处理消息量、服务器上次被分配给客户端的时间以及服务器的每个连接会话对应的处理消息量。Exemplarily, server 1 to server n respectively report to the scheduling module the load determination parameters in the latest statistical period; the load determination parameters may include the number of server connections, the amount of messages processed by the server in the last statistical period, the last time the server was The time allotted to the client and the amount of messages processed for each connection session of the server.
步骤A2:客户端向调度模块发送连接请求。Step A2: The client sends a connection request to the scheduling module.
示例性地,当客户端需要向服务器发送业务数据之前,需要先向调度模块发送连接请求。Exemplarily, before the client needs to send service data to the server, it needs to send a connection request to the scheduling module.
步骤A3:调度模块向客户端分配服务器清单。Step A3: The scheduling module distributes the server list to the client.
示例性地,调度模块根据每个服务器上报负载确定参数,确定每个服务器的负载值,进而,根据每个服务器的负载值以及客户端归属业务的重要程度或业务量情况,向客户端分配对应的服务器清单,并向客户端下发对应的服务器清单。Exemplarily, the scheduling module determines the load value of each server according to the load determination parameters reported by each server, and then assigns corresponding server list, and send the corresponding server list to the client.
步骤A4:客户端同时与服务器清单中每个服务器建立连接。Step A4: The client establishes a connection with each server in the server list at the same time.
示例性地,客户端的服务器清单中包括服务器1和服务器2,即,客户端同时与服务器1和服务器2建立TCP长连接。Exemplarily, the server list of the client includes the server 1 and the server 2, that is, the client establishes a TCP long connection with the server 1 and the server 2 at the same time.
步骤A5:客户端轮询发送业务数据。Step A5: The client polls to send business data.
示例性地,在确定客户端与服务器1和服务器2建立TCP长连接后,客户端会轮询的向已建立TCP长连接的服务器1和服务器2发送业务数据。Exemplarily, after determining that the client establishes the TCP long connection with the server 1 and the server 2, the client sends service data to the server 1 and the server 2 that have established the TCP long connection in a polling manner.
需要说明的是,当任一服务器接收到客户端发送的业务数据后,会统计最近一个统计周期的负载确定参数,并将上述负载确定数据定时上报给调度模块;这样,调度模块可基于负载确定数据,重新获取当前网络中每个服务器的负载值;并根据重新获取的负载值,确定服务器与客户端连接的服务器是否满足负载均衡条件,如果不满足,则调整客户端的服务器清单,使得与客户端连接的每个服务器均处于均衡状态。It should be noted that when any server receives the business data sent by the client, it will count the load determination parameters of the latest statistical period, and report the above load determination data to the scheduling module at regular intervals; in this way, the scheduling module can determine the load based on the load. Data, reacquire the load value of each server in the current network; and according to the reacquired load value, determine whether the server connected to the client meets the load balancing conditions, if not, adjust the server list of the client, so that the server with the client Each server connected to the end is in a balanced state.
示例性地,考虑到大型系统中客户端和服务器的数量较多,当服务器接收到客户端发送的业务数据时,均需要服务器自身统计每个统计周期的负载确定参数;即,服务器既要处理客户端发送的业务数据,还需要统计负载确定参数,可见,服务器在负载均衡过程中承担的任务会比较重;为了提高服务器的处理能力,可以在图2b的基础上,新增一个监控模块;图2d是本申请实施例中的另一种负载均衡调整的结构示意图,如图2d所示,将新增的监控模块连接在调度模块与每个服务器之间,这样,通过监控模块实现对每个服务器的负载确定参数的统计和监控,并将统计得到的每个服务器的负载确定参数上报给调度模块;再通过调度模块控制与客户端连接的服务器清单;即,通过监控模块完成服务器的部分任务,可以提高整个服务器集群的处理能力。For example, considering the large number of clients and servers in a large-scale system, when the server receives the business data sent by the client, the server needs to count the load determination parameters of each statistical period; that is, the server must process The business data sent by the client also needs to be counted to determine the parameters of the load. It can be seen that the server will undertake relatively heavy tasks in the load balancing process; in order to improve the processing capacity of the server, a monitoring module can be added on the basis of Figure 2b; Figure 2d is a schematic structural diagram of another load balancing adjustment in the embodiment of the present application. As shown in Figure 2d, the newly added monitoring module is connected between the scheduling module and each server, so that each The statistics and monitoring of the load determination parameters of each server, and report the load determination parameters of each server obtained from the statistics to the scheduling module; then control the list of servers connected to the client through the scheduling module; that is, complete the server part through the monitoring module tasks, which can improve the processing capacity of the entire server cluster.
本申请实施例中,通过控制客户端允许连接的服务器的数量,可以将业务量大的消息量更加均衡的发送到服务器上,可以降低发生因某类业务推广,导致业务量爆增,造成服务器死机的情况。另外,在客户端同时连接多个服务器后,针对某个服务器的变更,如下线、升级、重启,或是客户端到某个服务器的网络出现异常时,也不影响客户端的数据正常上报,提高了系统可靠性。In the embodiment of this application, by controlling the number of servers that the client is allowed to connect, messages with a large amount of business can be sent to the server in a more balanced manner, which can reduce the occurrence of an explosion in business volume caused by certain types of business promotion, causing server Crash situation. In addition, after the client connects to multiple servers at the same time, changes to a certain server, such as going offline, upgrading, restarting, or when the network between the client and a certain server is abnormal, will not affect the normal reporting of data from the client, improving system reliability.
图3是本申请实施例的负载均衡装置的组成结构示意图,如图3所示,该装置包括第一确定模块300、第二确定模块301和调整模块302,其中,Fig. 3 is a schematic diagram of the composition and structure of a load balancing device according to an embodiment of the present application. As shown in Fig. 3 , the device includes a first determination module 300, a second determination module 301 and an adjustment module 302, wherein,
第一确定模块300,配置为接收到多个客户端中每个客户端发送的连接请求后,获取当前网络中每个服务器的负载值;根据所述每个服务器的负载值,确定所述每个客户端的服务器清单,向所述每个客户端下发对应的服务器清单;所述服务器清单中包括至少两个服务器;The first determination module 300 is configured to obtain the load value of each server in the current network after receiving the connection request sent by each client in the plurality of clients; determine the load value of each server according to the load value of each server A server list of a client, and a corresponding server list is issued to each client; the server list includes at least two servers;
第二确定模块301,配置为在确定所述每个客户端与对应的服务器清单中每个服务器建立传输控制协议TCP长连接后,重新获取所述当前网络中每个服务器的负载值;根据重新获取的每个服务器的负载值,确定不满足 设定负载均衡条件的目标服务器;The second determination module 301 is configured to reacquire the load value of each server in the current network after determining that each client establishes a transmission control protocol TCP long connection with each server in the corresponding server list; Get the load value of each server to determine the target server that does not meet the set load balancing conditions;
调整模块302,配置为查找与所述目标服务器连接的目标客户端,调整所述目标客户端的服务器清单;所述目标客户端为所述多个客户端中的一个客户端。The adjustment module 302 is configured to search for a target client connected to the target server, and adjust the server list of the target client; the target client is one of the multiple clients.
在一些实施例中,所述调整模块302,配置为查找与所述目标服务器连接的目标客户端,包括:In some embodiments, the adjustment module 302 is configured to find the target client connected to the target server, including:
获取与所述目标服务器建立TCP长连接的至少两个客户端;Obtain at least two clients establishing TCP long connections with the target server;
根据所述至少两个客户端中每个客户端向所述目标服务器发送的消息量,从所述至少两个客户端中,将发送消息量最小的客户端确定为所述目标客户端,或者,将发送消息量小于或等于第一设定阈值的任一客户端确定为所述目标客户端。According to the amount of messages sent by each of the at least two clients to the target server, from among the at least two clients, determine the client that sends the smallest amount of messages as the target client, or , determining any client whose message volume is less than or equal to the first set threshold as the target client.
在一些实施例中,所述第二确定模块301,配置为根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器,包括:In some embodiments, the second determination module 301 is configured to determine the target server that does not meet the set load balancing condition according to the re-acquired load value of each server, including:
对所述重新获取的每个服务器的负载值进行排序,得到排序结果;Sorting the load values of each server obtained again to obtain a sorting result;
从所述排序结果中,得到负载值最高的服务器与负载值最低的服务器;在确定所述负载值最高的服务器与所述负载值最低的服务器的负载差值大于第二设定阈值时,将所述负载值最高的服务器确定为不满足所述设定负载均衡条件的目标服务器;或者,From the sorting results, the server with the highest load value and the server with the lowest load value are obtained; when it is determined that the load difference between the server with the highest load value and the server with the lowest load value is greater than a second set threshold, The server with the highest load value is determined as the target server that does not meet the set load balancing condition; or,
将所述排序结果中负载值大于第三设定阈值的任一服务器确定为不满足所述设定负载均衡条件的目标服务器。Determining any server with a load value greater than a third set threshold in the sorting result as a target server that does not satisfy the set load balancing condition.
在一些实施例中,所述调整模块302,配置为调整所述目标客户端的服务器清单,包括:In some embodiments, the adjustment module 302 is configured to adjust the server list of the target client, including:
将所述目标客户端的服务器清单中负载值最高的服务器移除,并向所述目标客户端的服务器清单中新增一个当前负载值最低的服务器。The server with the highest load value in the server list of the target client is removed, and a server with the lowest current load value is added to the server list of the target client.
在一些实施例中,所述装置还包括接收模块,所述接收模块,配置为:In some embodiments, the device further includes a receiving module configured to:
在接收所述多个客户端中每个客户端发送的连接请求之前,接收所述当前网络中每个服务器上报的负载确定参数;所述负载确定参数包括服务器的连接数、服务器在上一统计周期的处理消息量以及服务器上次被分配给客户端的时间中的至少一项;Before receiving the connection request sent by each client in the multiple clients, receive the load determination parameters reported by each server in the current network; the load determination parameters include the number of connections of the server, the server's last statistics At least one of the periodic processing message volume and the last time the server was assigned to the client;
所述第一确定模块300,配置为获取当前网络中每个服务器的负载值,包括:The first determining module 300 is configured to obtain the load value of each server in the current network, including:
根据所述当前网络中每个服务器上报的负载确定参数,确定当前网络中每个服务器的负载值。The load value of each server in the current network is determined according to the load determination parameters reported by each server in the current network.
在一些实施例中,在所述负载确定参数包括服务器的连接数、服务器在上一统计周期的处理消息量以及服务器上次被分配给客户端的时间的情况下,所述负载确定参数还包括连接数权重值、处理消息量权重值、以及时间参数权重值;In some embodiments, when the load determination parameters include the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the time when the server was allocated to the client last time, the load determination parameters further include connection The weight value of the number, the weight value of the processing message volume, and the weight value of the time parameter;
所述第一确定模块300,配置为根据所述当前网络中每个服务器上报的 负载确定参数,确定当前网络中每个服务器的负载值,包括:The first determination module 300 is configured to determine the load value of each server in the current network according to the load determination parameters reported by each server in the current network, including:
根据所述当前网络中每个服务器上报的服务器的连接数与所述连接数权重值、服务器在上一统计周期的处理消息量与处理消息量权重值、服务器上次被分配给客户端的时间与时间参数权重值,确定当前网络中每个服务器的负载值。According to the number of server connections reported by each server in the current network and the weight value of the number of connections, the amount of messages processed by the server in the last statistical period and the weight value of the amount of messages processed, the time when the server was assigned to the client last time and The time parameter weight value determines the load value of each server in the current network.
在一些实施例中,所述调整模块302,还配置为:In some embodiments, the adjustment module 302 is further configured to:
在当前统计周期内,每完成一次服务器清单的调整,对调整次数执行加1操作;In the current statistical period, every time the adjustment of the server list is completed, the number of adjustments will be increased by 1;
计算所述当前统计周期内调整所述服务器清单的总调整次数与所述当前网路中每个服务器的总连接数的比值,得到所述当前统计周期的调整会话占比;Calculating the ratio of the total number of times of adjusting the server list in the current statistical period to the total number of connections of each server in the current network to obtain the proportion of adjusted sessions in the current statistical period;
根据所述调整会话占比与第四设定阈值的大小关系,确定是否继续调整所述当前统计周期内的服务器清单。Whether to continue to adjust the server list in the current statistical period is determined according to the relationship between the adjusted session ratio and the fourth set threshold.
在一些实施例中,所述调整模块302,配置为根据所述调整会话占比与第四设定阈值的大小关系,确定是否继续调整所述当前统计周期内的服务器清单,包括:In some embodiments, the adjustment module 302 is configured to determine whether to continue adjusting the server list in the current statistical period according to the relationship between the adjustment session ratio and the fourth set threshold, including:
在确定所述调整会话占比大于或等于所述第四设定阈值时,等待所述当前统计周期结束;When it is determined that the adjusted session proportion is greater than or equal to the fourth set threshold, waiting for the end of the current statistics period;
在确定所述调整会话占比小于所述第四设定阈值、且确定存在不满足设定负载均衡条件的目标服务器时,继续调整所述当前统计周期内的服务器清单。When it is determined that the adjusted session proportion is less than the fourth set threshold and it is determined that there is a target server that does not meet the set load balancing condition, continue to adjust the server list in the current statistical period.
在实际应用中,上述第一确定模块300、第二确定模块301、调整模块302和接收模块均可以由位于电子设备中的处理器实现,该处理器可以为ASIC、DSP、DSPD、PLD、FPGA、CPU、控制器、微控制器、微处理器中的至少一种。In practical applications, the above-mentioned first determination module 300, second determination module 301, adjustment module 302 and receiving module can all be realized by a processor located in an electronic device, and the processor can be ASIC, DSP, DSPD, PLD, FPGA , CPU, controller, microcontroller, microprocessor at least one.
另外,在本实施例中的各功能模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。In addition, each functional module in this embodiment may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software function modules.
集成的单元如果以软件功能模块的形式实现并非作为独立的产品进行销售或使用时,可以存储在一个计算机可读取存储介质中,基于这样的理解,本实施例的技术方案本质上或者说对相关技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机、服务器、或者网络设备等)或processor(处理器)执行本实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read Only Memory,ROM)、RAM、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment is essentially or The contribution made by related technologies or all or part of the technical solution can be embodied in the form of software products, the computer software products are stored in a storage medium, and include several instructions to make a computer device (which can be a personal computer) , server, or network device, etc.) or a processor (processor) executes all or part of the steps of the method in this embodiment. The aforementioned storage medium includes: various media that can store program codes such as U disk, mobile hard disk, read-only memory (Read Only Memory, ROM), RAM, magnetic disk or optical disk.
具体来讲,本实施例中的一种负载均衡方法对应的计算机程序指令可以被存储在光盘、硬盘、U盘等存储介质上,当存储介质中的与一种负载均衡方法对应的计算机程序指令被一电子设备读取或被执行时,实现前述实施例的任意一种负载均衡方法。Specifically, the computer program instructions corresponding to a load balancing method in this embodiment can be stored on a storage medium such as an optical disk, a hard disk, or a USB flash drive. When the computer program instructions corresponding to a load balancing method in the storage medium When read or executed by an electronic device, any one of the load balancing methods in the foregoing embodiments is implemented.
基于前述实施例相同的技术构思,参见图4,其示出了本申请实施例提供的电子设备400,可以包括:存储器401和处理器402;其中,Based on the same technical concept as the foregoing embodiments, see FIG. 4 , which shows an electronic device 400 provided by an embodiment of the present application, which may include: a memory 401 and a processor 402; wherein,
存储器401,配置为存储计算机程序和数据; memory 401 configured to store computer programs and data;
处理器402,配置为执行存储器中存储的计算机程序,以实现前述实施例的任意一种负载均衡方法。The processor 402 is configured to execute a computer program stored in a memory, so as to implement any one of the load balancing methods in the foregoing embodiments.
在实际应用中,上述存储器401可以是易失性存储器(volatile memory),例如RAM;或者非易失性存储器(non-volatile memory),例如ROM、快闪存储器(flash memory)、硬盘(Hard Disk Drive,HDD)或固态硬盘(Solid-State Drive,SSD);或者上述种类的存储器的组合,并向处理器402提供指令和数据。In practical applications, the above-mentioned memory 401 can be a volatile memory (volatile memory), such as RAM; or a non-volatile memory (non-volatile memory), such as ROM, flash memory (flash memory), hard disk (Hard Disk Drive, HDD) or solid-state drive (Solid-State Drive, SSD); or a combination of the above-mentioned types of memory, and provide instructions and data to the processor 402.
上述处理器402可以为ASIC、DSP、DSPD、PLD、FPGA、CPU、控制器、微控制器、微处理器中的至少一种。可以理解地,对于不同的负载均衡设备,用于实现上述处理器功能的电子器件还可以为其它,本申请实施例不作具体限定。The aforementioned processor 402 may be at least one of ASIC, DSP, DSPD, PLD, FPGA, CPU, controller, microcontroller, and microprocessor. It can be understood that, for different load balancing devices, the electronic device used to implement the above processor function may also be other, which is not specifically limited in this embodiment of the present application.
本申请实施例还提供一种计算机程序产品,该计算机程序产品承载有程序代码,所述程序代码包括的指令可用于执行上述方法实施例中所述的负载均衡方法,具体可参见上述方法实施例,在此不再赘述。The embodiment of the present application also provides a computer program product, the computer program product carries a program code, and the instructions included in the program code can be used to execute the load balancing method described in the above method embodiment, for details, please refer to the above method embodiment , which will not be repeated here.
其中,上述计算机程序产品可以具体通过硬件、软件或其结合的方式实现。在一个可选实施例中,所述计算机程序产品具体体现为计算机存储介质,在另一个可选实施例中,计算机程序产品具体体现为软件产品,例如软件开发包(Software Development Kit,SDK)等等。Wherein, the above-mentioned computer program product may be specifically implemented by means of hardware, software or a combination thereof. In an optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (Software Development Kit, SDK) etc. wait.
在一些实施例中,本申请实施例提供的装置具有的功能或包含的模块可以用于执行上文方法实施例描述的方法,其具体实现可以参照上文方法实施例的描述,为了简洁,这里不再赘述。In some embodiments, the functions or modules included in the device provided by the embodiments of the present application can be used to execute the methods described in the above method embodiments, and its specific implementation can refer to the descriptions of the above method embodiments. For brevity, here No longer.
上文对各个实施例的描述倾向于强调各个实施例之间的不同之处,其相同或相似之处可以互相参考,为了简洁,本文不再赘述。The above descriptions of the various embodiments tend to emphasize the differences between the various embodiments, the same or similar points can be referred to each other, and for the sake of brevity, details are not repeated herein.
本申请所提供的各方法实施例中所揭露的方法,在不冲突的情况下可以任意组合,得到新的方法实施例。The methods disclosed in the various method embodiments provided in this application can be combined arbitrarily without conflict to obtain new method embodiments.
本申请所提供的各产品实施例中所揭露的特征,在不冲突的情况下可以任意组合,得到新的产品实施例。The features disclosed in the various product embodiments provided in this application can be combined arbitrarily without conflict to obtain new product embodiments.
本申请所提供的各方法或设备实施例中所揭露的特征,在不冲突的情况下可以任意组合,得到新的方法实施例或设备实施例。The features disclosed in each method or device embodiment provided in this application can be combined arbitrarily without conflict to obtain a new method embodiment or device embodiment.
本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用硬件实施例、软件实施例、或结 合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器和光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that the embodiments of the present application may be provided as methods, systems, or computer program products. Accordingly, the present application may take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) having computer-usable program code embodied therein.
本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present application is described with reference to flowcharts and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present application. It should be understood that each procedure and/or block in the flowchart and/or block diagram, and a combination of procedures and/or blocks in the flowchart and/or block diagram can be realized by computer program instructions. These computer program instructions may be provided to a general purpose computer, special purpose computer, embedded processor, or processor of other programmable data processing equipment to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing equipment produce a An apparatus for realizing the functions specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby The instructions provide steps for implementing the functions specified in the flow chart or blocks of the flowchart and/or the block or blocks of the block diagrams.
以上,仅为本申请的较佳实施例而已,并非用于限定本申请的保护范围。The above are only preferred embodiments of the present application, and are not intended to limit the protection scope of the present application.

Claims (12)

  1. 一种负载均衡方法,所述方法包括:A load balancing method, the method comprising:
    接收到多个客户端中每个客户端发送的连接请求后,获取当前网络中每个服务器的负载值;根据所述每个服务器的负载值,确定所述每个客户端的服务器清单,向所述每个客户端下发对应的服务器清单;所述服务器清单中包括至少两个服务器;After receiving the connection request sent by each client in the multiple clients, obtain the load value of each server in the current network; determine the server list of each client according to the load value of each server, and send to the Each client sends a corresponding server list; the server list includes at least two servers;
    在确定所述每个客户端与对应的服务器清单中每个服务器建立传输控制协议TCP长连接后,重新获取所述当前网络中每个服务器的负载值;根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器;After determining that each client establishes a transmission control protocol TCP long connection with each server in the corresponding server list, reacquire the load value of each server in the current network; according to the reacquired load value of each server , to determine the target server that does not meet the set load balancing conditions;
    查找与所述目标服务器连接的目标客户端,调整所述目标客户端的服务器清单;所述目标客户端为所述多个客户端中的一个客户端。Searching for a target client connected to the target server, and adjusting the server list of the target client; the target client is one of the multiple clients.
  2. 根据权利要求1所述的方法,其中,所述查找与所述目标服务器连接的目标客户端,包括:The method according to claim 1, wherein said searching for a target client connected to said target server comprises:
    获取与所述目标服务器建立TCP长连接的至少两个客户端;Obtain at least two clients establishing TCP long connections with the target server;
    根据所述至少两个客户端中每个客户端向所述目标服务器发送的消息量,从所述至少两个客户端中,将发送消息量最小的客户端确定为所述目标客户端,或者,将发送消息量小于或等于第一设定阈值的任一客户端确定为所述目标客户端。According to the amount of messages sent by each of the at least two clients to the target server, from among the at least two clients, determine the client that sends the smallest amount of messages as the target client, or , determining any client whose message volume is less than or equal to the first set threshold as the target client.
  3. 根据权利要求1所述的方法,其中,所述根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器,包括:The method according to claim 1, wherein, according to the load value of each server obtained again, determining the target server that does not meet the set load balancing conditions includes:
    对所述重新获取的每个服务器的负载值进行排序,得到排序结果;Sorting the load values of each server obtained again to obtain a sorting result;
    从所述排序结果中,得到负载值最高的服务器与负载值最低的服务器;在确定所述负载值最高的服务器与所述负载值最低的服务器的负载差值大于第二设定阈值时,将所述负载值最高的服务器确定为不满足所述设定负载均衡条件的目标服务器;或者,From the sorting results, the server with the highest load value and the server with the lowest load value are obtained; when it is determined that the load difference between the server with the highest load value and the server with the lowest load value is greater than a second set threshold, The server with the highest load value is determined as the target server that does not meet the set load balancing condition; or,
    将所述排序结果中负载值大于第三设定阈值的任一服务器确定为不满足所述设定负载均衡条件的目标服务器。Determining any server with a load value greater than a third set threshold in the sorting result as a target server that does not satisfy the set load balancing condition.
  4. 根据权利要求1所述的方法,其中,所述调整所述目标客户端的服务器清单,包括:The method according to claim 1, wherein said adjusting the server list of said target client comprises:
    将所述目标客户端的服务器清单中负载值最高的服务器移除,并向所述目标客户端的服务器清单中新增一个当前负载值最低的服务器。The server with the highest load value in the server list of the target client is removed, and a server with the lowest current load value is added to the server list of the target client.
  5. 根据权利要求1所述的方法,其中,所述方法还包括:The method according to claim 1, wherein the method further comprises:
    在接收所述多个客户端中每个客户端发送的连接请求之前,接收所述当前网络中每个服务器上报的负载确定参数;所述负载确定参数包括服务器的连接数、服务器在上一统计周期的处理消息量以及服务器上次被分配给客户端的时间中的至少一项;Before receiving the connection request sent by each client in the multiple clients, receive the load determination parameters reported by each server in the current network; the load determination parameters include the number of connections of the server, the server's last statistics At least one of the periodic processing message volume and the last time the server was assigned to the client;
    所述获取当前网络中每个服务器的负载值,包括:The acquisition of the load value of each server in the current network includes:
    根据所述当前网络中每个服务器上报的负载确定参数,确定当前网络中每个服务器的负载值。The load value of each server in the current network is determined according to the load determination parameters reported by each server in the current network.
  6. 根据权利要求5所述的方法,其中,在所述负载确定参数包括服务器的连接数、服务器在上一统计周期的处理消息量以及服务器上次被分配给客户端的时间的情况下,所述负载确定参数还包括连接数权重值、处理消息量权重值、以及时间参数权重值;The method according to claim 5, wherein, when the load determination parameters include the number of connections of the server, the amount of messages processed by the server in the last statistical period, and the time when the server was assigned to the client last time, the load The determination parameters also include the weight value of the connection number, the weight value of the processing message volume, and the weight value of the time parameter;
    所述根据所述当前网络中每个服务器上报的负载确定参数,确定当前网络中每个服务器的负载值,包括:The determining the load value of each server in the current network according to the load determination parameters reported by each server in the current network includes:
    根据所述当前网络中每个服务器上报的服务器的连接数与所述连接数权重值、服务器在上一统计周期的处理消息量与处理消息量权重值、服务器上次被分配给客户端的时间与时间参数权重值,确定当前网络中每个服务器的负载值。According to the number of server connections reported by each server in the current network and the weight value of the number of connections, the amount of messages processed by the server in the last statistical period and the weight value of the amount of messages processed, the time when the server was assigned to the client last time and The time parameter weight value determines the load value of each server in the current network.
  7. 根据权利要求1-6任一项所述的方法,其中,所述方法还包括:The method according to any one of claims 1-6, wherein the method further comprises:
    在当前统计周期内,每完成一次服务器清单的调整,对调整次数执行加1操作;In the current statistical period, every time the adjustment of the server list is completed, the number of adjustments will be increased by 1;
    计算所述当前统计周期内调整所述服务器清单的总调整次数与所述当前网路中每个服务器的总连接数的比值,得到所述当前统计周期的调整会话占比;Calculating the ratio of the total number of times of adjusting the server list in the current statistical period to the total number of connections of each server in the current network to obtain the proportion of adjusted sessions in the current statistical period;
    根据所述调整会话占比与第四设定阈值的大小关系,确定是否继续调整所述当前统计周期内的服务器清单。Whether to continue to adjust the server list in the current statistical period is determined according to the relationship between the adjusted session ratio and the fourth set threshold.
  8. 根据权利要求7所述的方法,其中,所述根据所述调整会话占比与第四设定阈值的大小关系,确定是否继续调整所述当前统计周期内的服务器清单,包括:The method according to claim 7, wherein the determining whether to continue adjusting the server list in the current statistical period according to the size relationship between the adjusted session proportion and the fourth set threshold includes:
    在确定所述调整会话占比大于或等于所述第四设定阈值时,等待所述当前统计周期结束;When it is determined that the adjusted session proportion is greater than or equal to the fourth set threshold, waiting for the end of the current statistics period;
    在确定所述调整会话占比小于所述第四设定阈值、且确定存在不满足设定负载均衡条件的目标服务器时,继续调整所述当前统计周期内的服务器清单。When it is determined that the adjusted session proportion is less than the fourth set threshold and it is determined that there is a target server that does not meet the set load balancing condition, continue to adjust the server list in the current statistical period.
  9. 一种负载均衡装置,所述装置包括:A load balancing device, the device comprising:
    第一确定模块,配置为接收到多个客户端中每个客户端发送的连接请求后,获取当前网络中每个服务器的负载值;根据所述每个服务器的负载值,确定所述每个客户端的服务器清单,向所述每个客户端下发对应的服务器清单;所述服务器清单中包括至少两个服务器;The first determining module is configured to obtain the load value of each server in the current network after receiving the connection request sent by each client in the plurality of clients; determine the load value of each server according to the load value of each server A server list of the client, sending a corresponding server list to each client; the server list includes at least two servers;
    第二确定模块,配置为在确定所述每个客户端与对应的服务器清单中每个服务器建立TCP长连接后,重新获取所述当前网络中每个服务器的负载值;根据重新获取的每个服务器的负载值,确定不满足设定负载均衡条件的目标服务器;The second determination module is configured to reacquire the load value of each server in the current network after determining that each client establishes a TCP long connection with each server in the corresponding server list; The load value of the server determines the target server that does not meet the set load balancing conditions;
    调整模块,配置为查找与所述目标服务器连接的目标客户端,调整所述目标客户端的服务器清单;所述目标客户端为所述多个客户端中的一个客户端。An adjustment module, configured to search for a target client connected to the target server, and adjust the server list of the target client; the target client is one of the plurality of clients.
  10. 一种电子设备,所述设备包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现权利要求1至8任一项所述的方法。An electronic device, the device comprising a memory, a processor, and a computer program stored on the memory and operable on the processor, when the processor executes the program, the method described in any one of claims 1 to 8 is realized method.
  11. 一种计算机存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现权利要求1至8任一项所述的方法。A computer storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
  12. 一种计算机程序产品,包括计算机可读代码,当所述计算机可读代码在电子设备中运行时,所述电子设备中的处理器执行权利要求1至8任一项所述的方法。A computer program product, comprising computer readable codes, when the computer readable codes are run in an electronic device, a processor in the electronic device executes the method according to any one of claims 1 to 8.
PCT/CN2022/099587 2021-09-30 2022-06-17 Load balancing method and apparatus, device, computer storage medium and program WO2023050901A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111165088.9 2021-09-30
CN202111165088.9A CN113810304A (en) 2021-09-30 2021-09-30 Load balancing method, device, equipment and computer storage medium

Publications (1)

Publication Number Publication Date
WO2023050901A1 true WO2023050901A1 (en) 2023-04-06

Family

ID=78939016

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/099587 WO2023050901A1 (en) 2021-09-30 2022-06-17 Load balancing method and apparatus, device, computer storage medium and program

Country Status (2)

Country Link
CN (1) CN113810304A (en)
WO (1) WO2023050901A1 (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117149099A (en) * 2023-10-31 2023-12-01 江苏华鲲振宇智能科技有限责任公司 Calculation and storage split server system and control method
CN117290114A (en) * 2023-11-23 2023-12-26 南京网眼信息技术有限公司 Load balancing method and system based on CPU integration
WO2024023728A1 (en) 2022-07-28 2024-02-01 Precision Planting Llc Agricultural sample packaging system
CN117745514A (en) * 2024-02-20 2024-03-22 浙江宇视科技有限公司 Image distribution method, device, equipment and medium of intelligent server cluster
CN117745514B (en) * 2024-02-20 2024-05-10 浙江宇视科技有限公司 Image distribution method, device, equipment and medium of intelligent server cluster

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113810304A (en) * 2021-09-30 2021-12-17 深圳前海微众银行股份有限公司 Load balancing method, device, equipment and computer storage medium
CN114780463A (en) * 2022-03-01 2022-07-22 阿里巴巴(中国)有限公司 Interrupt control method, device, distributed system and storage medium
CN115242720A (en) * 2022-08-03 2022-10-25 北京达佳互联信息技术有限公司 Connection method and device for long connection service, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105471760A (en) * 2014-09-12 2016-04-06 华为技术有限公司 Routing method, load balancing device and data communication system
CN107026907A (en) * 2017-03-30 2017-08-08 上海斐讯数据通信技术有限公司 A kind of load-balancing method, load equalizer and SiteServer LBS
US20200110625A1 (en) * 2018-10-04 2020-04-09 Cisco Technology, Inc. Placement of container workloads triggered by network traffic for efficient computing at network edge devices
CN112202918A (en) * 2020-10-16 2021-01-08 深圳乐播科技有限公司 Load scheduling method, device, equipment and storage medium for long connection communication
CN113810304A (en) * 2021-09-30 2021-12-17 深圳前海微众银行股份有限公司 Load balancing method, device, equipment and computer storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105471760A (en) * 2014-09-12 2016-04-06 华为技术有限公司 Routing method, load balancing device and data communication system
CN107026907A (en) * 2017-03-30 2017-08-08 上海斐讯数据通信技术有限公司 A kind of load-balancing method, load equalizer and SiteServer LBS
US20200110625A1 (en) * 2018-10-04 2020-04-09 Cisco Technology, Inc. Placement of container workloads triggered by network traffic for efficient computing at network edge devices
CN112202918A (en) * 2020-10-16 2021-01-08 深圳乐播科技有限公司 Load scheduling method, device, equipment and storage medium for long connection communication
CN113810304A (en) * 2021-09-30 2021-12-17 深圳前海微众银行股份有限公司 Load balancing method, device, equipment and computer storage medium

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024023728A1 (en) 2022-07-28 2024-02-01 Precision Planting Llc Agricultural sample packaging system
WO2024023731A1 (en) 2022-07-28 2024-02-01 Precision Planting Llc Agricultural sample packaging system
WO2024023729A1 (en) 2022-07-28 2024-02-01 Precision Planting Llc Agricultural sample packaging system and related methods
CN117149099A (en) * 2023-10-31 2023-12-01 江苏华鲲振宇智能科技有限责任公司 Calculation and storage split server system and control method
CN117149099B (en) * 2023-10-31 2024-03-12 江苏华鲲振宇智能科技有限责任公司 Calculation and storage split server system and control method
CN117290114A (en) * 2023-11-23 2023-12-26 南京网眼信息技术有限公司 Load balancing method and system based on CPU integration
CN117290114B (en) * 2023-11-23 2024-01-30 南京网眼信息技术有限公司 Load balancing method and system based on CPU integration
CN117745514A (en) * 2024-02-20 2024-03-22 浙江宇视科技有限公司 Image distribution method, device, equipment and medium of intelligent server cluster
CN117745514B (en) * 2024-02-20 2024-05-10 浙江宇视科技有限公司 Image distribution method, device, equipment and medium of intelligent server cluster

Also Published As

Publication number Publication date
CN113810304A (en) 2021-12-17

Similar Documents

Publication Publication Date Title
WO2023050901A1 (en) Load balancing method and apparatus, device, computer storage medium and program
US9804981B2 (en) Method, controller, and system for service flow control in object-based storage system
CN109218355B (en) Load balancing engine, client, distributed computing system and load balancing method
CN109308221B (en) Nginx dynamic load balancing method based on WebSocket long connection
US7773522B2 (en) Methods, apparatus and computer programs for managing performance and resource utilization within cluster-based systems
CN111726415B (en) TCP long connection load balancing scheduling method and system based on negative feedback mechanism
US8015281B2 (en) Dynamic server flow control in a hybrid peer-to-peer network
WO2010100859A1 (en) Distributed system
US9219786B2 (en) Behavior based client selection for disparate treatment
Nakai et al. Load balancing for internet distributed services using limited redirection rates
EP3264723B1 (en) Method, related apparatus and system for processing service request
US11316792B2 (en) Method and system of limiting traffic
US20160065660A1 (en) Computer system, computer, and load balancing method
WO2021120633A1 (en) Load balancing method and related device
CN112711479A (en) Load balancing system, method and device of server cluster and storage medium
WO2019237531A1 (en) Network node monitoring method and system
Bang et al. Design and implementation of a load shedding engine for solving starvation problems in Apache Kafka
US10237148B2 (en) Providing a data set for tracking and diagnosing datacenter issues
US9270746B2 (en) Scalable load balancing
CN112866394B (en) Load balancing method, device, system, computer equipment and storage medium
CN113268329A (en) Request scheduling method, device and storage medium
CN111614735B (en) Novel fog computing architecture based on weighted round robin algorithm and task scheduling method thereof
CN111611068B (en) Data writing method in distributed system, server and client
US20230396677A1 (en) Computing power information processing method, first network device, and system
Yoshimura et al. A Method of Distributing Clients to MQTT Brokers Using Server Redirection

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22874298

Country of ref document: EP

Kind code of ref document: A1