CN113760365A - Token fetching operation execution method, device, electronic equipment and computer readable medium - Google Patents

Token fetching operation execution method, device, electronic equipment and computer readable medium Download PDF

Info

Publication number
CN113760365A
CN113760365A CN202110121819.3A CN202110121819A CN113760365A CN 113760365 A CN113760365 A CN 113760365A CN 202110121819 A CN202110121819 A CN 202110121819A CN 113760365 A CN113760365 A CN 113760365A
Authority
CN
China
Prior art keywords
token
tokens
determining
request
consumption
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.)
Pending
Application number
CN202110121819.3A
Other languages
Chinese (zh)
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 Tuoxian Technology Co Ltd
Original Assignee
Beijing Jingdong Tuoxian 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 Tuoxian Technology Co Ltd filed Critical Beijing Jingdong Tuoxian Technology Co Ltd
Priority to CN202110121819.3A priority Critical patent/CN113760365A/en
Publication of CN113760365A publication Critical patent/CN113760365A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5021Priority

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the disclosure discloses a token fetching operation execution method, a token fetching operation execution device, electronic equipment and a computer readable medium. One embodiment of the method comprises: in response to receiving the request, determining an accumulated token number according to the remaining token number, the token generation speed and the time of the last token fetching operation; in response to determining that the accumulated token number is greater than zero, determining a consumption token number required for executing the business operation corresponding to the request; in response to determining that the accumulated number of tokens is less than the consumed number of tokens and that the request has priority, determining a number of pre-consumed tokens required to perform the business operation; and in response to the fact that the difference value between the accumulated token number and the pre-consumption token number meets a preset condition, updating the numerical value of the residual token number and the time of the last token fetching operation and executing the token fetching operation. The embodiment realizes the stability of the system and the usability of the system.

Description

