Summary of the invention
In view of this, this specification provides a kind of control method of batch processing rate, it is applied to token management person, the side
Method includes:
Several tokens for being used for predetermined period are generated according to current limliting parameter;The token is used to refer to the producer can be to
The task the upper limit of the number of consumer's distribution;
After the token request for receiving the producer in some predetermined period, if the token of the predetermined period is not yet provided
It finishes, provides token to the producer.
A kind of control method for batch processing rate that this specification provides is applied to the producer, the method includes:
Token request is sent to token management person;
After the token that the person that receives token management provides, obtain batch processing task and be simultaneously distributed to consumer, the acquisition or
The quantity of the batch processing task of distribution is no more than the task the upper limit of the number of token instruction.
This specification additionally provides a kind of control device of batch processing rate, is applied to token management person, described device packet
It includes:
Token generation unit, for generating several tokens for being used for predetermined period according to current limliting parameter;The token is used
To indicate that the producer can be to the task the upper limit of the number of consumer's distribution;
Token issuing unit, after the token for receiving the producer in some predetermined period is requested, if described predetermined
The token in period is not yet provided and is finished, and provides token to the producer.
A kind of control device for batch processing rate that this specification provides, is applied to the producer, and described device includes:
Token request unit, for sending token request to token management person;
Token uses unit, is simultaneously distributed to for after the token that the person that receives token management provides, obtaining batch processing task
The quantity of the batch processing task of consumer, the acquisition or distribution is no more than the task the upper limit of the number of token instruction.
A kind of computer equipment that this specification provides, including:Memory and processor;Being stored on the memory can
The computer program run by processor;When the processor runs the computer program, execute above-mentioned applied to token pipe
Step described in the control method of the batch processing rate of reason person.
A kind of computer equipment that this specification provides, including:Memory and processor;Being stored on the memory can
The computer program run by processor;When the processor runs the computer program, execute above-mentioned applied to the producer
Batch processing rate control method described in step.
A kind of computer readable storage medium that this specification provides, is stored thereon with computer program, the computer
When program is run by processor, step described in the control method of the above-mentioned batch processing rate applied to token management person is executed.
This specification additionally provides a kind of computer readable storage medium, is stored thereon with computer program, the calculating
When machine program is run by processor, step described in the above-mentioned control method applied to the batch processing rate of the producer is executed.
By above technical scheme as it can be seen that in the embodiment of this specification, token in predetermined period is determined according to current limliting parameter
The token that manager can provide, by token management, person is issued to the producer in predetermined period, receives the producer of token
It can be according to the task the upper limit of the number that token indicates to consumer's distributed tasks, so as to batch processing rate under concurrent framework
It controls more accurate.
Specific embodiment
The embodiment of this specification proposes a kind of control method of new batch processing rate, producers and consumers' and
It sends out and increases token management person in framework, the token for being used for predetermined period is generated according to current limliting parameter by token management person, at one
Token management person can only provide the token for being used for the predetermined period to the producer in predetermined period, and only receive the production of token
Person could be according to the task the upper limit of the number that token indicates to consumer's distributed tasks, to realize to the accurate of batch processing rate
Control.
Producer consumer mode is a kind of widely used concurrent processing framework.In the embodiment of this specification, in life
Increase token management person in the framework of production person and consumer's mode, as shown in Figure 1.Wherein, token management person, the producer or consumption
Person is functional module, can be class, function, thread, process, application program etc.;The producer is responsible for that batch processing will be carried out
Buffer area is written in task, and consumer is responsible for reading task from buffer area and executes the processing to the task.
In the embodiment of this specification, token management person, producers or consumers may operate in it is any have calculate and
In the equipment of storage capacity, such as mobile phone, tablet computer, PC (Personal Computer, PC), notebook, server
Etc. equipment;The items in this specification embodiment can also be realized by operating in the logical node of two or more equipment
Function.In addition, token management person, producers or consumers can be separately operable on different physical equipments or logical node,
Two sides or tripartite therein also may operate on the same physical equipment or logical node (such as token management person can and some
The producer operates on the same physical equipment), without limitation.
In the embodiment of this specification, the control method of batch processing rate is applied to process such as Fig. 2 institute of token management person
Show, the process applied to the producer is as shown in Figure 3.
In one side of token management person, step 210, the token for being used for predetermined period is generated according to current limliting parameter.
Current limliting parameter is the parameter for describing batch processing rate-limit, can be appointed according to batch processing in practical application scene
The specific implementation etc. of the type of business, producers or consumers is because of the usually determination design parameter to be used.For example, current limliting parameter can
To be the parameters such as handling capacity (Throughput), QPS (Query Per Second, query rate per second).
Predetermined period is the minimum time unit for carrying out batch processing rate control.The total batch processing flow of one predetermined period
It is to be controlled according to current limliting parameter, the batch processing rate of some moment could possibly be higher than corresponding to current limliting parameter in predetermined period
Rate.Predetermined period can be determined to the ability to bear of moment batch processing rate according in practical application scene, make a reservation for week
Phase is smaller, and the variation of batch processing spot speed is more steady.
Token management person can obtain current limliting parameter in a predetermined manner.For example, can be from pre- in configuration information
Determine storage location acquisition, can easily change current limliting parameter by modifying configuration information in this way.Configuration information can be stored in
Token management person is local, can also be obtained by token management person by network.
Current limliting parameter can be arranged according to the period, that is, several predetermined amount of time are arranged, and each predetermined amount of time has
Corresponding current limliting parameter.The current limliting parameter of different predetermined amount of time may be the same or different.For example, when operation batch
When the system of processing task is also used to complete other tasks, the rush hour section of other tasks can be regard as a predetermined time
Section, is arranged the current limliting parameter of slow rate;Using the low ebb period of other tasks as another predetermined amount of time, setting is very fast
The current limliting parameter of rate.For another example, as a predetermined amount of time, this can be made a reservation for without the period of batch processing task
It is 0 that the current limliting parameter of period, which is set as rate,.It should be noted that each predetermined amount of time includes at least a predetermined week
Phase.
Token management person generates several tokens for being used for predetermined period according to current limliting parameter.Token is used to refer to produce
The task the upper limit of the number that person can distribute to consumer.Specifically, token management person will meet current limliting parameter in predetermined period
Under conditions of the maximum task total amount that is capable of handling give several tokens, each token has in a determining task quantity
Limit, the summation of the task the upper limit of the number of all tokens are no more than above-mentioned maximum task total amount.
Can arrange task the upper limit of the number indicated by each token is a fixed value;Can also carry in token should
The task the upper limit of the number of token, task the upper limit of the number indicated by difference tokens can be different in this way.The concrete form of token is joined
It realizes, repeats no more according to the prior art.
In one side of the producer, step 310, token request is sent to token management person.
After producer's starting, before task to be processed is written to buffer area, token is sent to token management person and is asked
It asks.When the task the upper limit of the number that the producer has used a upper token to indicate, continuing that task to be processed is written to buffer area
Before, token request is sent to token management person.
In one side of token management person, step 220, after the token request that the producer is received in some predetermined period, if
The token of the predetermined period is not yet provided and is finished, and provides token to the producer.
After token manager receives the token request of the producer in some predetermined period, token management person inquiry is used for
Whether the token of the predetermined period has residue, finishes if token is not yet provided, and provides token to the producer, and will send out
The token put is reduced from the remaining token of the predetermined period.Token management person once can provide one to a producer
To multiple tokens, without limitation.
If the token granting of the predetermined period finishes, token management person can be not responding to the token request of the producer;?
The token request without available tokens, or the refusal producer can be replied to the producer.
When some predetermined period then, finished if the token of the predetermined period is not yet provided, according to practical application scene
Needs, can enable the predetermined period not yet provide finish token failure, to ensure the limitation to batch processing rate;It can also be with
The predetermined period is not yet provided the token finished to be added in the token that next predetermined period can be provided, to criticizing
The completion total amount of reason task provides more ensure.
In the producer, step 320, after the token that the person that receives token management provides, obtains batch processing task and be simultaneously distributed to
Consumer, obtains or the quantity of the batch processing task of distribution is no more than the task the upper limit of the number that the token indicates.
The token that person returns if the producer for sending token request to token management person receives token management, the producer
The batch processing task for being no more than the task the upper limit of the number can be obtained, is led to according to the task the upper limit of the number of the token instruction received
It crosses write-in buffer area and is distributed to consumer and handle;The producer can also will not surpass after obtaining several batch processing tasks
The batch processing task for crossing the task the upper limit of the number of the token instruction received is distributed to consumer by write-in buffer area and handles.
The task that the producer completes task the upper limit of the number obtain and distribution after, even if after being finished the token received, can be with
Again token request is sent to token management person, application continues next token of batch processing work.
The token that person provides if the producer does not receive token management, the producer suspend distribution batch processing task
Work can send token request to token management person again after waiting scheduled delay.Scheduled delay can join
Predetermined period is examined to be arranged.The situation for not receiving the token of granting may include that the producer does not have after a certain period of time in waiting
Receive the response to token request, the response for receiving no available tokens or response of refusal token request etc..
Producer's acquisition batch processing task, the concrete mode for distributing batch processing task can be according to the realities of practical application scene
It is existing, it is realized with reference to the prior art, without limitation.For example, delay queue can be put it into the delayed tasks in database
In, being delayed in queue for task could be removed from queue upon expiration, and the producer can extract from delay queue and expire
Delayed tasks.
Consumer obtains batch processing task from buffer area, is carried out according to the business demand in practical application scene to task
Processing.Consumer obtains and the concrete mode of processing task can refer to prior art realization, repeats no more.
As it can be seen that increasing token management person, root in the concurrent framework of producers and consumers in the embodiment of this specification
The token that token management person can provide in predetermined period is determined according to current limliting parameter, is provided in predetermined period by token management person
To the producer, and the producer for only receiving token could appoint according to the task the upper limit of the number that token indicates to consumer's distribution
Business, realizes and is precisely controlled under concurrent framework to batch processing rate.
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.
In an application example of this specification, Internet Service Provider is to overdue delay in delayed tasks database
Task carries out batch processing, some the business interface limited throughput for needing to call when due to batch processing needs the speed to batch processing
Rate is limited.The structure of the batch processing system of the Internet Service Provider is as shown in Figure 4.
The delayed tasks in need for carrying out batch processing are saved in delayed tasks database.Delayed tasks can pass through two kinds of sides
Formula imports in delayed tasks database, one is being introduced directly into delayed tasks database from offline database, another kind be by
The interface that the application of the Internet Service Provider is provided by delayed tasks database is written online.
The queue database that is delayed provides the view of delay queue, after the delayed tasks being delayed in queue expire, the producer
The delayed tasks having expired can be obtained from delay queue.
Configuring maintenance functional module provides interface to add the configuration information of batch processing task, and saves matching of being provided with
Confidence breath.It include current limliting parameter in configuration information, the current limliting parameter used in this application example is QPS.
Token management person reads current limliting parameter QPS from configuring maintenance functional module, and the order of predetermined period is generated based on QPS
Board.If predetermined period is 1 second, the task the upper limit of the number that each token represents is N (N is natural number), and token management person is according to QPS
The token sum that a predetermined period can be provided can be obtained, be set as M (M is natural number).
Some producer sends token request to token management person in some predetermined period.Token management person inquiry is used for
The remaining token quantity of the predetermined period then provides 1 token to the producer, and will be used for the predetermined period if it is greater than 0
Remaining token quantity subtract 1.It is finished if the M token for the predetermined period has been provided, refuses the order of the producer
Board request.
After the token that the producer person that receives token management provides, overdue delayed tasks are extracted from delay queue,
Write-in buffer area is distributed to consumer.After the acquisition and distribution for completing N number of delayed tasks, which sends out to token management person
New token is sent to request, application continues next token of batch processing.
After the producer person that receives token management refuses the response of token request, scheduled delay is waited (to be set as 0.5
Second), token request is sent to token management person again.
Consumer reads overdue delayed tasks from buffer area, and the interface for calling business realizing functional module to provide is to arriving
The delayed tasks of phase carry out business processing, complete batch-processing work.
It is corresponding with the realization of above-mentioned process, the embodiment of this specification additionally provide it is a kind of applied to token management person batch at
Manage the control device and a kind of control device of the batch processing rate applied to the producer of rate.Both devices can lead to
Software realization is crossed, can also be realized by way of hardware or software and hardware combining.Taking software implementation as an example, as logical meaning
On device, be by the CPU (Central Process Unit, central processing unit) of place equipment by corresponding computer journey
Sequence instruction is read into memory what operation was formed.For hardware view, in addition to CPU shown in fig. 5, memory and memory it
Outside, the equipment where the control device of batch processing rate also typically includes chip for carrying out wireless signal transmitting-receiving etc. other is hard
Part, and/or for realizing other hardware such as board of network communicating function.
Fig. 6 show a kind of control device of batch processing rate of this specification embodiment offer, is applied to token management
Person, described device include token generation unit and token issuing unit, wherein:Token generation unit is used for raw according to current limliting parameter
At several tokens for predetermined period;The token is used to refer in the task quantity that the producer can distribute to consumer
Limit;After token issuing unit is used to receive the token request of the producer in some predetermined period, if the predetermined period
Token is not yet provided and is finished, and provides token to the producer.
Optionally, described device further includes configuration acquiring unit, for obtaining current limliting parameter from configuration information.
Optionally, the current limliting parameter includes:In the current limliting parameter of several predetermined amount of time, the predetermined amount of time packet
Include at least one predetermined period.
Optionally, the current limliting parameter includes:Query rate QPS per second.
Optionally, described device further includes token disabling unit, for predetermined period then, the order not yet provided of failing
Board.
Fig. 7 show a kind of control device of batch processing rate of this specification embodiment offer, is applied to the producer, institute
Stating device includes token request unit and token using unit, wherein:Token request unit is used to send to token management person and enable
Board request;Token is used for after the token that the person that receives token management provides using unit, is obtained batch processing task and is distributed to and disappears
The quantity of the batch processing task of Fei Zhe, the acquisition or distribution is no more than the task the upper limit of the number of token instruction.
Optionally, described device further includes:Waiting retries unit, for waiting scheduled when not receiving the token of granting
Token request is sent to token management person after delay time.
Optionally, the token includes using unit acquisition batch processing task:It is obtained from database based on delay queue
Overdue delayed tasks.
The embodiment of this specification provides a kind of computer equipment, which includes memory and processor.
Wherein, the computer program that can be run by processor is stored on memory;Computer program of the processor in operation storage
When, execute each step for being applied to the control method of batch processing rate of token management person in this specification embodiment.It is corresponding
The detailed description of each step of the control method of batch processing rate for token management person refer to before content, no longer
It repeats.
The embodiment of this specification provides a kind of computer equipment, which includes memory and processor.
Wherein, the computer program that can be run by processor is stored on memory;Computer program of the processor in operation storage
When, execute each step for being applied to the control method of batch processing rate of the producer in this specification embodiment.To being applied to
The detailed description of each step of the control method of the batch processing rate of the producer refer to before content, be not repeated.
The embodiment of this specification provides a kind of computer readable storage medium, is stored with computer on the storage medium
Program, these computer programs execute batch for being applied to token management person in this specification embodiment when being run by processor
Each step of the control method of processing speed.To each step of the control method for the batch processing rate for being applied to token management person
Rapid detailed description refer to before content, be not repeated.
The embodiment of this specification provides a kind of computer readable storage medium, is stored with computer on the storage medium
Program, these computer programs execute the batch processing for being applied to the producer in this specification embodiment when being run by processor
Each step of the control method of rate.To be applied to the producer batch processing rate control method each step it is detailed
Content before describing to refer to, is not repeated.
The foregoing is merely the preferred embodiments of this specification, all the application's not to limit the application
Within spirit and principle, any modification, equivalent substitution, improvement and etc. done be should be included within the scope of the application protection.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net
Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or
The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium
Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves
State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable
Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM),
Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or other magnetic storage devices
Or any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, it calculates
Machine readable medium does not include temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
It should also be noted that, the terms "include", "comprise" or its any other variant are intended to nonexcludability
It include so that the process, method, commodity or the equipment that include a series of elements not only include those elements, but also to wrap
Include other elements that are not explicitly listed, or further include for this process, method, commodity or equipment intrinsic want
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including described want
There is also other identical elements in the process, method of element, commodity or equipment.
It will be understood by those skilled in the art that the embodiment of this specification can provide as the production of method, system or computer program
Product.Therefore, the embodiment of this specification can be used complete hardware embodiment, complete software embodiment or combine software and hardware side
The form of the embodiment in face.Moreover, it wherein includes that computer is available that the embodiment of this specification, which can be used in one or more,
It is real in the computer-usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) of program code
The form for the computer program product applied.