CN107453938B - Load balancing method, system, electronic device and computer readable storage medium - Google Patents

Load balancing method, system, electronic device and computer readable storage medium Download PDF

Info

Publication number
CN107453938B
CN107453938B CN201610534680.4A CN201610534680A CN107453938B CN 107453938 B CN107453938 B CN 107453938B CN 201610534680 A CN201610534680 A CN 201610534680A CN 107453938 B CN107453938 B CN 107453938B
Authority
CN
China
Prior art keywords
node
count
state
equal
last
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201610534680.4A
Other languages
Chinese (zh)
Other versions
CN107453938A (en
Inventor
徐新坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
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 Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Publication of CN107453938A publication Critical patent/CN107453938A/en
Application granted granted Critical
Publication of CN107453938B publication Critical patent/CN107453938B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/10Active monitoring, e.g. heartbeat, ping or trace-route
    • H04L43/103Active monitoring, e.g. heartbeat, ping or trace-route with adaptive polling, i.e. dynamically adapting the polling rate
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • H04L43/0805Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
    • H04L43/0817Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking functioning
    • 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/1029Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers using data related to the state of servers by a load balancer

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Environmental & Geological Engineering (AREA)
  • Health & Medical Sciences (AREA)
  • Cardiology (AREA)
  • General Health & Medical Sciences (AREA)
  • Test And Diagnosis Of Digital Computers (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a load balancing method and a system, after checking the validity of a node each time, the probability that the node state is unchanged when the node is checked next time is calculated, and the time interval between the node check and the next node check after the node check is finished this time is calculated according to the probability, so that the time interval of the node check can be dynamically changed, namely for the node with the unchanged validity state, the checking frequency is adaptively reduced, the resource consumption required by the check is reduced, for the node with the changed validity, the checking frequency is adaptively improved, and the checking real-time performance is ensured.

Description

Load balancing method, system, electronic device and computer readable storage medium
Technical Field
The invention belongs to the technical field of computers, and particularly relates to a load balancing method and a load balancing system, which are used for realizing load balancing of flow among a plurality of nodes.
Background
In a large internet company, applications are deployed on many nodes, and in order to achieve load balancing among the nodes, traffic distribution needs to be performed on the nodes. As shown in fig. 1, in the prior art, a load balancing cluster is used to perform node splitting, where the load balancing cluster is composed of a plurality of load balancers (e.g., haproxy and nginx), each load balancer is connected to each node, and the load balancers may forward a request of a user to an application on the node and return an execution result of the application on the node to the user.
The load balancer needs to periodically perform validity checks on the nodes at the back end to ensure that the nodes are valid. In the prior art, two schemes are generally adopted for node validity check: one is to check the validity of high frequency, which may result in consuming a lot of unnecessary resources and even overwhelming some nodes that are busy; another approach is to increase the period of health checks, which, while reducing resource consumption, can lose timeliness of node checks.
Disclosure of Invention
Technical problem to be solved
The invention provides a load balancing method and a load balancing system, which can detect effective nodes in all nodes with low resource consumption and high real-time performance and realize load balancing among the effective nodes.
(II) technical scheme
The invention provides a load balancing method, which is used for realizing load balancing of flow among a plurality of nodes and comprises the following steps:
s1, circularly checking the validity of each node in the plurality of nodes, and identifying the node as a valid node or a failed node;
s2, the traffic is directed to an active node of the plurality of nodes.
Further, in step S1, when each node is checked in a loop, if the node is checked to be in a valid state for r consecutive times, the node is identified as a valid node, and if the node is checked to be in a invalid state for f consecutive times, the node is identified as a invalid node, where r and f are integers greater than or equal to 2.
Further, step S1 includes:
s11, setting a count variable and a last _ state variable for each node, wherein, when the node is checked each time, if the validity of the node is not changed, the count is added with 1, otherwise, the count is equal to 0, the last _ state represents the validity of the last checked node, the count is initialized to 0, and the value of the last _ state is initialized to be in a valid state or a failure state;
s12, obtaining a random number m between 0 and 1, and starting validity check after sleeping for m multiplied by n time, wherein n represents the period of each check and the unit is second;
s13, obtaining the current _ state of the node, if the current _ state is not equal to last _ state, executing step S14, if it is equal to last _ state, executing step S15;
s14, let count equal to 0, let last _ state equal to current _ state, after sleeping for n times, execute step S13;
s15, calculating the probability p that the current _ state and last _ state of the node are equal when checking next timecount
Figure GDA0001479485640000021
Wherein x and s are configurable constants,
then calculating the time interval t from the current check to the next checkcount
tcount=pcount×c+n,
Wherein c is a configurable constant, and meanwhile, the count is added by 1;
s16, if current _ state is valid and count is greater than or equal to r, identifying the node as valid, if current _ state is invalid and count is greater than or equal to f, identifying the node as invalid;
s17, dormancy tcountAfter that time, the process proceeds to step S13.
Preferably, n is 1, c is 2, x is 1.5, and s is 10.
Further, p corresponding to the time when count goes from 0 to size is calculated in advancecountAnd combining these pcountStoring in a memory; in the calculation of pcountIf the count is less than or equal to the size, directly obtaining p corresponding to the count value from the memorycountIf count is larger than size, directly obtaining p corresponding to size from memorycountWhere size is a configurable constant.
The invention also provides a load balancing system, which is connected with a plurality of nodes and used for realizing load balancing of flow among the nodes, and the system comprises:
the checking module is used for circularly checking the validity of each node in the plurality of nodes and identifying the node as a valid node or a failed node;
and the traffic import module is used for importing traffic into an effective node of the plurality of nodes.
Further, when each node is checked in a circulating mode, if the node is checked to be in a valid state for r times, the node is identified to be a valid node, and if the node is checked to be in a failure state for f times, the node is identified to be a failure node, wherein r and f are integers greater than or equal to 2.
Further, the checking module performs the steps of:
s11, setting a count variable and a last _ state variable for each node, wherein, when the node is checked each time, if the validity of the node is not changed, the count is added with 1, otherwise, the count is equal to 0, the last _ state represents the validity of the last checked node, the count is initialized to 0, and the value of the last _ state is initialized to be in a valid state or a failure state;
s12, obtaining a random number m between 0 and 1, and starting validity check after sleeping for m multiplied by n time, wherein n represents the period of each check and the unit is second;
s13, obtaining the current _ state of the node, if the current _ state is not equal to last _ state, executing step S14, if it is equal to last _ state, executing step S15;
s14, let count equal to 0, let last _ state equal to current _ state, after sleeping for n times, execute step S13;
s15, calculating the probability p that the current _ state and last _ state of the node are equal when checking next timecount
Figure GDA0001479485640000041
Wherein x and s are configurable constants,
then calculating the time interval t from the current check to the next checkcount
tcount=pcount×c+n,
Wherein c is a configurable constant, and meanwhile, the count is added by 1;
s16, if current _ state is valid and count is greater than or equal to r, identifying the node as valid, if current _ state is invalid and count is greater than or equal to f, identifying the node as invalid;
s17, dormancy tcountAfter that time, the process proceeds to step S13.
Preferably, n is 1, c is 2, x is 1.5, and s is 10.
Further, the checking module pre-calculates p corresponding to the time when the count goes from 0 to sizecountAnd combining these pcountStoring in a memory; in the calculation of pcountIf the count is less than or equal to the size, directly obtaining p corresponding to the count value from the memorycountIf count is larger than size, directly obtaining p corresponding to size from memorycountWhere size is a configurable constant.
The invention also provides an electronic device comprising a memory and a processor coupled to the memory, the processor being configured to execute the above load balancing method based on instructions stored in the memory.
The present invention also provides a computer-readable storage medium storing computer instructions which, when executed by a processor, implement the load balancing method described above.
(III) advantageous effects
In the load balancing method and the load balancing system, after the validity of the node is checked each time, the time for checking the node next time is calculated, so that the time interval for checking the node is dynamically changed, namely for the node with unchanged validity state, the checking frequency is adaptively reduced, the resource consumption required by checking is reduced, for the node with changed validity, the checking frequency is adaptively improved, and the checking real-time performance is ensured.
Drawings
Fig. 1 is a schematic diagram of load balancing between nodes by using a load balancing cluster in the prior art.
Fig. 2 is a flowchart of a load balancing method according to an embodiment of the present invention.
Fig. 3 is a flowchart of node validity checking in an embodiment of the present invention.
FIG. 4 shows a check interval t according to an embodiment of the inventioncountGraph of change with count value.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to specific embodiments and the accompanying drawings.
Fig. 2 is a flowchart of a load balancing method according to an embodiment of the present invention, and as shown in fig. 2, the method includes:
and S1, circularly checking the validity of each node in the plurality of nodes, and identifying the node as a valid node or a invalid node. A node as referred to herein may be a server (server) on which an application is installed to determine whether the server node is valid by checking whether the application on the server is successfully serviced. In this embodiment, if the node is checked to be in the valid state for 3 consecutive times, the node is identified as a valid node, and if the node is checked to be in the invalid state for 4 consecutive times, the node is identified as a invalid node.
S2, the traffic is directed to an active node of the plurality of nodes. For an invalid node, traffic is not introduced to it because it cannot work normally. The present step may adopt the existing load balancing method, and is not described herein again.
However, practical experience shows that if a node is checked to be valid at this time, the probability that the node is checked to be valid at the next time is increased, and similarly, if a node is checked to be invalid at this time, the probability that the node is checked to be invalid at the next time is increased. Therefore, a certain one is checked i times in successionWhen the node is in the same state, the probability that the node keeps the same state is checked for the (i + 1) th time
Figure GDA0001479485640000051
x and s are configurable parameters, and in this embodiment, x is 1.5 and s is 10.
Fig. 3 is a flowchart of node validity checking performed in the embodiment of the present invention, and as shown in fig. 3, step S1 specifically includes:
s11, setting a count variable and a last _ state variable for each node, wherein, each time the node is checked, if the validity of the node is not changed, the count is added with 1, otherwise, the count is equal to 0, the last _ state represents the validity of the last checked node, the count is initialized to 0, and the value of the last _ state is initialized to a failure state;
s12, obtaining a random number m between 0 and 1, and starting validity check after sleeping for mxn time, wherein n is equal to 1 second;
s13, obtaining the current _ state of the node, if the current _ state is not equal to last _ state, executing step S14, if it is equal to last _ state, executing step S15;
s14, let count equal to 0, let last _ state equal to current _ state, after sleeping for n times, execute step S13;
s15, calculating the probability p that the current _ state and last _ state of the node are equal when checking next timecount
Figure GDA0001479485640000061
Wherein x is 1.5, s is 10,
then calculating the time interval t from the current check to the next checkcount
tcount=pcount×c+n,
Wherein c is 2, and adding 1 to the count;
s16, if current _ state is valid and count is greater than or equal to r, identifying the node as valid, if current _ state is invalid and count is greater than or equal to f, identifying the node as invalid;
s17, dormancy tcountAfter that time, the process proceeds to step S13.
In actual operation, p is calculated for liftcountThe efficiency of (1) can be obtained by pre-calculating the value of count from 0 to 20 to obtain a value of p0To p20Then store it in the memory when count<When the count is 20, the first count of the p _ list, that is, the p _ list [ count ] is directly obtained]And p iscountThe value is p _ list [ count ]]. When count>At 20, the last number p of the p _ list array is obtained20And p iscountValue of p20
FIG. 4 shows a check interval t according to an embodiment of the inventioncountThe graph showing the variation with the count value is shown in FIG. 4, where the horizontal axis represents the count and the vertical axis represents the tcountWhen the count value is small, namely when the state change is just completed, the high-frequency check is kept, so that the state of the rear-end server can be determined quickly according to the configured rise or fall times, and the timeliness of the check is ensured. When the count value is gradually increased, the period of the examination is appropriately prolonged, and pcountThe rule that the more times a certain state is continuously kept, the higher the probability of keeping the state is checked next time is also met. In this embodiment, the maximum value of the check period is smaller than c + n, which ensures that the check period is not extended indefinitely, so as to avoid losing the timeliness of the health check.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the present invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A load balancing method is used for realizing load balancing of traffic among a plurality of nodes, and is characterized by comprising the following steps:
s1, circularly checking the validity of each node in the plurality of nodes, and identifying the node as a valid node or a failed node;
s2, leading the flow into an effective node of a plurality of nodes;
wherein the step S1 includes:
s11, setting a count variable and a last _ state variable for each node, wherein, when the node is checked each time, if the validity of the node is not changed, the count is added with 1, otherwise, the count is equal to 0, the last _ state represents the validity of the last checked node, the count is initialized to 0, and the value of the last _ state is initialized to be in a valid state or a failure state;
s12, obtaining a random number m between 0 and 1, and starting validity check after sleeping for m multiplied by n time, wherein n represents the period of each check and the unit is second;
s13, obtaining the current _ state of the node currently checked, if the current _ state is not equal to last _ state, executing step S14, if equal, executing step S15:
s14, let count equal to 0, let last _ state equal to current _ state, after sleeping for n times, execute step S13;
s15, calculating the probability p that the current _ state and last _ state of the node are equal when checking next timecount
Figure FDA0002629216400000011
Wherein x and s are configurable constants,
then calculating the time interval t from the current check to the next checkcount
tcount=pcount×c+n,
Wherein c is a configurable constant, and meanwhile, the count is added by 1;
s16, if current _ state is valid and count is greater than or equal to r, identifying the node as valid, if current _ state is invalid and count is greater than or equal to f, identifying the node as invalid;
s17, dormancy tcountAfter that time, the process proceeds to step S13.
2. The method according to claim 1, wherein in step S1, when each node is checked in a loop, if the node is checked to be in a valid state for r times, the node is identified as a valid node, and if the node is checked to be in a failed state for f times, the node is identified as a failed node, where r and f are integers greater than or equal to 2.
3. The load balancing method according to claim 1, wherein n is 1, c is 2, x is 1.5, and s is 10.
4. The method according to claim 1, wherein p is pre-calculated for a count from 0 to sizecountAnd combining these pcountStoring in a memory; in the calculation of pcountIf the count is less than or equal to the size, directly obtaining p corresponding to the count value from the memorycountIf count is larger than size, directly obtaining p corresponding to size from memorycountWhere size is a configurable constant.
5. A load balancing system, connected to a plurality of nodes, for load balancing traffic among the plurality of nodes, the system comprising:
the checking module is used for circularly checking the validity of each node in the plurality of nodes and identifying the node as a valid node or a failed node;
the traffic import module is used for importing traffic into an effective node of the plurality of nodes;
the inspection module performs the steps of:
s11, setting a count variable and a last _ state variable for each node, wherein, when the node is checked each time, if the validity of the node is not changed, the count is added with 1, otherwise, the count is equal to 0, the last _ state represents the validity of the last checked node, the count is initialized to 0, and the value of the last _ state is initialized to be in a valid state or a failure state;
s12, obtaining a random number m between 0 and 1, and starting validity check after sleeping for m multiplied by n time, wherein n represents the period of each check and the unit is second;
s13, obtaining the current _ state of the node currently checked, if the current _ state is not equal to last _ state, executing step S14, if equal, executing step S15:
s14, let count equal to 0, let last _ state equal to current _ state, after sleeping for n times, execute step S13;
s15, calculating the probability p that the current _ state and last _ state of the node are equal when checking next timecount
Figure FDA0002629216400000031
Wherein x and s are configurable constants,
then calculating the time interval t from the current check to the next checkcount
tcount=pcount×c+n,
Wherein c is a configurable constant, and meanwhile, the count is added by 1;
s16, if current _ state is valid and count is greater than or equal to r, identifying the node as valid, if current _ state is invalid and count is greater than or equal to f, identifying the node as invalid;
s17, dormancy tcountAfter that time, the process proceeds to step S13.
6. The load balancing system of claim 5, wherein the checking module identifies each node as a valid node if the node is checked to be in a valid state for r consecutive times, and identifies the node as a failed node if the node is checked to be in a failed state for f consecutive times, wherein r and f are integers greater than or equal to 2.
7. The load balancing system of claim 5, wherein n is 1, c is 2, x is 1.5, and s is 10.
8. The load balancing system of claim 5, wherein the checking module pre-calculates p corresponding to the count from 0 to sizecountAnd combining these pcountStoring in a memory; in the calculation of pcountIf the count is less than or equal to the size, directly obtaining p corresponding to the count value from the memorycountIf count is larger than size, directly obtaining p corresponding to size from memorycountWhere size is a configurable constant.
9. An electronic device, comprising:
a memory; and
a processor coupled to the memory, the processor configured to perform the method of load balancing of any one of claims 1 to 4 based on instructions stored in the memory.
10. A computer-readable storage medium storing computer instructions which, when executed by a processor, implement a load balancing method as claimed in any one of claims 1 to 4.
CN201610534680.4A 2016-05-30 2016-07-07 Load balancing method, system, electronic device and computer readable storage medium Active CN107453938B (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN2016103705751 2016-05-30
CN201610370575 2016-05-30

Publications (2)

Publication Number Publication Date
CN107453938A CN107453938A (en) 2017-12-08
CN107453938B true CN107453938B (en) 2020-11-20

Family

ID=60486147

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610534680.4A Active CN107453938B (en) 2016-05-30 2016-07-07 Load balancing method, system, electronic device and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN107453938B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101986272A (en) * 2010-11-05 2011-03-16 北京大学 Task scheduling method under cloud computing environment
CN103368864A (en) * 2013-07-31 2013-10-23 北京华易互动科技有限公司 Intelligent load balancing method based on c/s (Client/Server) architecture
CN103491512A (en) * 2012-06-12 2014-01-01 腾讯科技(深圳)有限公司 Implementation method and device for information pushing
CN104991850A (en) * 2015-06-27 2015-10-21 广州华多网络科技有限公司 Heartbeat package control method and apparatus for application program
CN105376317A (en) * 2015-11-19 2016-03-02 网宿科技股份有限公司 Load balancing control method and load balancing control device
CN105577507A (en) * 2014-11-10 2016-05-11 中国移动通信集团广东有限公司 Heartbeat packet transmission interval adjustment method, device and server

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8938645B2 (en) * 2012-09-19 2015-01-20 Sap Se Invalidation of metadata buffers

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101986272A (en) * 2010-11-05 2011-03-16 北京大学 Task scheduling method under cloud computing environment
CN103491512A (en) * 2012-06-12 2014-01-01 腾讯科技(深圳)有限公司 Implementation method and device for information pushing
CN103368864A (en) * 2013-07-31 2013-10-23 北京华易互动科技有限公司 Intelligent load balancing method based on c/s (Client/Server) architecture
CN105577507A (en) * 2014-11-10 2016-05-11 中国移动通信集团广东有限公司 Heartbeat packet transmission interval adjustment method, device and server
CN104991850A (en) * 2015-06-27 2015-10-21 广州华多网络科技有限公司 Heartbeat package control method and apparatus for application program
CN105376317A (en) * 2015-11-19 2016-03-02 网宿科技股份有限公司 Load balancing control method and load balancing control device

Also Published As

Publication number Publication date
CN107453938A (en) 2017-12-08

Similar Documents

Publication Publication Date Title
US11888756B2 (en) Software load balancer to maximize utilization
CN103902386B (en) Multi-thread network crawler processing method based on connection proxy optimal management
CN110535787B (en) Message consumption method, device and readable storage medium
WO2018161735A1 (en) Parent node selection method and network node
US11650990B2 (en) Method, medium, and system for joining data tables
WO2022001086A1 (en) Efficient gpu resource allocation optimization method and system
JP2012118987A (en) Computer implementation method, computer program, and system for memory usage query governor (memory usage query governor)
US11144366B2 (en) Computing node processor resource optimization method, computing node and server cluster
CN103412786A (en) High performance server architecture system and data processing method thereof
US11748164B2 (en) FAAS distributed computing method and apparatus
CN104639645A (en) Method and device for balancing network load, and cluster service system
CN107370808B (en) Method for performing distributed processing on big data task
US20190075060A1 (en) Low-redistribution load balancing
CN112118314B (en) Load balancing method and device
US9916182B2 (en) Method and apparatus for allocating stream processing unit
CN116227599A (en) Inference model optimization method and device, electronic equipment and storage medium
CN109558232B (en) Determination method, apparatus, equipment and the medium of degree of parallelism
CN107453938B (en) Load balancing method, system, electronic device and computer readable storage medium
WO2019028987A1 (en) Data processing method, electronic device and computer readable storage medium
CN115484233B (en) Method, device, equipment and medium for forwarding link aggregation message in digital communication chip
CN115002114B (en) Node processing method, device, electronic equipment, storage medium and server
CN113946274B (en) Data processing method, device, equipment and medium
CN111865722B (en) Node health state detection and processing method
CN109408242B (en) Server resource online and offline method and device
CN109542601B (en) Policy compiling method and device, electronic equipment and computer storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant