Summary of the invention
To overcome the problems in correlation technique, present description provides the current-limiting method of distributed system, device and
Equipment.
According to this specification embodiment in a first aspect, provide a kind of current-limiting method of distributed system, the distribution
Include multiple nodes in system, includes at least one host node and at least one child node, the current limliting in the multiple node
Method includes:
After each node determines that current limliting is triggered, the request to be processed that load balancer is sent is intercepted to message
It manages in queue;
The host node is after the request to be processed that setting quantity is chosen in the Message Processing queue, by the to be processed of selection
Request is distributed at least one described node;
After the child node receives the request to be processed of the host node distribution, request processing flow is executed.
Optionally, the host node chooses the request to be processed from the Message Processing queue according to the setting period.
Optionally, the host node is elected to obtain by all nodes by election mechanism.
Optionally, the determining current limliting is triggered, comprising: and the quantity of request to be processed reaches setting current limit threshold, or
It is to receive setting current limliting instruction.
Optionally, the method also includes the request to be processed backups that: each node also sends load balancer
In database.
Optionally, the method also includes: for processing complete request to be processed, update the request in the database
Processing status.
Optionally, the method also includes: if the Message Processing queue is operating abnormally, the host node is from the data
Request to be processed is chosen in library.
Optionally, the host node is to choose setting the to be processed of quantity from the Message Processing queue according to priority to ask
It asks.
According to the second aspect of this specification embodiment, a kind of current-limiting method of distributed system is provided, the method is answered
For any node in distributed system, which comprises
After determining that current limliting is triggered, the request to be processed that load balancer is distributed is intercepted into Message Processing queue;
Determine it itself is host node either child node;
If host node, after the request to be processed that setting quantity is chosen in the Message Processing queue, by selection wait locate
Reason request is distributed at least one described node;
If child node, then after the request for receiving host node distribution, request processing flow is executed.
Optionally, the host node chooses the request to be processed from the Message Processing queue according to the setting period.
Optionally, the host node is elected to obtain by all nodes by election mechanism.
Optionally, the determining current limliting is triggered, comprising: and the quantity of request to be processed reaches setting current limit threshold, or
It is to receive setting current limliting instruction.
Optionally, the method also includes: by load balancer send request to be processed back up in database.
Optionally, the method also includes: for processing complete request to be processed, update the request in the database
Processing status.
Optionally, the method also includes: if the Message Processing queue is operating abnormally, the host node is from the data
Request to be processed is chosen in library.
Optionally, the host node is to choose setting the to be processed of quantity from the Message Processing queue according to priority to ask
It asks.
According to the third aspect of this specification embodiment, a kind of current-limiting apparatus of distributed system is provided, described device is answered
For any node in distributed system, described device includes:
Blocking module is used for: after determining that current limliting is triggered, the request to be processed that load balancer is distributed being intercepted to message
It handles in queue;
Determining module is used for: determining it itself is host node either child node;
Distribution module is used for: if host node, the request to be processed of setting quantity is chosen from the Message Processing queue
Afterwards, the request to be processed of selection is distributed at least one described node;
Processing module is used for: if child node, then after the request for receiving host node distribution, executing request processing flow.
Optionally, the host node chooses the request to be processed from the Message Processing queue according to the setting period.
Optionally, the host node is elected to obtain by all nodes by election mechanism.
Optionally, the blocking module, is also used to: the quantity of request to be processed reaches setting current limit threshold, or connects
Receive setting current limliting instruction.
Optionally, described device further includes backup module, is used for: by load balancer send request to be processed backup in
In database.
Optionally, the method also includes: for processing complete request to be processed, update the request in the database
Processing status.
Optionally, the distribution module is also used to: if the Message Processing queue is operating abnormally, the host node is from described
Request to be processed is chosen in database.
Optionally, the host node is to choose setting the to be processed of quantity from the Message Processing queue according to priority to ask
It asks.
According to the fourth aspect of this specification embodiment, a kind of computer equipment is provided, including memory, processor and deposit
Store up the computer program that can be run on a memory and on a processor, wherein the processor is realized when executing described program
Aforementioned current-limiting method.
The technical solution that the embodiment of this specification provides can include the following benefits:
In this specification embodiment, the current limliting scheme of distributed system can be when needing current limliting, and each node intercepts negative
The request to be processed of balanced device distribution is carried into Message Processing queue, chooses setting number from the Message Processing queue by host node
After the request to be processed of amount, the request to be processed of selection is distributed at least one described node and is handled.The present embodiment can
To control the flow of whole system from the angle of global traffic, in the case where saving system resource, it can protect system and exist
Big flow still normally can externally provide service in the case where impacting, to achieve the purpose that protection system.
It should be understood that above general description and following detailed description be only it is exemplary and explanatory, not
This specification can be limited.
Specific embodiment
Example embodiments are described in detail here, and the example is illustrated in the accompanying drawings.Following description is related to
When attached drawing, unless otherwise indicated, the same numbers in different drawings indicate the same or similar elements.Following exemplary embodiment
Described in embodiment do not represent all embodiments consistent with this specification.On the contrary, they are only and such as institute
The example of the consistent device and method of some aspects be described in detail in attached claims, this specification.
It is only to be not intended to be limiting this explanation merely for for the purpose of describing particular embodiments in the term that this specification uses
Book.The "an" of used singular, " described " and "the" are also intended to packet in this specification and in the appended claims
Most forms are included, unless the context clearly indicates other meaning.It is also understood that term "and/or" used herein is
Refer to and includes that one or more associated any or all of project listed may combine.
It will be appreciated that though various information may be described using term first, second, third, etc. in this specification, but
These information should not necessarily be limited by these terms.These terms are only used to for same type of information being distinguished from each other out.For example, not taking off
In the case where this specification range, the first information can also be referred to as the second information, and similarly, the second information can also be claimed
For the first information.Depending on context, word as used in this " if " can be construed to " ... when " or
" when ... " or " in response to determination ".
With the fast development of internet, Internet application is while amount of access rapid growth, operation system without when without
The impact for not being faced with big flow is carved, if service still normally cannot can externally be provided under big flow impact, entirely
System is likely to paralyse in the case where big flow is impacted, although operation system can split dilatation by distribution, sometimes
The flow of operation system is not that can all face very big flow always, and big flow is possible to only occur in the advertising campaign phase
Between, if specifically for System Expansion should be carried out to short-term big flow, within a very long time later, distributed system
There is substantial portion of resource to be at idle state in fact, and then wastes system resource.
This specification embodiment is directed to above-mentioned distributed system scene, provides a kind of current limliting scheme, can be from global flow
The angle of amount can protect system and impact in big flow to control the flow of whole system in the case where saving system resource
In the case where service still normally can be externally provided, to achieve the purpose that protection system.
As shown in Figure 1, being a kind of this specification business scenario schematic diagram shown according to an exemplary embodiment, in Fig. 1
Include: multiple request originators, the distributed system including multiple nodes and load balancer;Wherein, load balancer with
Each node connection in distributed system, load balancer can accept the request to be processed that each request originator is initiated,
By the node to be processed requested assignment in distributed system.
When facing big flow, there are many number of requests that load balancer distributes to each node, it is possible to exceed node institute
The range that can be born.The scheme of the present embodiment proposes a kind of distributed system from the global traffic of limitation distributed system
The solution for current limliting of uniting is as shown in Figure 2 A a kind of this specification distributed system shown according to an exemplary embodiment
Current-limiting method flow chart, wherein include multiple nodes in the distributed system, include at least one in the multiple node
Host node and at least one child node, comprising:
In step 202, after each node determines that current limliting is triggered, by the request to be processed of load balancer transmission
It intercepts into Message Processing queue.
In step 204, the host node, will after the request to be processed that setting quantity is chosen in the Message Processing queue
The request to be processed chosen is distributed at least one described node.
In step 206, after the child node receives the request to be processed that the host node is distributed, request processing is executed
Process.
Optionally, the trigger timing or condition of flexible configuration current limliting be can according to need in practical application, by way of example, can
To be that can be artificial current limliting of initiating using the trigger timing at the beginning of advertising campaign as current limliting and instruct, be also possible to root
According to uninterrupted automatic trigger current limliting, it can also be situations such as abnormal progress current limliting etc. occur in distributed system.Specifically, institute
It states the quantity that a kind of mode that determining current limliting is triggered is request to be processed and reaches setting current limit threshold, wherein the current limit threshold
Can according to need flexible setting, be based on this, the present embodiment can the current total flow of monitoring system in a distributed system it is big
It is small, if it exceeds the current limiting threshold of setting, then Dynamic trigger current limliting, and according in the certain period of time of backstage configuration flow it is big
It is small come dynamic current limiting.Optionally, determine that the other modes that current limliting is triggered can also receive setting current limliting instruction, dynamic current limiting
Switch can also be by backstage configuration by manually triggering, to achieve the purpose that protect distributed system.
In the present embodiment, the size of flow can be by the calculating of the quantity to request to be processed come real in distributed system
It is existing.As shown in Figure 2 B, distributed system can collect the flow in current system, such as can be by requesting all global note every time
Number, by way of example, the Incr of Redis can be used) realize, wherein Redis be being write using ANSI C an of open source,
Support network, it is memory-based also can persistence log type, Key-Value database, and provide the API of multilingual.
The digital value stored in key can be increased one by the Incr order of Redis.Specifically, each node connects the same Redis in system
(independently and its either cluster is all possible), node remember that a number (calls Redis's for each request to be processed
Incr is realized) so that recording the whole flow of distributed system in Redis.It is appreciated that can spirit as needed in practical application
Selection other modes living, the present embodiment do not limit this.
Furthermore it is possible to (optionally, can be the maximum in the unit time in the backstage of distributed system configuration current limit threshold
Number of request), when flow system flow reaches current limit threshold, current limiting switch can be automatically turned on, determines and executes current limliting processing;In other examples
In, it is also possible to manually trigger current limiting switch on backstage, distributed system starts to carry out current limliting processing later.
In the present embodiment, the node in distributed system can receive the request to be processed of load balancer transmission, if point
The normal inactive current limliting of the flow of cloth system, then each node receives the to be processed of load balancer transmission in distributed system
After request, directly request to be processed can be handled.In the case where needing current limliting, each node is for load in the present embodiment
The request to be processed that balanced device is sent will not be handled directly, but request to be processed is intercepted into Message Processing queue
(optional, can be realized using the priority query zset of Redis), fishes for setting number by host node from Message Processing queue
Each node is distributed to after the request of amount to be handled.The present embodiment limits the quantity of request to be processed using host node, can
To prevent impact of the big flow to each node.
Optionally, problem caused by Message Processing queue exception, request to be processed can also be backed up simultaneously in order to prevent
It under Message Processing queue abnormal conditions, can also be got from database to be processed to database for use as data of revealing all the details
Request.
A host node (Master node) can be determined in the present embodiment from each node of distributed system, after being used for
Continuous message distribution.Optionally, determine that host node can be there are many implementation.In some instances, can be by distribution
In system each node according to setting rule select one of node as host node, optionally, the setting rule can be with
Machine is chosen, and can be based on node software and hardware resources selection etc.;It can also be configured by technical staff.It is additionally provided in the present embodiment
The implementation of election mechanism, host node are elected to obtain by all nodes by election mechanism, elect one by each node
A Master node, by way of example, can be realized by the Master election mechanism of Zookeeper, wherein Zookeeper is
One distributed, open source code distributed application program coordination service.
In the present embodiment, other nodes except host node are known as child node, are based on this, each section in distributed system
Point can determine it itself is host node or child node.For host node, setting quantity can be chosen from Message Processing queue
Request to be processed be distributed at least one described node, optionally, request to be processed can be divided based on load balancing
Hair, whether it includes host node itself that the node of distribution does not limit, does not also limit and whether is distributed to all child nodes either part
Child node.Optionally, which can be determined, the present embodiment based on the uninterrupted that can bear in distributed system
It does not limit this.Wherein, the priority of various requests to be processed is provided in Message Processing queue in advance, such as can be according to
The priority of some products is ranked up or is that business is ranked up according to other dimensions etc. as desired, practical application
In can flexible configuration as needed, the present embodiment do not limit this.
Optionally, since processing of the node to the request to be processed distributed needs certain time, host node can be according to
The period is set from from the Message Processing queue selection request to be processed, that is to say that host node is chosen at regular intervals,
As an example, the period is set as 10 seconds, then host node was chosen primary and is distributed every 10 seconds, which is used for each
The processing that node makes requests.Wherein, which can according to need flexible configuration, such as the processing capacity based on node
And determine, the present embodiment does not limit this.As a kind of implementation, can in Master node configuring timing tasks,
To after the trigger time of timed task, request to be processed is chosen according to priority from Message Processing queue, it is specific to choose
Quantity can be determined by the current limliting number of backstage configuration.Finally, the request to be processed of selection is distributed to distributed system by host node
Node in system.After each node receives solicited message in distributed system, it can be requested according to normal flow processing.
Optionally, since the request to be processed that each node also sends load balancer is backed up in database,
If the Message Processing queue is operating abnormally, host node can also select request to be processed from the database.Wherein, node
After request to be processed is completed in processing, can in more new database the request processing status, which can be processing
It completes or untreated etc., it therefore, can be according to the processing requested in database when choosing request to be processed in host node database
State chooses request to be processed.
Next it is illustrated again by Fig. 2 C, each node can configure a global interception in distributed system
Device is responsible for intercepting request to be processed.Using the blocker, first determine whether current limiting switch is opened, current limiting switch unlatching has more
The possible situation of kind: the flow that for example can be system reaches the threshold value of backstage default triggering current limliting;It can also be manually on backstage
Configuration triggering current limliting strategy.Request is normally handled by normal processing logic if not starting to.If it find that opening limit
Request to be processed is then first stored in database by stream switch, then will be in the priority query Zset of solicited message write-in Redis
The precedence information in face, request is read from the priority configuration of backstage configuration.Optionally, request originator can also be returned to
Relevant information of the request to be processed in process processed.Optionally, it can also be generated for each request to be processed global
Unique distribution order number can also be sent out after the completion of the request to be processed is processed for request originator query processing progress
The solicited message of the message informing request originator order number is sent to be disposed.Wherein, it is completed for processing to be processed
Request, can also update the processing status of the request in the database.
As shown in Figure 2 D, each node in distributed system all configures the timed task of certain period of time triggering
(such as how many minute/how many second etc. can configure according to business demand).According to the timed task, node can be according to setting week
Phase judges whether itself is Master node, then without any processing if not Master node, if it is Master node
Then take solicited message inside the priority query of Redis, (how many points of quantity from the current limliting of backstage configuration of the quantity of selection
Clock/current limlitings how many number of request such as how many seconds), if taking solicited message to be abnormal inside Redis, from database the inside
Choose request to be processed.
For a plurality of request to be processed of selection, each node that can be distributed to by host node in cluster is handled,
Each node can configure a request processing flow, and when node receives the request to be processed of distribution, then trigger request is handled
Process starts business logic processing, the processing status of current solicited message order number related data can be updated after the completion of processing,
The request originator request can also be sent messages to be disposed.
The present embodiment is different from traditional single machine list example current limliting scheme, goes out from completely new distributed system current limliting angle
Hair carries out current limliting detection in real time, had both supported automatic trigger current limliting or had supported artificial triggering current limliting, and specific current limliting number can also be with
Dynamic configuration is carried out by backstage, and for the persistence of solicited message other than supporting to choose inside priority query,
There are also the data of revealing all the details of database to support, and has ensured the stability of request data.
For request originator, current limliting strategy is transparent unaware to request originator, request hair before and after current limliting
Processing status can be requested by the order number active inquiry once requested by playing side, also be notified that client after the completion of request processing
End request disposition.For the loading condition of distributed system, Master node is to support election (Zookeeper
Master election mechanism), even if Master node is hung, other nodes can also become again Master section by election mechanism
Point;And the distribution of task is also load balancing, other nodes by load balancing being distributed in cluster.
The present embodiment carries out current limliting detection from completely new distributed system current limliting angle in real time, and dynamic opens limit
Flow Policy, request to be processed can be handled by consumption to each node load balancing in systems.
The current limliting scheme of the present embodiment is entirely transparent, client before and after unlatching current limliting strategy for request originator
End is unaware, is not born for request originator, does not need to do any additional processing.
In the present embodiment, the current limliting number of one side system can be by the configuration dynamic expansion of background system, another aspect,
The number of nodes that request is handled in system can also dynamically increase, and only need to extend application distribution formula, because one
The distributed system node of extension is both the alternate node and child node of Master node, can be the processing of request message
It reduces processing pressure and achievees the purpose that the protection system of current limliting to alleviate the pressure of entire distributed system cluster.
In the present embodiment, the Master node in one side system can be elected by remaining node and be obtained after hanging;
On the other hand after some child nodes hang, influence to whole system will not be especially big, and the flow of whole system still can be with
Load balancing it is distributed to other child nodes.
As shown in figure 3, being the current limliting side of this specification another distributed system shown according to an exemplary embodiment
The flow chart of method, this method can be applied to any node in distributed system, which comprises
In step 302, after determining that current limliting is triggered, the request to be processed that load balancer is distributed is intercepted to message
It manages in queue;
In step 304, determine it itself is host node either child node;
Within step 306, if host node, after the request to be processed that setting quantity is chosen in the Message Processing queue,
The request to be processed of selection is distributed at least one described node;
In step 308, if child node, then after the request for receiving host node distribution, request processing flow is executed.
Optionally, the host node chooses the request to be processed from the Message Processing queue according to the setting period.
Optionally, the host node is elected to obtain by all nodes by election mechanism.
Optionally, the determining current limliting is triggered, comprising: and the quantity of request to be processed reaches setting current limit threshold, or
It is to receive setting current limliting instruction.
Optionally, the method also includes: by load balancer send request to be processed back up in database.
Optionally, the method also includes: for processing complete request to be processed, update the request in the database
Processing status.
Optionally, the method also includes: if the Message Processing queue is operating abnormally, the host node is from the data
Request to be processed is chosen in library.
Optionally, the host node is to choose setting the to be processed of quantity from the Message Processing queue according to priority to ask
It asks.
The current limliting scheme of the present embodiment is the angle of each node from distributed system to describe, specific process flow
It can refer to the description of Fig. 2A to Fig. 2 D illustrated embodiment, details are not described herein.
Corresponding with the embodiment of the current-limiting method of aforementioned distributed system, this specification additionally provides distributed system
The embodiment of current-limiting apparatus and its applied terminal.
The embodiment of the current-limiting apparatus of this specification distributed system can be applied on a computing device, such as server
Or terminal device.Installation practice can also be realized by software realization by way of hardware or software and hardware combining.
Taking software implementation as an example, as the device on a logical meaning, being will be non-volatile by the processor of file process where it
Property memory in corresponding computer program instructions be read into memory operation formed.For hardware view, such as Fig. 4 institute
Show, is a kind of hardware structure diagram of computer equipment where the current-limiting apparatus of this specification distributed system, in addition to shown in Fig. 4
Except processor 410, memory 430, network interface 420 and nonvolatile memory 440, in embodiment where device 431
Server or electronic equipment can also include other hardware generally according to the actual functional capability of the computer equipment, no longer superfluous to this
It states.
As shown in figure 5, Fig. 5 is a kind of this specification block diagram of device shown according to an exemplary embodiment, the dress
It sets and includes:
Blocking module 51, is used for: after determining that current limliting is triggered, the request to be processed that load balancer is distributed being intercepted to disappearing
In breath processing queue;
Determining module 52, is used for: determining it itself is host node either child node;
Distribution module 53, is used for: if host node, the request to be processed of setting quantity is chosen from the Message Processing queue
Afterwards, the request to be processed of selection is distributed at least one described node;
Processing module 54, is used for: if child node, then after the request for receiving host node distribution, executing request processing stream
Journey.
Optionally, the host node chooses the request to be processed from the Message Processing queue according to the setting period.
Optionally, the host node is elected to obtain by all nodes by election mechanism.
Optionally, the blocking module, is also used to: the quantity of request to be processed reaches setting current limit threshold, or connects
Receive setting current limliting instruction.
Optionally, described device further includes backup module, is used for: by load balancer send request to be processed backup in
In database.
Optionally, the method also includes: for processing complete request to be processed, update the request in the database
Processing status.
Optionally, the distribution module is also used to: if the Message Processing queue is operating abnormally, the host node is from described
Request to be processed is chosen in database.
Optionally, the host node is to choose setting the to be processed of quantity from the Message Processing queue according to priority to ask
It asks.
Correspondingly, this specification also provides a kind of computer equipment, including memory, processor and storage are on a memory
And the computer program that can be run on a processor, wherein the processor realizes aforementioned distributed system when executing described program
The current-limiting method of system.
The function of modules and the realization process of effect are specifically detailed in above-mentioned in the current-limiting apparatus of above-mentioned distributed system
The realization process of step is corresponded in the current-limiting method of distributed system, details are not described herein.
For device embodiment, since it corresponds essentially to embodiment of the method, so related place is referring to method reality
Apply the part explanation of example.The apparatus embodiments described above are merely exemplary, wherein described be used as separation unit
The module of explanation may or may not be physically separated, and the component shown as module can be or can also be with
It is not physical module, it can it is in one place, or may be distributed on multiple network modules.It can be according to actual
The purpose for needing to select some or all of the modules therein to realize this specification scheme.Those of ordinary skill in the art are not
In the case where making the creative labor, it can understand and implement.
It is above-mentioned that this specification specific embodiment is described.Other embodiments are in the scope of the appended claims
It is interior.In some cases, the movement recorded in detail in the claims or step can be come according to the sequence being different from embodiment
It executes and desired result still may be implemented.In addition, process depicted in the drawing not necessarily require show it is specific suitable
Sequence or consecutive order are just able to achieve desired result.In some embodiments, multitasking and parallel processing be also can
With or may be advantageous.
Those skilled in the art will readily occur to this specification after considering specification and practicing the invention applied here
Other embodiments.This specification is intended to cover any variations, uses, or adaptations of this specification, these modifications,
Purposes or adaptive change follow the general principle of this specification and do not apply in the art including this specification
Common knowledge or conventional techniques.The description and examples are only to be considered as illustrative, the true scope of this specification and
Spirit is indicated by the following claims.
It should be understood that this specification is not limited to the precise structure that has been described above and shown in the drawings,
And various modifications and changes may be made without departing from the scope thereof.The range of this specification is only limited by the attached claims
System.
The foregoing is merely the preferred embodiments of this specification, all in this explanation not to limit this specification
Within the spirit and principle of book, any modification, equivalent substitution, improvement and etc. done should be included in the model of this specification protection
Within enclosing.