Token fetching operation execution method, device, electronic equipment and computer readable medium
Technical Field
The embodiment of the disclosure relates to the technical field of computers, in particular to a token fetching operation execution method, a token fetching operation execution device, electronic equipment and a computer readable medium.
Background
The token fetching operation is an operation of fetching tokens from the token bucket according to the number of tokens required by the request and the number of tokens remaining in the token bucket. At present, when a token fetching operation is performed, the following method is generally adopted: and if the number of tokens required by the request is less than that of the tokens in the token bucket, taking out the tokens from the token bucket and executing the business operation corresponding to the request. Otherwise, the request is rejected.
However, when the token fetching operation is performed in the above manner, there are often the following technical problems:
when the number of tokens in the token bucket is less than the number of tokens required by the request, the request is directly rejected, and the service capability of the system is difficult to be considered while the stability of the system is ensured.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
Some embodiments of the present disclosure propose a token fetching operation execution method, apparatus, electronic device and computer readable medium to solve one or more of the technical problems mentioned in the background section above.
In a first aspect, some embodiments of the present disclosure provide a token fetching operation execution method, including: in response to receiving the request, determining an accumulated token number according to the remaining token number, the token generation speed and the time of the last token fetching operation; in response to determining that the accumulated token number is greater than zero, determining a consumption token number required for executing the business operation corresponding to the request; in response to determining that the accumulated number of tokens is less than the consumed number of tokens and that the request has priority, determining a number of pre-consumed tokens required to perform the business operation; and in response to the fact that the difference value between the accumulated token number and the pre-consumption token number meets a preset condition, updating the numerical value of the residual token number and the time of the last token fetching operation and executing the token fetching operation.
Optionally, the determining the number of consumption tokens required for executing the service operation corresponding to the request includes: and determining the consumption token number according to the average consumption rate corresponding to the request and the token generation speed.
Optionally, the determining the number of pre-consumption tokens required for executing the service operation includes: and determining the number of the pre-consumption tokens according to the number of the consumption tokens and the priority.
Optionally, the updating the value of the remaining number of tokens and the time of the last token fetching operation includes: updating the value of the accumulated token count to the bucket capacity value in response to determining that the accumulated token count is greater than the bucket capacity value of the token bucket corresponding to the request; updating the value of the residual token number to the difference value between the accumulated token number and the pre-consumption token number; and updating the time of last token fetching operation to the time of receiving the request.
Optionally, the executing the token fetching operation includes: and updating the number of tokens in the token bucket to zero in response to determining that the number of remaining tokens is less than zero.
Optionally, the executing the token fetching operation further includes: and updating the token number in the token bucket to the residual token number in response to determining that the residual token number is greater than or equal to zero.
Optionally, the method further includes: and executing the business operation corresponding to the request.
In a second aspect, some embodiments of the present disclosure provide a token fetching operation execution apparatus, including: a first determination unit configured to determine, in response to receiving the request, an accumulated token number according to the remaining token number, the token generation speed, and a time at which the token fetching operation was performed last time; a second determining unit configured to determine, in response to determining that the accumulated token number is greater than zero, a consumption token number required to perform a business operation corresponding to the request; a third determining unit configured to determine a number of pre-consumed tokens required to perform the business operation in response to determining that the accumulated token number is less than the consumed token number and that the request has a priority; and the updating and executing unit is configured to update the value of the residual token number and the time of the last token fetching operation and execute the token fetching operation in response to the fact that the difference value between the accumulated token number and the pre-consumption token number meets the preset condition.
Optionally, the second determining unit of the token fetching operation executing apparatus is further configured to: and in response to determining that the accumulated token number is greater than zero, determining the consumption token number according to the average consumption rate corresponding to the request and the token generation speed.
Optionally, the third determining unit of the token fetching operation executing apparatus is further configured to: in response to determining that the accumulated number of tokens is less than the consumed number of tokens and that the request has a priority, determining the pre-consumed number of tokens based on the consumed number of tokens and the priority.
Optionally, the update and execution unit of the token fetching operation execution device is further configured to: updating the value of the accumulated token count to the bucket capacity value in response to determining that the accumulated token count is greater than the bucket capacity value of the token bucket corresponding to the request; updating the value of the residual token number to the difference value between the accumulated token number and the pre-consumption token number; and updating the time of last token fetching operation to the time of receiving the request.
Optionally, the update and execution unit of the token fetching operation execution device is further configured to: and updating the number of tokens in the token bucket to zero in response to determining that the number of remaining tokens is less than zero.
Optionally, the update and execution unit of the token fetching operation execution device is further configured to: and updating the token number in the token bucket to the residual token number in response to determining that the residual token number is greater than or equal to zero.
Optionally, the token fetching operation executing apparatus further includes a service operation executing unit. The service operation execution unit is configured to execute the service operation corresponding to the request.
In a third aspect, some embodiments of the present disclosure provide an electronic device, comprising: one or more processors; a storage device having one or more programs stored thereon, which when executed by one or more processors, cause the one or more processors to implement the method described in any of the implementations of the first aspect.
In a fourth aspect, some embodiments of the present disclosure provide a computer readable medium on which a computer program is stored, wherein the program, when executed by a processor, implements the method described in any of the implementations of the first aspect.
The above embodiments of the present disclosure have the following advantages: by the token fetching operation execution method of some embodiments of the present disclosure, the system service capability can be improved on the premise of ensuring the system stability. Specifically, the reason why it is difficult to compromise the service capability of the system while ensuring the stability of the system is that: when the number of tokens in the token bucket is less than the number of tokens required for the request, the request is directly denied in order to ensure system stability. Based on this, the token fetching operation execution method of some embodiments of the present disclosure does not directly reject the request when the accumulated token number is less than the consumption token number required by the request. But the number of the pre-consumption tokens is determined according to the priority of the request, and the token fetching operation is executed according to the number of the pre-consumption tokens, so that the request with the priority obtains the tokens according to the number of the pre-consumption tokens to be executed. Therefore, the stability of the system is ensured, and the service capability of the system is considered.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and elements are not necessarily drawn to scale.
FIG. 1 is a schematic diagram of one application scenario of a token fetch operation execution method of some embodiments of the present disclosure;
FIG. 2 is a flow diagram of some embodiments of a method of token fetch execution according to the present disclosure;
FIG. 3 is a schematic illustration of cumulative token count updates in some embodiments of a method of token fetch execution according to the present disclosure;
FIG. 4 is a flow diagram of further embodiments of a method of performing a token fetch operation according to the present disclosure;
FIG. 5 is a schematic block diagram of some embodiments of a token fetch operation performing apparatus according to the present disclosure;
FIG. 6 is a schematic structural diagram of an electronic device suitable for use in implementing some embodiments of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings. The embodiments and features of the embodiments in the present disclosure may be combined with each other without conflict.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Fig. 1 is a schematic diagram of an application scenario of a target data transmission method according to some embodiments of the present disclosure.
In the application scenario of fig. 1, first, the computing device 101 may determine, in response to receiving the request 102, a cumulative token count 106 from the remaining token count 103, the token generation speed 104, and the time 105 of the last execution of the token fetching operation. The computing device 101 may then determine a number of consumption tokens 107 required to perform the business operation corresponding to the request 102 in response to determining that the cumulative number of tokens 106 is greater than zero. The computing device 101 may then determine a number of pre-consumed tokens 108 required to perform the business operation in response to determining that the cumulative number of tokens 106 is less than the number of consumed tokens 107 and that the request 102 has priority. Finally, the computing device 101 may update the value of the remaining token count 103 and the time 105 of the last token fetching operation and execute the token fetching operation in response to determining that the difference between the accumulated token count 106 and the pre-consumed token count 108 satisfies a preset condition.
The computing device 101 may be hardware or software. When the computing device is hardware, it may be implemented as a distributed cluster composed of multiple servers or terminal devices, or may be implemented as a single server or a single terminal device. When the computing device is embodied as software, it may be installed in the hardware devices enumerated above. It may be implemented, for example, as multiple software or software modules to provide distributed services, or as a single software or software module. And is not particularly limited herein.
It should be understood that the number of computing devices in FIG. 1 is merely illustrative. There may be any number of computing devices, as implementation needs dictate.
With continued reference to fig. 2, a flow 200 of some embodiments of a method of token fetch execution is shown in accordance with the present disclosure. The token fetching operation execution method comprises the following steps:
step 201, in response to receiving the request, determining the accumulated token number according to the remaining token number, the token generation speed and the time of last execution of the token fetching operation.
In some embodiments, an executing agent (such as the computing device shown in fig. 1) of the token fetching operation executing method may determine, in response to receiving the request, a cumulative token count according to the remaining token count, the token generation speed, and the time to execute the token fetching operation by the following formula. The request may be a different category of service request (e.g., a request for quote, a request for item search, etc.). The remaining number of tokens may be the number of tokens remaining after the last token fetching operation. If the token fetching operation is not performed before the request is received, the remaining number of tokens may be set to zero. The token generation speed may be a generation speed of tokens in a token bucket corresponding to the request. The token bucket may be a token bucket for a certain type of request or a token bucket for all types of requests. The time of last execution of the token fetching operation may be the time of last request reception. If no token is obtained from the token bucket before the request is received, the time of the last token fetching operation may be set as the creation time of the token bucket.
cur_permits=last_permits+(cur_time-last_time)×V0
Wherein cur _ limits represents the above-mentioned cumulative token number. last _ limits represents the number of tokens remaining above. last _ time represents the time the last token fetch operation was performed as described above. cur _ time represents the time at which the request was received. V denotes the token generation speed.
As an example, the above-mentioned remaining token number may be 1. The token generation speed may be 2/sec. The time of last execution of the token fetching operation may be 20 minutes and 46 seconds at 14 o' clock at 1 month and 13 months in 2021. The time for receiving the request may be 14 o' clock 40 min 56 sec at 1/13/2021. The above-mentioned cumulative token number may be 21.
Step 202, in response to determining that the accumulated token number is greater than zero, determining a consumption token number required for executing the business operation corresponding to the request.
In some embodiments, in response to determining that the accumulated token number is greater than zero, the execution main body may determine, according to the category information corresponding to the request, a consumption token number required for executing the service operation corresponding to the request. In this way, the consumption token numbers corresponding to different types of requests can be preset, and the corresponding relationship between the types and the consumption token numbers can be recorded in advance. The correspondence may be recorded by way of a binary set. The binary may include category information and a consumption token count.
By way of example, the category to which the request corresponds may be "quote," "search," or the like. The binary groups corresponding to the categories "offer" and "search" may be [ "offer", 3], [ "search", 5], respectively.
Optionally, the executing body may further terminate the execution of the subsequent step in response to determining that the number of the accumulated tokens is less than or equal to zero, and send a prompt message requesting execution failure to the terminal device that sent the request.
As an example, the above-mentioned hint message may be "network congestion, please retry later".
In the above implementation, when the accumulated token number is less than or equal to zero, it may indicate that there is not enough tokens currently available for the executing agent to service the received request. Therefore, the purpose of ensuring the stability of the system is achieved by terminating the execution of the subsequent steps.
Step 203, in response to determining that the cumulative number of tokens is less than the number of consumption tokens and that the request has priority, determining a number of pre-consumption tokens required to perform the business operation.
In some embodiments, the executing agent may determine a number of pre-consumed tokens required to perform the business operation in response to determining that the accumulated number of tokens is less than the consumed number of tokens and that the request has priority. The priority may be set in advance according to the category of the request. The priority may be expressed numerically. The larger the numerical value of the number, the higher the priority. The correspondence between the category of the request having priority and the priority may be pre-recorded by the binary. So that it can be determined whether the request has priority through the duplet. The number of tokens to be consumed in advance may be the number of tokens to be pre-allocated for the execution of the request when the accumulated number of tokens does not satisfy the number of tokens to be consumed for the execution of the request.
Optionally, the executing body may further terminate the execution of the subsequent step in response to determining that the accumulated token number is smaller than the consumption token number and that the request does not have priority, and send a prompt message requesting that the execution fails to the terminal device that sent the request.
In the above implementation, when the request does not have priority, it may be indicated that the request is of low importance. Therefore, the request can be directly rejected under the condition that the number of tokens is insufficient, and the frequency of the request is controlled, so that the aim of ensuring the stability of the system is fulfilled.
And step 204, in response to the fact that the difference value between the accumulated token number and the pre-consumption token number meets the preset condition, updating the numerical value of the residual token number and the time of the last token fetching operation and executing the token fetching operation.
In some embodiments, the execution agent may update the value of the remaining number of tokens and the time of the last execution of the token fetching operation and execute the token fetching operation in response to determining that the difference between the accumulated number of tokens and the pre-consumed number of tokens satisfies a preset condition. The preset condition may be that the difference is less than zero and the number of the pre-consumption tokens is less than or equal to the difference.
And (4) optional. The execution main body may send a prompt message requesting execution failure to the terminal device that sent the request in response to the difference between the accumulated token number and the pre-consumed token number not satisfying the preset condition.
In some optional implementations of some embodiments, the updating, by the execution main, the value of the remaining number of tokens and the time of the last execution of the token fetching operation may include:
in a first step, in response to determining that the accumulated token count is greater than a bucket capacity value of a token bucket corresponding to the request, a value of the accumulated token count is updated to the bucket capacity value. Wherein the bucket capacity value may be a maximum number of tokens that can be held in the token bucket.
As an example, the above-described cumulative token number may be 15. The above-mentioned bucket capacity value may be 10. The value of the above-described cumulative token number may be updated to 10. Referring to fig. 3, the value of the cumulative token count 301 may be updated to the bucket capacity value 303 in response to determining that the cumulative token count 301 is greater than the bucket capacity value 303 of the token bucket corresponding to the request 302.
And secondly, updating the value of the residual token number into the difference value between the accumulated token number and the pre-consumption token number.
As an example, the above-described cumulative token number may be 15. The number of pre-consumption tokens may be 8. The difference between the accumulated number of tokens and the pre-consumed number of tokens may be 7. The value of the number of remaining tokens can be updated 7.
And thirdly, updating the time of last token fetching operation to the time of receiving the request.
In some optional implementations of some embodiments, the executing unit may perform the token fetching operation, including: and updating the token number in the token bucket to the residual token number in response to determining that the residual token number is greater than or equal to zero.
In some optional implementations of some embodiments, the executing unit may further include: and updating the token number in the token bucket to the residual token number in response to determining that the residual token number is greater than or equal to zero.
The above embodiments of the present disclosure have the following advantages: by the token fetching operation execution method of some embodiments of the present disclosure, the system service capability can be improved on the premise of ensuring the system stability. Specifically, the reason why it is difficult to compromise the service capability of the system while ensuring the stability of the system is that: when the number of tokens in the token bucket is less than the number of tokens required for the request, the request is directly denied in order to ensure system stability. Based on this, the token fetching operation execution method of some embodiments of the present disclosure does not directly reject the request when the accumulated token number is less than the consumption token number required by the request. But the number of the pre-consumption tokens is determined according to the priority of the request, and the token fetching operation is executed according to the number of the pre-consumption tokens, so that the request with the priority obtains the tokens according to the number of the pre-consumption tokens to be executed. Therefore, the stability of the system is ensured, and the service capability of the system is considered.
With further reference to fig. 4, a flow 400 of further embodiments of a method of performing a token fetch operation is illustrated. The flow 400 of the token fetching operation execution method includes the following steps:
in response to receiving the request, step 401 determines an accumulated token number according to the remaining token number, the token generation speed, and the time of last execution of the token fetching operation.
In some embodiments, the specific implementation manner and technical effects of step 401 may refer to step 201 in those embodiments corresponding to fig. 2, and are not described herein again.
Step 402, in response to determining that the accumulated token number is greater than zero, determining a consumption token number required for executing the business operation corresponding to the request.
In some embodiments, an executing agent (e.g., a computing device as shown in fig. 1) of the token-taking operation execution method may determine the number of consumption tokens by the following equation in response to determining that the cumulative number of tokens is greater than zero:
Figure BDA0002922358270000101
wherein the need _ limits represents the above consumption token number. S represents the token generation speed. V represents the average elapsed time ratio corresponding to the request. U denotes an adjustment factor.
Figure BDA0002922358270000102
Indicating rounding up. The average elapsed time ratio may be a ratio between an average processing time of each request having the same category as the request and an average processing time of requests of all categories. The average elapsed time ratio can be determined by an AOP (Aspect Oriented Programming) method. When the request does not have priority, the adjustment factor may be 1. When the request has a priority, the adjustment factor may be a value preset according to the priority of the request, andthe adjustment factor is in positive correlation with the priority.
As an example, the request may have 4 priorities of 1, 2, 3, and 4. The larger the value, the higher the priority of the corresponding request. The adjustment factors corresponding to the above priorities may be 2, 3, 4 and 5, respectively.
Step 403, in response to determining that the accumulated token number is less than the consumption token number and that the request has a priority, determining a pre-consumption token number according to the consumption token number and the priority.
In some embodiments, the execution agent may determine the number of pre-consumption tokens by the following formula according to the number of consumption tokens and the priority in response to determining that the accumulated number of tokens is less than the number of consumption tokens and that the request has the priority:
Figure BDA0002922358270000103
where pre _ limits represents the number of pre-consumed tokens. The need _ limits represents the above consumption token number. G denotes a priority parameter.
Figure BDA0002922358270000104
Indicating rounding up. The priority parameter is in positive correlation with the priority. The priority parameter may be expressed in percentage.
As an example, first, 100% may be equally divided according to the number of priorities the request has, resulting in an equal division percentage. The product of the value of each priority and the above-mentioned percentile may then be used as the priority parameter for that priority. The request may have 4 priorities of 1, 2, 3 and 4. The corresponding priority parameters may be 25%, 50%, 75% and 100%
In step 404, in response to determining that the difference between the accumulated token count and the pre-consumed token count satisfies the preset condition, updating the value of the remaining token count and the time of the last token fetching operation and executing the token fetching operation.
In some embodiments, the specific implementation manner and technical effects of step 404 may refer to step 204 in those embodiments corresponding to fig. 2, and are not described herein again.
Step 405, executing the service operation corresponding to the request.
In some embodiments, the execution subject may execute a service operation corresponding to the request.
As an example, the request may be an item search request. The corresponding business operation may be to search the article information in the database to obtain a search result, and send the search result to the terminal device that sent the request for display.
As can be seen from fig. 4, compared with the description of some embodiments corresponding to fig. 2, the flow 400 of the token fetching operation execution method in some embodiments corresponding to fig. 4 embodies the steps of extending the determining of the consumption token number and the pre-consumption token number. The number of consumption tokens required by the request can be determined in a self-adaptive manner, the number of consumption tokens required by the request is dynamically adjusted according to the average time consumption ratio corresponding to the request under the condition that system service resources are in shortage, the request frequency is controlled, and the stability and the service capability of the system are ensured. Meanwhile, the number of pre-consumption tokens is dynamically set according to the determined number of consumption tokens, so that excessive pre-consumption of the tokens is prevented. On the premise of ensuring the stability of the system, the service capability of the system is further improved.
With further reference to fig. 5, as an implementation of the methods shown in the above figures, the present disclosure provides some embodiments of a token fetching operation execution apparatus, which correspond to those shown in fig. 2, and which may be applied in various electronic devices.
As shown in fig. 5, the token fetching operation performing apparatus 500 of some embodiments includes: a first determining unit 501, a second determining unit 502, a third determining unit 503, and an updating and executing unit 504. Wherein the first determining unit 501 is configured to determine the accumulated token number according to the remaining token number, the token generation speed and the time of last execution of the token fetching operation in response to receiving the request. A second determining unit 502 configured to determine, in response to determining that the accumulated token number is greater than zero, a consumption token number required to perform a business operation corresponding to the request. A third determining unit 503 configured to determine a number of pre-consumed tokens required to perform the business operation in response to determining that the accumulated token number is less than the consumed token number and that the request has a priority. An updating and executing unit 504, configured to update the value of the remaining token count and the time of the last token fetching operation and execute the token fetching operation in response to determining that the difference between the accumulated token count and the pre-consumed token count satisfies a preset condition.
In an optional implementation manner of some embodiments, the second determining unit 502 of the token fetching execution apparatus 500 may be further configured to: and in response to determining that the accumulated token number is greater than zero, determining the consumption token number according to the average consumption rate corresponding to the request and the token generation speed.
In an optional implementation manner of some embodiments, the third determining unit 503 of the token fetching execution apparatus 500 may be further configured to: in response to determining that the accumulated number of tokens is less than the consumed number of tokens and that the request has a priority, determining the pre-consumed number of tokens based on the consumed number of tokens and the priority.
In an optional implementation manner of some embodiments, the update and execution unit 504 of the token fetching execution apparatus 500 may be further configured to: updating the value of the accumulated token count to the bucket capacity value in response to determining that the accumulated token count is greater than the bucket capacity value of the token bucket corresponding to the request; updating the value of the residual token number to the difference value between the accumulated token number and the pre-consumption token number; and updating the time of last token fetching operation to the time of receiving the request.
In an optional implementation manner of some embodiments, the update and execution unit 504 of the token fetching execution apparatus 500 may be further configured to: and updating the number of tokens in the token bucket to zero in response to determining that the number of remaining tokens is less than zero.
In an optional implementation manner of some embodiments, the update and execution unit 504 of the token fetching execution apparatus 500 may be further configured to: and updating the token number in the token bucket to the residual token number in response to determining that the residual token number is greater than or equal to zero.
In an optional implementation manner of some embodiments, the token fetching operation performing apparatus 500 further includes a service operation performing unit. The service operation execution unit may be configured to execute a service operation corresponding to the request.
It will be understood that the elements described in the apparatus 500 correspond to various steps in the method described with reference to fig. 2. Thus, the operations, features and resulting advantages described above with respect to the method are also applicable to the apparatus 500 and the units included therein, and are not described herein again.
Referring now to fig. 6, shown is a schematic diagram of an electronic device 600 suitable for use in implementing some embodiments of the present disclosure. The electronic device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 6, electronic device 600 may include a processing means (e.g., central processing unit, graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage means 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 illustrates an electronic device 600 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided. Each block shown in fig. 6 may represent one device or may represent multiple devices as desired.
In particular, according to some embodiments of the present disclosure, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, some embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In some such embodiments, the computer program may be downloaded and installed from a network through the communication device 609, or installed from the storage device 608, or installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of some embodiments of the present disclosure.
It should be noted that the computer readable medium described in some embodiments of the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In some embodiments of the disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In some embodiments of the present disclosure, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: in response to receiving the request, determining an accumulated token number according to the remaining token number, the token generation speed and the time of the last token fetching operation; in response to determining that the accumulated token number is greater than zero, determining a consumption token number required for executing the business operation corresponding to the request; in response to determining that the accumulated number of tokens is less than the consumed number of tokens and that the request has priority, determining a number of pre-consumed tokens required to perform the business operation; and in response to the fact that the difference value between the accumulated token number and the pre-consumption token number meets a preset condition, updating the numerical value of the residual token number and the time of the last token fetching operation and executing the token fetching operation.
Computer program code for carrying out operations for embodiments of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in some embodiments of the present disclosure may be implemented by software, and may also be implemented by hardware. The described units may also be provided in a processor, and may be described as: a processor includes a first determination unit, a second determination unit, a third determination unit, and an update and execution unit. Where the names of the units do not constitute a limitation on the units themselves in some cases, for example, the first determination unit may also be described as "a unit that determines the accumulated token count from the remaining token count, the token generation speed, and the time at which the token fetching operation was performed last time in response to receiving a request".
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.

Claims (10)

1. A token fetch operation execution method, comprising:
in response to receiving the request, determining an accumulated token number according to the remaining token number, the token generation speed and the time of the last token fetching operation;
in response to determining that the accumulated token number is greater than zero, determining a consumption token number required for executing the business operation corresponding to the request;
in response to determining that the cumulative number of tokens is less than the number of consumption tokens and that the request has priority, determining a number of pre-consumption tokens required to perform the business operation;
and in response to the fact that the difference value between the accumulated token number and the pre-consumption token number meets a preset condition, updating the numerical value of the residual token number and the time of the last token fetching operation and executing the token fetching operation.
2. The method of claim 1, wherein the determining a number of consumption tokens required to perform the business operation corresponding to the request comprises:
and determining the consumption token number according to the average consumption rate corresponding to the request and the token generation speed.
3. The method of claim 1, wherein the determining a number of pre-consumption tokens required to perform the business operation comprises:
and determining the number of the pre-consumption tokens according to the number of the consumption tokens and the priority.
4. The method of claim 1, wherein said updating the value of the remaining number of tokens and the time the last token fetching operation was performed comprises:
in response to determining that the cumulative number of tokens is greater than a bucket capacity value of a token bucket corresponding to the request, updating a numerical value of the cumulative number of tokens to the bucket capacity value;
updating the value of the remaining token number to be the difference between the accumulated token number and the pre-consumption token number;
and updating the time of last token fetching execution to the time of receiving the request.
5. The method of claim 4, wherein the performing a token fetch operation comprises:
updating the number of tokens in the token bucket to zero in response to determining that the remaining number of tokens is less than zero.
6. The method of claim 5, wherein the performing a token fetch operation further comprises:
updating the number of tokens in the token bucket to the remaining number of tokens in response to determining that the remaining number of tokens is greater than or equal to zero.
7. The method of claim 1, wherein the method further comprises:
and executing the business operation corresponding to the request.
8. A token fetching operation execution apparatus comprising:
a first determination unit configured to determine, in response to receiving the request, an accumulated token number according to the remaining token number, the token generation speed, and a time at which the token fetching operation was performed last time;
a second determining unit configured to determine, in response to determining that the accumulated token number is greater than zero, a consumption token number required to perform a business operation corresponding to the request;
a third determining unit configured to determine a number of pre-consumption tokens required to perform the business operation in response to determining that the accumulated token number is less than the consumption token number and that the request has a priority;
and the updating and executing unit is configured to update the numerical value of the residual token number and the time of the last token taking operation and execute the token taking operation in response to the fact that the difference value between the accumulated token number and the pre-consumption token number meets the preset condition.
9. An electronic device, comprising:
one or more processors;
a storage device having one or more programs stored thereon,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, wherein the program, when executed by a processor, implements the method of any one of claims 1-7.
CN202110121819.3A 2021-01-28 2021-01-28 Token fetching operation execution method, device, electronic equipment and computer readable medium Pending CN113760365A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110121819.3A CN113760365A (en) 2021-01-28 2021-01-28 Token fetching operation execution method, device, electronic equipment and computer readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110121819.3A CN113760365A (en) 2021-01-28 2021-01-28 Token fetching operation execution method, device, electronic equipment and computer readable medium

Publications (1)

Publication Number Publication Date
CN113760365A true CN113760365A (en) 2021-12-07

Family

ID=78786527

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110121819.3A Pending CN113760365A (en) 2021-01-28 2021-01-28 Token fetching operation execution method, device, electronic equipment and computer readable medium

Country Status (1)

Country Link
CN (1) CN113760365A (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110545246A (en) * 2018-05-29 2019-12-06 北京京东尚科信息技术有限公司 Token bucket-based current limiting method and device
CN111447150A (en) * 2020-02-29 2020-07-24 中国平安财产保险股份有限公司 Access request current limiting method, server and storage medium
US20200311197A1 (en) * 2019-03-27 2020-10-01 International Business Machines Corporation Natural language processing matrices

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110545246A (en) * 2018-05-29 2019-12-06 北京京东尚科信息技术有限公司 Token bucket-based current limiting method and device
US20200311197A1 (en) * 2019-03-27 2020-10-01 International Business Machines Corporation Natural language processing matrices
CN111447150A (en) * 2020-02-29 2020-07-24 中国平安财产保险股份有限公司 Access request current limiting method, server and storage medium

Similar Documents

Publication Publication Date Title
CN110781373B (en) List updating method and device, readable medium and electronic equipment
CN112416632B (en) Event communication method and device, electronic equipment and computer readable medium
CN111240834A (en) Task execution method and device, electronic equipment and storage medium
CN111246228A (en) Method, device, medium and electronic equipment for updating gift resources of live broadcast room
CN110768861B (en) Method, device, medium and electronic equipment for obtaining overtime threshold
CN113760991A (en) Data operation method and device, electronic equipment and computer readable medium
CN112559898B (en) Item information sending method, item information sending device, electronic equipment and computer readable medium
CN112422551B (en) SSL certificate updating method and device, electronic equipment and storage medium
CN113791891A (en) Continuous integration task construction method, device, equipment and computer readable medium
CN112181733A (en) Service request processing method, device, equipment and storage medium
CN112019406B (en) Flow monitoring method and device, electronic equipment and computer readable medium
CN113760365A (en) Token fetching operation execution method, device, electronic equipment and computer readable medium
CN111756833B (en) Node processing method, node processing device, electronic equipment and computer readable medium
CN112163176A (en) Data storage method and device, electronic equipment and computer readable medium
CN113518183A (en) Camera calling method and device and electronic equipment
CN113760178A (en) Cache data processing method and device, electronic equipment and computer readable medium
CN112817701A (en) Timer processing method and device, electronic equipment and computer readable medium
CN111580890A (en) Method, apparatus, electronic device, and computer-readable medium for processing features
CN112527454A (en) Container group scheduling method and device, electronic equipment and computer readable medium
CN112015625B (en) Alarm device control method, device, electronic device and computer readable medium
CN112235167B (en) Flow alarm method, device, electronic equipment and computer readable medium
CN112307320A (en) Information pushing method and device, mobile terminal and storage medium
CN112804164B (en) Flow information generation method and device, electronic equipment and computer readable medium
CN112073202B (en) Information generation method and device, electronic equipment and computer readable medium
CN112148448B (en) Resource allocation method, apparatus, device and computer readable 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