WO2019120217A1 - 一种令牌获取方法、装置、服务器、用户终端及介质 - Google Patents

一种令牌获取方法、装置、服务器、用户终端及介质 Download PDF

Info

Publication number
WO2019120217A1
WO2019120217A1 PCT/CN2018/122042 CN2018122042W WO2019120217A1 WO 2019120217 A1 WO2019120217 A1 WO 2019120217A1 CN 2018122042 W CN2018122042 W CN 2018122042W WO 2019120217 A1 WO2019120217 A1 WO 2019120217A1
Authority
WO
WIPO (PCT)
Prior art keywords
user terminal
token
tokens
preset
global
Prior art date
Application number
PCT/CN2018/122042
Other languages
English (en)
French (fr)
Inventor
孙鹏
Original Assignee
北京金山云网络技术有限公司
北京金山云科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 北京金山云网络技术有限公司, 北京金山云科技有限公司 filed Critical 北京金山云网络技术有限公司
Publication of WO2019120217A1 publication Critical patent/WO2019120217A1/zh

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/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • 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
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load

Definitions

  • the present application relates to the field of communications technologies, and in particular, to a token acquiring method, apparatus, server, user terminal, and medium.
  • an object storage system a user can interact with the object storage system to implement uploading and downloading of objects. Since the data storage system has a large number of users, and these users share limited bandwidth resources, it is necessary to limit the bandwidth resources used by each user.
  • the object storage system includes a front-end server and a back-end storage system.
  • the user terminal before the user terminal sends a request for uploading or downloading to the storage system of the back end, in order to obtain the bandwidth resource, the user terminal first needs to send a request for the request token to the server at the front end; the server at the front end passes the preset global order according to the request.
  • the token bucket acquires the token, assigns the token to the user terminal, and notifies the user terminal; after receiving the notification, the user terminal interacts with the storage system of the backend by using the bandwidth resource corresponding to the allocated token to implement uploading or downloading of the object. .
  • the purpose of the embodiment of the present application is to provide a method, an apparatus, a server, a user terminal, and a medium for acquiring a token, so as to prevent the system from being in an abnormal state that cannot provide services for other users for a long time.
  • the specific technical solutions are as follows:
  • the embodiment of the present invention provides a method for acquiring a token, which is applied to a server, where the method includes: receiving a first token request sent by a user terminal; determining, according to the first token request, the The number of tokens requested by the user terminal; the number of tokens requested by the user terminal is obtained from a specific token bucket corresponding to the preset user terminal; if the specific token is successfully acquired, Obtaining, from the preset global token bucket, the number of tokens requested by the user terminal, where the number of tokens in the specific token bucket is smaller than the order in the global token bucket The number of cards.
  • the method further includes: if the number of tokens requested by the user terminal is successfully obtained from a preset global token bucket, sending the user to the user terminal The number of tokens requested by the terminal is a global token.
  • the method further includes: if the global token fails to be obtained, rejecting the first token request according to a preset rejection policy or after presetting the first preset duration, again from the preset In the global token bucket, the number of tokens requested by the user terminal is obtained as a global token.
  • the method further includes: rejecting the first token request if the obtaining of the specific token fails; or, if the acquiring the specific token fails, at an interval target preset duration And acquiring, from the preset specific token bucket corresponding to the user terminal, the number of tokens requested by the user terminal, or a specific token; or if the acquiring the specific token fails, The user terminal sends a waiting instruction for instructing to wait for the first preset duration, so that the user terminal receives the waiting instruction, and after re-separating the first preset duration in the waiting instruction, re-sending to the server Sending the first token request.
  • the first token request includes a bandwidth requirement of the user terminal; and determining, according to the first token request, the number of tokens requested by the user terminal, including: Calculating a bandwidth corresponding to the bandwidth requirement in the first token request, and calculating a number of tokens requested by the user terminal.
  • the method further includes: determining, by the predetermined token bucket corresponding to the preset user terminal, a number of tokens requested by the user terminal, Whether the user terminal is a preset terminal that requires a bandwidth limitation; the obtaining, from the specific token bucket corresponding to the preset user terminal, the number of tokens requested by the user terminal, including: When it is determined that the user terminal is a preset terminal that requires bandwidth limitation, the number of tokens requested by the user terminal is obtained from a specific token bucket corresponding to the preset user terminal.
  • the first token request further includes an identifier of the user terminal, and determining whether the user terminal is a preset terminal that requires bandwidth limitation, includes: determining a preset bandwidth requirement Whether the identifier of the user terminal is included in the user identifier, and if yes, determining that the user terminal is a preset terminal that requires bandwidth limitation.
  • the method further includes: if the user terminal is not a preset terminal that requires bandwidth limitation, determining whether the number of tokens requested by the user terminal is greater than or equal to the global token. The total number of global tokens in the bucket; if the number of tokens requested by the user terminal is greater than or equal to the total number of global tokens in the global token bucket, setting the user terminal to be needed a user terminal that limits the bandwidth, and sets a corresponding specific token bucket for the user terminal, and rejects the first token request; if the number of tokens requested by the user terminal is smaller than that in the global token bucket The total number of global tokens is obtained, and the number of tokens requested by the user terminal is obtained from the global token bucket.
  • the method further includes: acquiring a number of token requests and a number of token request failures of each user terminal in a preset time; and when the sum of the number of token request failures of each user terminal is greater than zero If the user terminal is not recorded, the user terminal with the most token request times is determined as the penalty user terminal, and the total number of specific tokens in the specific token bucket corresponding to the determined penalty user terminal is set to a first preset number of tokens, where the number of the first preset tokens is smaller than the number of tokens in the global token bucket; if the sum of the number of token request failures of the respective user terminals is equal to zero, if If the user terminal is punishing, the number of the specified tokens corresponding to the specific token bucket corresponding to the punishing user terminal is increased, and the number of the specific tokens corresponding to the specific token bucket corresponding to the punishing user terminal is increased.
  • the total number of specific tokens for a particular token bucket, the total number of specific tokens for the increased specific token bucket being less than the
  • the method further includes: if the global token fails to be acquired, acquiring a total number of worker threads for processing the token request at the current time; and rejecting if the total number reaches the first preset number Determining, by the first token, a worker thread corresponding to the first token request; if the total number reaches a second preset quantity, and does not reach the first preset quantity, determining the recorded penalty user Whether the user terminal is included in the terminal; if yes, rejecting the first token request, and releasing the working thread corresponding to the first token request; if not, after the interval of the first preset duration, Obtaining, from the global token bucket, the number of tokens requested by the user terminal, and if the total number does not reach the second preset number, after the interval is the first preset duration, the global order is again The number of tokens requested by the user terminal is obtained in the card bucket.
  • the embodiment of the present application provides a method for acquiring a token, which is applied to a user terminal, where the foregoing method includes:
  • the feedback information includes: successfully acquiring the number of tokens requested by the user terminal, and the method further includes: using the number of tokens requested by the user terminal, a global order Card, performing a write or read in the data storage system.
  • the embodiment of the present application provides a token acquiring apparatus, which is applied to a server, and includes: a first receiving module, configured to receive a first token request sent by a user terminal; and a first determining module, configured to Determining, by the first token request, the number of tokens requested by the user terminal; the first obtaining module is configured to acquire, from the specific token bucket corresponding to the preset user terminal, the requested by the user terminal The number of tokens is a specific token, the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket; and the second obtaining module is configured to: if the specific token is successfully acquired, The global token bucket acquires a global token of the number of tokens requested by the user terminal.
  • the embodiment of the present application provides a token obtaining apparatus, which is applied to a user terminal, and includes: a sending module, configured to send a first token request of a user terminal to a server, where the first token request is used for Determining, by the server, the number of tokens requested by the user terminal according to the first token request; acquiring the first token requesting the requested token in a specific token bucket corresponding to the preset user terminal
  • the number of tokens is a specific token, the number of tokens in the specific token bucket is less than the number of tokens in the global token bucket; if the specific token fails to be obtained, the first token request is rejected; Successfully acquiring the specific token, obtaining a number of global tokens requested by the user terminal from the global token bucket; and receiving, configured to receive, by the server, the first token The feedback requested to be sent.
  • an embodiment of the present application provides a server, including: a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory complete communication with each other through a bus; and the memory is configured to store the computer program.
  • a processor configured to execute a program stored on the memory, to implement the method steps of the first aspect.
  • an embodiment of the present application provides a user terminal, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory complete communication with each other through a bus; and the memory is configured to store the computer program.
  • a processor configured to execute a program stored on the memory, to implement the method steps of the second aspect.
  • the embodiment of the present application provides a computer readable storage medium, where the computer program stores a computer program, and when the computer program is executed by the processor, the method steps described in the first aspect are implemented.
  • an embodiment of the present application provides a computer readable storage medium, where the computer program stores a computer program, and when the computer program is executed by the processor, the method steps described in the second aspect are implemented.
  • an embodiment of the present application provides a computer program product comprising instructions, which when executed on a computer, cause the computer to perform the method steps described in the first aspect above.
  • an embodiment of the present application provides a computer program product comprising instructions, when executed on a computer, causing a computer to perform the method steps described in the second aspect above.
  • an embodiment of the present application provides a computer program that, when run on a computer, causes the computer to perform the method steps described in the first aspect above.
  • an embodiment of the present application provides a computer program that, when run on a computer, causes the computer to perform the method steps described in the second aspect above.
  • the user terminal that needs to request the token successfully obtains the specific token from the specific token bucket corresponding to the user terminal, and then obtains the global token from the global token bucket, thereby limiting the
  • the user terminal obtains the token directly from the global token bucket; since the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket, the user terminal cannot obtain all the tokens from the global token bucket at one time.
  • the global token ensures that other user terminals than the user terminal can request a token from the global token bucket to prevent the system from being in an abnormal state that cannot provide services for other users for a long time.
  • FIG. 1 is a first schematic flowchart of a method for acquiring a token applied to a server according to an embodiment of the present application
  • FIG. 2 is a second schematic flowchart of a method for acquiring a token applied to a server according to an embodiment of the present application
  • FIG. 3 is a schematic flowchart of implementing a reward and punishment for penalizing a user terminal in a token acquiring method according to an embodiment of the present disclosure
  • FIG. 4 is a schematic flowchart of a method for acquiring a token applied to a user terminal according to an embodiment of the present disclosure
  • FIG. 5 is a schematic structural diagram of a token acquiring apparatus applied to a server according to an embodiment of the present application
  • FIG. 6 is a schematic structural diagram of a token acquiring apparatus applied to a user terminal according to an embodiment of the present application
  • FIG. 7 is a schematic structural diagram of a server according to an embodiment of the present application.
  • FIG. 8 is a schematic structural diagram of a user terminal according to an embodiment of the present application.
  • the global token bucket automatically replenishes the token within the preset duration.
  • the request of the other user is satisfied after the global token bucket is replenished, the other users obtain the token from the global token bucket through the above request, so that the requests of other users are obtained. It may take too long for the global token bucket to replenish the token, which may cause the system to be in an abnormal state that cannot serve other users for a long time.
  • the inventors consider that the method for acquiring a token, the device, the server, the user terminal, and the medium are provided by using the embodiment of the present application, and the user terminal that needs the request token corresponds to the user terminal.
  • a specific token bucket successfully obtains a specific token, and then obtains a global token from the global token bucket, thereby limiting the user terminal to obtain the token directly from the global token bucket.
  • the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket, so that the user terminal cannot obtain all the global tokens from the global token bucket at one time, thereby ensuring that the user terminal is not included in the user terminal.
  • Other user terminals can request tokens from the global token bucket to prevent the system from being in an abnormal state that cannot serve other users for a long time.
  • a specific token bucket and a global token bucket may be collectively referred to as a token bucket.
  • a token bucket can be thought of as a container that holds a preset number of tokens.
  • the token bucket has a token bucket control mechanism, and the control mechanism may be to place a token into the bucket according to a set speed or a preset frequency, which is of course not limited thereto. And, if the token in the token bucket is not acquired, or the speed of being acquired is less than the generated speed, the token will continue to increase until the token bucket is filled. When the token in the token bucket exceeds the total token number of the token bucket, the extra token will overflow the token bucket, so that the token in the token bucket no longer increases.
  • This control mechanism of the token bucket can achieve bandwidth limitation. That is, the user requests to apply for a token from a token bucket, and only the token application is successful to perform subsequent operations. If the token application fails, it needs to wait or be notified that the application fails. This achieves the effect of global bandwidth limitations.
  • the token obtaining method provided by the server in the embodiment of the present application can be applied to a server of the data storage system.
  • the embodiment of the present application provides a token acquisition method.
  • the token obtaining method provided by the embodiment of the present application is applied to a server, and the method may include the following steps A1-A4:
  • Step A1 Receive a first token request sent by a user terminal.
  • Step A2 Determine, according to the first token request, a quantity of tokens requested by the user terminal;
  • Step A3 Obtain, from a specific token bucket corresponding to the preset user terminal, a specific token of the number of tokens requested by the user terminal;
  • step A4 if the specific token is successfully obtained, the number of tokens requested by the user terminal is obtained from the preset global token bucket;
  • the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket.
  • the method may further include:
  • step A5 if the number of tokens requested by the user terminal is successfully obtained from the preset global token bucket, the number of tokens requested by the user terminal is sent to the user terminal. brand.
  • the method may further include:
  • Step A6 If the global token fails to be obtained, the first token request is rejected according to the preset rejection policy, or after the first preset duration is obtained, the preset global token bucket is obtained again.
  • the number of tokens requested by the user terminal is a global token.
  • the method may further include:
  • Step A71 If the obtaining of the specific token fails, rejecting the first token request; or,
  • step A72 if the failure to obtain the specific token fails, the number of tokens requested by the user terminal is obtained from the specific token bucket corresponding to the preset user terminal again after the interval target preset duration.
  • Specific token or,
  • Step A73 If the acquiring the specific token fails, sending, to the user terminal, a waiting instruction for indicating waiting for the first preset duration, so that the user terminal receives the waiting instruction, and waiting for the waiting instruction at intervals After the first preset duration in the medium, the first token request is resent to the server.
  • the first token request includes a bandwidth requirement of the user terminal
  • the determining, according to the first token request, the number of tokens requested by the user terminal The method includes: calculating, according to the bandwidth corresponding to the bandwidth requirement in the first token request, the number of tokens requested by the user terminal.
  • the method before the obtaining, by the preset specific token bucket corresponding to the user terminal, the number of tokens requested by the user terminal, the method further include:
  • Step A8 determining whether the user terminal is a preset terminal that requires bandwidth limitation
  • the obtaining the specific number of tokens requested by the user terminal from the specific token bucket corresponding to the preset user terminal includes: when determining that the user terminal is preset When a terminal with a bandwidth limitation is required, a specific token of the number of tokens requested by the user terminal is obtained from a specific token bucket corresponding to the preset user terminal.
  • the first token request further includes an identifier of the user terminal
  • determining whether the user terminal is a preset terminal that requires bandwidth limitation includes: determining a preset Whether the identifier of the user terminal is included in the user identifier that requires bandwidth limitation, and if yes, determining that the user terminal is a preset terminal that requires bandwidth limitation.
  • the method may further include:
  • step A9 if the user terminal is not a preset terminal that requires bandwidth limitation, it is determined whether the number of tokens requested by the user terminal is greater than or equal to the total number of global tokens in the global token bucket.
  • Step A10 If the number of tokens requested by the user terminal is greater than or equal to the total number of global tokens in the global token bucket, set the user terminal to a user terminal that requires bandwidth limitation, The user terminal sets a corresponding specific token bucket and rejects the first token request;
  • Step A11 If the number of tokens requested by the user terminal is less than the total number of the global tokens in the global token bucket, obtain the requested by the user terminal from the global token bucket.
  • the number of tokens is a global token.
  • the method may further include:
  • step A12 the number of token requests and the number of token request failures of each user terminal are obtained within a preset time period
  • Step A13 when the sum of the number of token request failures of each user terminal is greater than zero, if the penalty user terminal is not recorded, the user terminal with the most token request times is determined as the penalty user terminal, and the determined And punishing the total number of the specific tokens in the specific token bucket corresponding to the user terminal, and setting the number of the first preset tokens, where the number of the first preset tokens is smaller than the number of tokens in the global token bucket;
  • Step A14 when the sum of the number of token request failures of each user terminal is equal to zero, if the penalized user terminal has been recorded, based on the recorded number of tokens that have been set to punish the specific token bucket corresponding to the user terminal, Increasing the number of specific tokens that the recorded penalty user terminal corresponds to a specific token bucket, and obtaining the total number of specific tokens of the increased specific token bucket, the specific token of the increased specific token bucket The total number is less than the number of tokens in the global token bucket.
  • the method may further include:
  • Step A15 If the global token fails to be obtained, obtain the total number of worker threads used to process the token request at the current time;
  • Step A16 If the total quantity reaches the first preset quantity, reject the first token request, and release the working thread corresponding to the first token request;
  • Step A17 If the total number reaches the second preset number, and the first preset number is not reached, determining whether the recorded user terminal includes the user terminal; if yes, rejecting the first The token request, and release the work thread corresponding to the first token request; if not, the number of tokens requested by the user terminal is obtained from the global token bucket again after the interval is separated by the first preset duration Global token
  • step A18 if the total number does not reach the second preset number, the number of tokens requested by the user terminal is obtained from the global token bucket again after the interval is separated by the first preset duration.
  • a token acquisition method provided by the server from the perspective of the embodiment of the present application is described below with reference to FIG.
  • a method for acquiring a token provided by an embodiment of the present application is applied to a server, and the method may include the following steps:
  • Step 101 Receive a first token request sent by a user terminal.
  • the login Before entering the above data storage system, the login can be verified by the user name and password, thereby ensuring that the user name and the user password match the user name and the user password in the database in which the user information is stored in advance, and the privacy of the user is protected.
  • the user name is the user identifier used by the user to access the data storage system.
  • the user terminal may pre-customize the terminal device that the fixed traffic or the user uses the charging traffic, and the user terminal may be a terminal device of a different brand type.
  • Any user terminal that can implement the embodiment of the present application belongs to the protection scope of the embodiment of the present application. It should be emphasized that the user terminal is a terminal used by the user to access the data storage system. Moreover, for a user, the user can access the data storage system by using the same user identifier on different user terminals, and the data storage system uses the user identifier as a basis for distinguishing different users.
  • the user terminal stated in the embodiment of the present application is substantially equivalent to the user.
  • Step 102 Determine, according to the first token request, the number of tokens requested by the user terminal.
  • the first token request may include the number of tokens requested by the user terminal.
  • the above step 102 determines that the number of tokens requested by the user terminal can obtain the requested number of tokens directly from the first token request, which is convenient and quick.
  • the first token request includes a bandwidth requirement of the user terminal.
  • the foregoing step 102 may determine the number of tokens requested by the user terminal by the following steps:
  • calculating the number of tokens requested by the user terminal according to the bandwidth corresponding to the bandwidth requirement in the first token request may include the following steps:
  • the preset operation rule may be a division rule or a multiplication rule. Certainly, the preset operation rule here is merely an example. Any preset operation rule that can implement the embodiment of the present application belongs to the protection scope of the embodiment of the present application, and is not exemplified herein.
  • the specific implementation steps of the foregoing steps are as follows: the correspondence between the size of the preset bandwidth and the size of the preset token is the bandwidth size corresponding to each token, and the first token request is The bandwidth corresponding to the bandwidth requirement is divided by the bandwidth corresponding to each token, and the quotient is obtained as the number of tokens requested by the user terminal.
  • a token is allowed to send 1 Byte of data, and the corresponding bandwidth of each token is 1 B.
  • the bandwidth requirement corresponding to the bandwidth requirement in the first token request is 100 B, and the determined number of requested tokens is 100. .
  • B is a unit symbol of commonly used bandwidth traffic. Where B is the symbol of the byte, and the byte is the basic unit of data or data traffic. 1B is 1 Byte.
  • the specific implementation steps of the foregoing steps are as follows: the correspondence between the size of the preset bandwidth and the size of the preset token is a ratio of the size of the preset token to the size of the preset bandwidth.
  • the bandwidth corresponding to the bandwidth requirement in the first token request is multiplied by the ratio to obtain a product, and the product is used as the number of tokens requested by the user terminal.
  • 10 tokens are allowed to send 100 Bytes of data, and 10 tokens have a bandwidth size of 100 B, and the ratio of the token size to the bandwidth size is 0.1/B, and the bandwidth corresponding to the bandwidth requirement in the first token request.
  • the size is 1000B, and the determined number of requested tokens is 100.
  • the corresponding bandwidth size corresponding to each token may be in the range of [1B, 0.1 KB], and the value range is not limited. Among them, 0.1KB is 0.1 kilobytes.
  • Step 103 Determine whether the user terminal is a preset terminal that requires bandwidth limitation. If yes, go to step 104;
  • the preset terminal requiring bandwidth limitation can be determined in various ways:
  • the user terminal set in advance is used as a preset terminal that requires bandwidth limitation. This makes it easy to record user terminals.
  • the user terminal identifier may be stored first, that is, the user identifier of the user of the user terminal is used, so that the specific token bucket corresponding to the identifier is conveniently allocated in a later manner, which is convenient to implement. The bandwidth limit of the user terminal.
  • the determining whether the user terminal is a preset terminal that requires a bandwidth limitation may include: determining whether the pre-recorded preset user bandwidth that requires the bandwidth limitation includes the identifier of the user terminal, and if yes, The user terminal is a pre-recorded preset terminal that requires bandwidth limitation. And if it is not included, determining that the number of tokens requested by the user terminal is greater than or equal to the total number of global tokens in the global token bucket, the identifier of the user terminal is recorded as a preset user identifier that requires bandwidth limitation. The user terminal is used as a preset terminal that requires bandwidth limitation.
  • a user terminal having a fixed bandwidth requirement may be used as a preset terminal that requires bandwidth limitation. This can meet different user needs.
  • the first token request may include a bandwidth requirement
  • determining whether the user terminal is a preset terminal that requires a bandwidth limitation may include: determining whether the bandwidth requirement is a preset fixed bandwidth requirement, and if yes, determining The user terminal is a preset terminal that requires bandwidth limitation.
  • step 104 the number of tokens requested by the user terminal is obtained from a specific token bucket corresponding to the preset user terminal, and the number of tokens of the specific token bucket is smaller than the token of the global token bucket. Quantity.
  • the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket.
  • the total number of tokens in a specific token bucket is smaller than the total number of tokens in the global token bucket. This prevents the user terminal from obtaining all the tokens in the global token bucket at one time, so as to prevent the system from being in an abnormal state that cannot provide services for other users for a long time.
  • the specific token bucket corresponding to the user terminal is preset in order to facilitate targeted restriction on each user terminal.
  • step 105 it is determined whether the specific token is successfully acquired. If not, step 106 is performed; if yes, step 107 is performed.
  • Step 106 If the acquisition of the specific token fails, the first token request is rejected.
  • the specific token of the particular token bucket may be used, or may be used but released, it may also be added automatically, so the number of tokens for a particular token in a particular token bucket is constantly changing. When the number of tokens of a particular token in a particular token bucket is less than the number of tokens requested, then the particular token bucket does not satisfy the requested number of tokens, at which point the server fails to acquire the particular token. Since the specific token bucket is for preventing the user terminal from obtaining all the global tokens from the global token bucket at one time, the specific token bucket does not satisfy the number of tokens requested by the user terminal, and the first token is directly rejected. request.
  • the server may select any one of the following methods according to a preset rejection policy for subsequent processing:
  • the number of tokens requested by the user terminal is obtained from the specific token bucket corresponding to the preset user terminal; or
  • the acquiring the specific token fails, sending a waiting instruction for instructing to wait for the first preset duration to the user terminal, so that the user terminal receives the waiting instruction, at intervals of the waiting instruction After the first preset duration, the first token request is resent to the server.
  • rejecting the first token request may include: generating a reject instruction rejecting the first token request, which is of course not limited thereto. It should be emphasized that the processing method selected by the server is not limited to the three modes given above.
  • the user terminal can process the reject instruction and the wait instruction. For example, according to the reject instruction, the user terminal cannot interact with the backend data storage system at this time, and the user terminal can send a new first token request. For example, according to the waiting instruction, the first token request is resent when waiting for the first preset duration to be reached. In this way, the server can feed back the first token request of the user terminal, and complete the interaction between the user terminal and the server.
  • Step 107 Acquire a global token of the requested number of tokens from the global token bucket.
  • the global token bucket acquires the number of global tokens of the requested token. This is equivalent to concatenating a specific token bucket and a global token bucket, thereby achieving bandwidth limitation on the user terminal.
  • the specific token is successfully obtained from the specific token bucket corresponding to the user terminal, and the global token is obtained from the global token bucket, so that the user terminal is directly restricted.
  • the token is obtained from the global token bucket; since the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket, the user terminal cannot obtain all the global orders from the global token bucket at one time. Card, thereby ensuring that other user terminals than the user terminal can request a token from the global token bucket, preventing the system from being in an abnormal state that cannot provide services for other users for a long time.
  • multiple specific token buckets may be concatenated prior to the global token bucket.
  • the plurality of specific token buckets include a first specific token bucket and a second specific token bucket.
  • a specific implementation process of multiple specific token buckets may be concatenated, a first specific token bucket is concatenated before the global token bucket, and then a serial number is connected before the first specific token bucket. Two specific token buckets, the number of tokens of the second specific token bucket being less than the number of tokens of the first token bucket.
  • the bandwidth restriction is performed by using two layers of specific token buckets, so that the user terminal can apply for the global token of the global token bucket at one time, and the corresponding number is reduced. Further, it is ensured that other user terminals other than the user terminal can request a token from the global token bucket to prevent the system from being in an abnormal state that cannot provide services for other users for a long time.
  • the implementation process of concatenating a second specific token bucket before the first specific token bucket is the same as or similar to the implementation of a specific token bucket before the global token bucket, and details are not described herein. .
  • the user terminal requesting the token, after successfully obtaining the specific token from the second specific token bucket corresponding to the user terminal, and then the user terminal A specific token is obtained in the corresponding first specific token bucket, and the global token is obtained from the global token bucket after the specific token is successfully obtained from the first specific token bucket.
  • the above two-layer specific token bucket is only used as an example. Any specific token bucket that can be implemented by the present application can ensure that other user terminals except the user terminal can request a token from the global token bucket. The scope of protection of the application examples.
  • step 103 includes: determining whether the pre-recorded preset user identifier of the required bandwidth limit includes the identifier of the user terminal. That is, it is judged whether the user who accesses the server and the data storage system through the user terminal is a user who needs bandwidth limitation. If yes, go to step 104; if no, that is, the user terminal is not a preset terminal that requires bandwidth limitation, then step 112 is performed;
  • step 104 the number of tokens requested is obtained from a specific token bucket corresponding to the preset user terminal, and the number of tokens of the specific token bucket is smaller than the number of tokens of the global token bucket.
  • step 105 it is determined whether the specific token is successfully acquired; if yes, step 108 is performed.
  • Step 104 and step 105 in FIG. 2 are the same as steps 104 and 105 in FIG. 1 , and the same or similar technical effects can be achieved, and details are not described herein again.
  • Step 108 Determine whether the number of requested tokens global tokens is successfully obtained from the global token bucket. If yes, go to step 109, if no, go to step 110;
  • Step 109 Send, to the user terminal, a global token of the requested number of tokens;
  • Step 110 Reject the first token request according to a preset rejection policy, or wait for the first preset duration, and perform step 111.
  • the server may reject the first token request according to the preset rejection policy or obtain the first preset duration after the interval, and then obtain the preset global token bucket again.
  • the number of tokens requested by the user terminal is a global token. It can be understood that the global token of the global token bucket fails, and the server waits for the first preset duration to achieve the effect of the current limiting. However, the server may also reject the first token request according to a preset rejection policy, to prevent the user terminal from affecting normal services of other user terminals except the user terminal.
  • the server may send a waiting instruction for indicating to wait for the first preset duration to the user terminal, so that the user terminal receives the waiting instruction, and waits for the waiting instruction at intervals After the first preset duration in the medium, the first token request is resent to the server.
  • Step 111 When waiting for the first preset duration, determine whether the first preset duration waiting for the first token request arrives; if not, proceed to step 111, and if yes, perform step 108, if If the number of the requested tokens fails to be obtained from the global token bucket, the step of rejecting the first token request according to the preset denial policy is performed, and the global token bucket is every second preset duration. , increase the preset number of global tokens.
  • the preset number may be a fixed value, so that partial bandwidth limitation may be implemented.
  • the first preset duration and the second preset duration may be set according to user requirements, and are not limited herein.
  • the first preset duration may be the same as the second preset duration, and the first preset duration and the second preset duration may also be different.
  • Step 112 it is determined whether the requested number of tokens is greater than or equal to the total number of global tokens in the global token bucket; if yes, step 113 is performed, if not, step 114 is performed;
  • Step 113 Record the identifier of the user terminal as a preset user identifier that requires a bandwidth limitation, set a corresponding specific token bucket for the user terminal, and reject the first token request;
  • Step 114 Obtain a number of global tokens of the requested token from the global token bucket.
  • the user terminal may apply for all global tokens of the global token bucket at one time, and the user terminal is called an abnormality.
  • User terminal for traffic Therefore, it is necessary to limit the bandwidth of the user terminal of the abnormal traffic.
  • the global token bucket adds 10 global tokens every 1 second.
  • the number of global tokens in the global token bucket is 25, and the number of tokens requested by the user terminal that requires bandwidth limitation is 30.
  • the number of global tokens that obtain the global token bucket is 35.
  • the number of global tokens in the global token bucket is greater than the number of requested tokens, so that the user terminal can obtain the global token from the global token bucket.
  • the user terminal cannot obtain all the global tokens from the global token bucket at one time, thereby ensuring that other user terminals other than the user terminal can request the token from the global token bucket, thereby preventing the system from being unable to be used for other time.
  • the abnormal state of the service provided by the user is a condition that provides
  • the bandwidth of the user terminal is limited. This can quickly locate the source of abnormal traffic when abnormal traffic occurs, and prevent the system from being in an abnormal state for a long time.
  • the specific token bucket corresponding to the identifier set here may be a specific token bucket already existing in the data storage system, or a newly established specific token bucket.
  • the requested number of tokens equals or exceeds the total number of global tokens in the global token bucket, indicating that the requested number of tokens requested by the first token is unreasonable, and the user terminal may apply for a global token at one time. All global tokens of the bucket, such that the user terminal may affect other user terminals except the user terminal to request tokens from the global token bucket. Therefore, in order to prevent the system from being in an abnormal state that cannot provide services for other users for a long time, The first token request is rejected.
  • Determining the pre-recorded preset user identifier that requires the bandwidth limitation does not include the identifier of the user terminal, and determines that the requested number of tokens is less than the total number of global tokens in the global token bucket, the user terminal The number of requested tokens can be obtained from the global token bucket.
  • the user terminal that determines that the requested number of tokens is greater than or equal to the total number of global tokens in the global token bucket may automatically discover the user terminal of abnormal traffic, and then set the user terminal for the abnormality.
  • the user terminal of the abnormal traffic can be controlled to ensure the stability of the data storage system.
  • the user terminal sends a first token request to the server
  • the server receives the first token request, determines that the pre-recorded preset user identifier that requires the bandwidth limitation does not include the identifier S of the user terminal, and determines that the requested number of tokens is 200;
  • the total number of global tokens in the global token bucket is 100. Since 200 is greater than 100, the identifier S of the user terminal is recorded as a user identifier requiring bandwidth limitation, and a specific token bucket is set for the user terminal. There are 90 specific tokens in the specific token bucket, and the first token request is rejected this time;
  • the user terminal resends the new first token request to the server
  • the server receives the new first token request, determines that the pre-recorded preset required bandwidth limit identifier includes the identifier S of the user terminal, and determines that the new requested token number is 70, then the specific A specific token is successfully obtained in the token bucket, and then 70 global tokens are obtained from the global token bucket.
  • steps A12-A14 may include the following steps:
  • Step 201 Acquire a number of token requests and a number of token request failures of all user terminals in a preset time. That is, the number of token requests and the number of token request failures of each user terminal in a preset time period are obtained.
  • the preset time can be set according to the needs of the user.
  • the smaller the value of the preset time the less likely the system is to be in an abnormal state that cannot provide services for other users for a long time.
  • the value of the preset time is too small, and the frequency of recording is too large, which increases the running load. Therefore, in order to balance the running load and determine the accuracy of the abnormal state, the preset time value is from 1 second to 10 seconds, for example, 5 seconds, 6 seconds.
  • the data recorded at each preset time can be cleared to reduce the load on the storage.
  • the data recorded at each preset time can also be migrated to other storage devices for later use of the recorded data.
  • the above may also obtain the number of successful token requests while obtaining the number of token requests and the number of token request failures.
  • the number of token request successes may be calculated by the difference between the number of token requests and the number of token request failures, or may be obtained by the counter recording the number of token request successes.
  • the calculation process of the former also occupies the running memory, and the latter can also conveniently record the number of successful token requests of all the user terminals acquired within the preset time.
  • the preset time can be implemented by a timer, or any code implementation that can indicate the preset time.
  • the number of token requests, the number of token request failures, and/or the number of token request successes may also be implemented by a counter, or any number of token requests, token request failures, and/or token request successes may be recorded. Code.
  • step 201 may obtain the request information of all user terminals in the preset time by using the following steps:
  • the above acquisition can also be implemented by an acquisition tool, or by a code having an acquisition function. This is not limited here.
  • Step 202 Determine whether the sum of the number of token request failures of all user terminals is equal to zero. If yes, execute 203; if no, and the number of token request failures is greater than zero, step 205 is performed;
  • Step 203 Determine whether there is a penalty user terminal, if yes, execute step 204; if no, the execution ends.
  • Step 204 Increase the number of specific tokens corresponding to the specific token bucket of the penalty user terminal based on the number of tokens that have been set, and obtain the total number of specific tokens of the specific token bucket after the increase.
  • the total number of specific tokens for this particular token bucket is less than the number of tokens in the global token bucket.
  • the number of tokens that have been set may be the number of first preset tokens that have been set only once.
  • the number of tokens that have been set may also be a specific order that has been increased to correspond to the specific token bucket of the user terminal. The number of cards obtained.
  • Step 205 it is determined whether there is a penalty user terminal, if not, step 206 is performed; if yes, the execution ends;
  • the identity of the penalty user terminal indicates that there is a penalty user terminal, and the penalty user terminal corresponds to the total number of specific tokens in the specific token bucket, which has been set to the first preset token number.
  • Step 206 Determine the user terminal with the most token request times as the penalty user terminal, and then perform step 207.
  • the user terminal that punishes the user terminal is the user terminal that has the most number of token requests found in the request information of all user terminals within a preset time.
  • Step 207 Set the total number of specific tokens in the specific token bucket corresponding to the penalty user terminal to the first preset token number, where the first preset token number is smaller than the number of tokens in the global token bucket.
  • the penalty for the penalty user terminal is completed because the number of the first preset tokens is less than the number of tokens in the global token bucket.
  • the server is relatively unstable within a preset time, such as interrupting the service or having an error, and the user terminal can be requested to request a specific time within the preset time.
  • the total number of tokens is reduced, so that it can be guaranteed that the penalty user terminal does not affect other user terminals except the penalty user terminal to request a token from the global token bucket.
  • the number of the first preset tokens may be set according to the needs of the user, or may be calculated by summing the total number of tokens for which the user terminal token requests the number of successes, and the sum of the number of tokens for the number of token request failures. It is obtained by calculating the number of tokens that are successfully requested within a preset time.
  • the number of tokens that are successful for each request of the user terminal is calculated within a preset time, and the minimum number of tokens is found in the number of tokens that all requests succeed.
  • the minimum number of tokens described above may be used as the first preset number of tokens.
  • the number of the first preset tokens may be a preset number.
  • the preset number may be 1 or 2. Any value that satisfies the minimum number of tokens is a protection range of the embodiment of the present application, and is not exemplified herein.
  • Step 208 Acquire the number of token requests and the number of token request failures of all user terminals in the next preset time period adjacent to the preset time.
  • Step 209 Determine whether the sum of the number of token request failures of each user terminal is equal to zero in the next preset time period after the preset time. If yes, step 210 is performed.
  • Step 210 Determine whether the penalty user terminal exists. If yes, execute step 211; if no, the execution ends.
  • Step 211 based on the number of the first preset tokens, increase the number of specific tokens corresponding to the specific token bucket of the penalty user terminal, and obtain the total number of specific tokens of the specific token bucket that is increased.
  • the total number of specific tokens for this particular token bucket is greater than the number of tokens in the global token bucket.
  • the sum of the number of token request failures of each user terminal is equal to zero, indicating that the server is stable within a preset time, such as no interrupt service or error has occurred.
  • the number of specific tokens requested by the penalty user terminal can be increased, so that the user terminal needs can be satisfied.
  • Increasing the total number of specific tokens of a specific token bucket according to a preset ratio belongs to a reward for the penalty user terminal, and the reward here belongs to a gradual reward, which can ensure that the system quickly returns to stability, and reduces the penalty user terminal to other users.
  • the terminal requests the impact of the token from the global token bucket.
  • the penalty time of the user terminal can be set after the penalty.
  • the value of the sleep time is from 1 second to 5 seconds, such as 5 seconds.
  • the preset ratio is 1.1
  • every 5 seconds is recorded and counted, and the total number of successful user terminal token requests in the current 5 seconds is recorded as B, the total number of token request failures is counted as n, and all user terminals are
  • the user terminal that obtains the most token request times is denoted as b, and the number of token requests for the penalty user terminal b is determined to be m
  • the total number of tokens for the number of token request success times is ts
  • the total number of tokens for the number of token request failures is tf
  • the total number of tokens ts is less than or equal to the total number of global token buckets.
  • the total number of global tokens of the global token bucket is 100, and the number of token requests for the user terminal b is 5, and each time the penalty user terminal b requests 40 tokens, the number of successes of the user token request is Ts is 2 times, the total number of tokens for the number of token request success times is 80, and the remaining number of global tokens of the global token bucket is 20, then the number of user token request failures is 3, corresponding to the user request.
  • the number of failed tokens tf is 120.
  • Penalty In the current 5 seconds, if n>0, set the total number of specific tokens that punish the user terminal for a specific token bucket as the number of first preset tokens is max(2, ts-tf) to complete the penalty. The user terminal limits the total number of specific tokens for a particular token bucket.
  • the total number of specific tokens corresponding to the increased specific token bucket is multiplied by 1.1, and the total number of specific tokens of the specific token bucket is increased until the total number of specific tokens of the specific token bucket is increased. If the number of the preset rewards of the user terminal is satisfied, the penalty user terminal is no longer rewarded, and the number of the rewards may be set according to the user's needs, and the specific token of the specific token bucket is increased. The total number is less than the number of tokens in the global token bucket.
  • the first preset number can be set according to the needs of the server and the needs of the user.
  • the first preset number ranges from 93% to 98%.
  • the first preset number is 95%.
  • the terminal determines whether the recorded user terminal includes the user. The terminal, if it is included, rejects the first token request, and releases the corresponding working thread of the first token request; if not, after obtaining the first preset duration, the second token bucket is obtained again from the global token bucket.
  • the number of tokens requested by the user terminal is a global token; the second preset number may be set according to the needs of the server and the needs of the user.
  • the first preset number ranges from 89% to 92%.
  • the first preset number is 90%.
  • the first preset number is greater than the second preset number.
  • Determining that the total number of worker threads used to process the token request reaches a second preset number, indicating that the current worker thread also has partial bearer capability, may reject part of the first token request, and release the rejected first token request The corresponding worker thread. This ensures the stability of the data storage system.
  • the recorded user terminal includes the user terminal, that is, the user terminal with the most recorded token request times includes the user terminal, rejecting the first token request and releasing the first
  • the token requests the corresponding worker thread. Because the user terminal with the most requests has more threads, it is easy to cause a large load on the system. Therefore, the first token request of most user terminals can be processed normally, and the maximum number of requests for the token can be rejected. The first token request corresponding to the user terminal.
  • the number of tokens requested by the user terminal is obtained from the global token bucket again after the first preset duration.
  • the first token request of all user terminals can be processed normally, waiting The first preset duration. This ensures the stability of the data storage system.
  • the user terminal that penalizes the maximum number of token requests is punished.
  • This punishment only punishes the user terminal to ensure system stability, and ensures that other user terminals can apply for global tokens from the global token bucket.
  • the system can be quickly returned to stability, and the penalty user terminal is reduced to other user terminals.
  • the server automatically obtains all user terminals and limits the user terminals that have the most token request times. It does not require manual intervention and avoids the risk of manual operation errors. After the server is stable, it automatically opens the restriction on penalizing the user terminal to achieve Punish the rewards of the user terminal. This introduced penalty and reward can quickly limit the punishment of the user terminal, making the system quickly return to stability.
  • the method for acquiring the token provided by the user terminal in the embodiment of the present application can be applied to the user terminal. From the perspective of the user terminal, the embodiment of the present application provides a token acquiring method.
  • the embodiment of the present application further provides a token obtaining method, which is applied to a user terminal, and includes the following steps:
  • Step 31 Send a first token request of the user terminal to the server, so that the server determines, according to the first token request, the number of tokens requested by the user terminal; and the specific order corresponding to the preset user terminal Obtaining, in the card bucket, the number of tokens requested by the user terminal, the number of tokens in the specific token bucket being less than the number of tokens in the global token bucket; if the obtaining of the specific token fails, rejecting The first token request; if the specific token is successfully acquired, the requested token number of global tokens are obtained from the global token bucket.
  • Step 32 Receive feedback information sent by the server for the first token request.
  • the foregoing feedback information may include: if the server fails to obtain the global token, generating, according to a preset rejection policy, rejecting the rejection instruction of the first token request or waiting for a waiting instruction of a first preset duration.
  • the above feedback information may further include: successfully acquiring the number of global tokens of the requested token.
  • the user terminal can receive the global token of the requested number of tokens successfully obtained by the server.
  • the method further includes:
  • the user terminal sends the first token request to the server, and the server successfully obtains the specific token from the specific token bucket corresponding to the user terminal, and then successfully obtains the global token from the global token bucket.
  • the server successfully obtains the token directly from the global token bucket; since the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket, the user terminal cannot be from the global token bucket at one time. All the global tokens are obtained, so that other user terminals other than the user terminal can request the token from the global token bucket to prevent the system from being in an abnormal state that cannot provide services for other users for a long time.
  • the embodiment of the present application further provides a token obtaining apparatus, which is applied to a server, and includes:
  • the first receiving module 41 is configured to receive a first token request sent by the user terminal;
  • the first determining module 42 is connected to the first receiving module 41, and is configured to determine, according to the first token request, the number of tokens requested by the user terminal;
  • the first obtaining module 43 is connected to the first determining module 42, and is configured to obtain a specific token of the number of tokens requested by the user terminal from a specific token bucket corresponding to the preset user terminal.
  • the number of tokens in the specific token bucket is less than the number of tokens in the global token bucket;
  • the second obtaining module 44 is connected to the first obtaining module 43, and is configured to obtain, from the global token bucket, the number of tokens requested by the user terminal, if the specific token is successfully acquired. brand.
  • the server successfully obtains the specific token from the specific token bucket corresponding to the user terminal, and then successfully obtains the global token from the global token bucket, thereby limiting the
  • the user terminal obtains the token directly from the global token bucket; since the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket, the user terminal cannot obtain all the tokens from the global token bucket at one time.
  • the global token ensures that other user terminals than the user terminal can request a token from the global token bucket to prevent the system from being in an abnormal state that cannot provide services for other users for a long time.
  • the second obtaining module 44 is further configured to: if the number of tokens requested by the user terminal is successfully obtained from the preset global token bucket, Sending, to the user terminal, a number of global tokens requested by the user terminal.
  • the second obtaining module 44 is further configured to: if the global token fails to be obtained, reject the first token request or first at intervals according to a preset rejection policy After the preset duration, the number of tokens requested by the user terminal is obtained from the preset global token bucket.
  • the apparatus further includes: a first rejecting module; the first rejecting module is configured to: if the acquiring the specific token fails, rejecting the first token request; Or, if the obtaining of the specific token fails, the number of tokens requested by the user terminal is obtained from a specific token bucket corresponding to the preset user terminal again after the interval target preset duration. a token; or, if the obtaining of the specific token fails, sending a waiting instruction to the user terminal to indicate waiting for the first preset duration, so that the user terminal receives the waiting instruction, at intervals After waiting for the first preset duration in the instruction, the first token request is resent to the server.
  • a first rejecting module is configured to: if the acquiring the specific token fails, rejecting the first token request; Or, if the obtaining of the specific token fails, the number of tokens requested by the user terminal is obtained from a specific token bucket corresponding to the preset user terminal again after the interval target preset duration. a token; or, if the obtaining of the specific token fails,
  • the first token request includes a bandwidth requirement of the user terminal; the first determining module 42 is configured to: according to the bandwidth in the first token request The bandwidth corresponding to the demand is calculated, and the number of tokens requested by the user terminal is calculated.
  • the apparatus further includes: a first determining module, configured to determine whether the user terminal is a preset terminal that requires bandwidth limitation; and the first obtaining module 43 is configured to When it is determined that the user terminal is a preset terminal that requires bandwidth limitation, the number of tokens requested by the user terminal is obtained from a specific token bucket corresponding to the preset user terminal.
  • the first token request further includes an identifier of the user terminal
  • the first determining module is configured to: determine a preset user identifier that requires a bandwidth limitation, Whether the identifier of the user terminal is included, and if so, determining that the user terminal is a preset terminal that requires bandwidth limitation.
  • the apparatus further includes: a second determining module, configured to determine, if the user terminal is not the preset terminal that requires bandwidth limitation, determining that the user terminal requests Whether the number of tokens is greater than or equal to the total number of global tokens in the global token bucket; the first processing module is set to be greater than or equal to the total number of the global tokens in the global token bucket And setting the user terminal to a user terminal that requires a bandwidth limitation, setting a corresponding specific token bucket for the user terminal, and rejecting the first token request; and the third obtaining module is set to be less than The total number of the global tokens in the global token bucket is obtained from the global token bucket, and the number of tokens requested by the user terminal is obtained.
  • a second determining module configured to determine, if the user terminal is not the preset terminal that requires bandwidth limitation, determining that the user terminal requests Whether the number of tokens is greater than or equal to the total number of global tokens in the global token bucket
  • the first processing module is set to be greater than or equal to the total number
  • the device further includes:
  • the fourth obtaining module is configured to obtain the number of token requests and the number of token request failures of each user terminal in a preset time period; and the second processing module is configured to: when the sum of the number of token request failures of each user terminal is greater than Zero time, if the penalty user terminal is not recorded, the user terminal with the most token request times is determined as the penalty user terminal, and the total number of specific tokens in the specific token bucket corresponding to the determined penalty user terminal is set.
  • the number of the first preset tokens is smaller than the number of tokens in the global token bucket; and the third processing module is configured to be the number of token request failures of the respective user terminals.
  • the recorded penalty user terminal corresponds to the specific token bucket based on the number of set tokens that have been recorded to punish the specific token bucket corresponding to the user terminal.
  • the apparatus further includes: a fourth processing module, configured to: if the global token fails to be acquired, obtain a total number of working threads for processing the token request at the current time; Resolving the first token request, releasing the first token request, releasing the worker thread corresponding to the first token request; if the total number reaches the second preset number, and does not reach the first a predetermined number, determining whether the recorded user terminal includes the user terminal; if included, rejecting the first token request, and releasing the work thread corresponding to the first token request; If the total number of tokens requested by the user terminal is obtained from the global token bucket, the number of global tokens requested by the user terminal is obtained again; if the total number does not reach the second preset number, After the first preset duration is separated, the number of tokens requested by the user terminal is obtained from the global token bucket.
  • a fourth processing module configured to: if the global token fails to be acquired, obtain a total number of working threads for processing the token request at the current time; Resolving the first token
  • the embodiment of the present application further provides a token acquiring apparatus, which is applied to a user terminal, and includes:
  • the sending module 51 is configured to send a first token request of the user terminal to the server, so that the server determines, according to the first token request, the number of tokens requested by the user terminal; Obtaining, by the specific token bucket corresponding to the user terminal, the number of tokens requested by the user terminal, the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket; If the specific token fails, the first token request is rejected; if the specific token is successfully obtained, the number of tokens requested by the user terminal is obtained from the global token bucket.
  • the receiving module 52 is connected to the sending module 51 and configured to receive feedback information sent by the server for the first token request.
  • the feedback information includes: successfully acquiring the number of global tokens of the requested token;
  • the token obtaining apparatus further includes: an executing module, configured to perform writing or reading in the data storage system by using the requested number of tokens global tokens Out.
  • the embodiment of the present application further provides a server, including a processor and a machine readable storage medium, the machine readable storage medium storing machine executable instructions executable by the processor, the processor being The machine executable instructions cause the token acquisition method steps described above to be implemented.
  • the embodiment of the present application further provides a server, as shown in FIG. 7, including a processor 61, a communication interface 62, a memory 63, and a communication bus 64, wherein the processor 61 communicates The interface 62, the memory 63 completes communication with each other through the communication bus 64,
  • a memory 63 configured to store a computer program
  • the processor 61 when configured to execute the program stored on the memory 63, implements the steps of a token acquisition method provided by the embodiment of the present application from the perspective of the server.
  • the embodiment of the present application further provides a user terminal, including a processor and a machine readable storage medium, the machine readable storage medium storing machine executable instructions executable by the processor, the processor being The machine executable instructions cause the token acquisition method steps described above to be implemented.
  • the embodiment of the present application further provides a user terminal, as shown in FIG. 8, including a processor 71, a communication interface 72, a memory 73, and a communication bus 74, wherein the processor 71, Communication interface 72, memory 73 completes communication with each other via communication bus 74,
  • a memory 73 configured to store a computer program
  • the processor 71 when configured to execute the program stored on the memory 73, implements the steps of a token acquisition method provided by the user terminal in the embodiment of the present application.
  • the communication bus mentioned by the above user terminal/server may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus.
  • PCI Peripheral Component Interconnect
  • EISA Extended Industry Standard Architecture
  • the communication bus can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, only one thick line is shown in the figure, but it does not mean that there is only one bus or one type of bus.
  • the communication interface is used for communication between the above user terminal/server and other devices.
  • the memory may include a random access memory (RAM), and may also include a non-volatile memory (NVM), such as at least one disk storage.
  • RAM random access memory
  • NVM non-volatile memory
  • the memory may also be at least one storage device located away from the aforementioned processor.
  • the above processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; or may be a digital signal processing (DSP), dedicated integration.
  • CPU central processing unit
  • NP network processor
  • DSP digital signal processing
  • ASIC Application Specific Integrated Circuit
  • FPGA Field-Programmable Gate Array
  • the method provided in this embodiment of the present application can be applied to a user terminal.
  • the user terminal may be: a desktop computer, a portable computer, a smart mobile terminal, a server, or the like. It is not limited herein, and any user terminal that can implement the present application belongs to the protection scope of the present application.
  • the embodiment of the present application provides a computer readable storage medium, where the computer includes a computer program, and the computer program is executed by a processor to implement the token acquiring method. step.
  • the embodiment of the present application provides a computer readable storage medium, where the computer includes a computer program, and the computer program is executed by the processor to implement the token acquiring method. step.
  • the embodiment of the present application provides a computer program product comprising instructions that, when run on a computer, cause the computer to perform the token acquisition method steps described above.
  • the embodiment of the present application provides a computer program product comprising instructions, which when executed on a computer, causes the computer to execute the token acquisition method steps described above.
  • the embodiment of the present application provides a computer program that, when run on a computer, causes the computer to perform the steps of the token acquisition method described above.
  • the embodiment of the present application provides a computer program that, when run on a computer, causes the computer to perform the steps of the token acquisition method described above.
  • the method for acquiring a token, the server, the user terminal, and the medium provided by the embodiment of the present application successfully acquires a specific token from a specific token bucket corresponding to the user terminal for the user terminal that needs to request the token.
  • the global token is obtained from the global token bucket, so that the user terminal is directly obtained from the global token bucket; since the number of tokens in the specific token bucket is smaller than the number of tokens in the global token bucket, In this way, the user terminal cannot obtain all the global tokens from the global token bucket at one time, thereby ensuring that other user terminals other than the user terminal can request the token from the global token bucket, thereby preventing the system from being unable to be used for other time.
  • the abnormal state of the service provided by the user is a specific token bucket corresponding to the user terminal for the user terminal that needs to request the token.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

一种令牌获取方法、装置、服务器、用户终端及介质,涉及通信技术领域,其中,该令牌获取方法包括:接收用户终端发送的第一令牌请求;根据该第一令牌请求,确定该用户终端所请求的令牌数量;判断该用户终端是否为预设的需要带宽限制的终端;如果是该预设的需要带宽限制的终端,则从预设的该用户终端对应的特定令牌桶中获取该第一令牌请求该所请求的令牌数量个特定令牌,该特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量;判断是否成功获取该特定令牌;如果获取该特定令牌失败,则拒绝该第一令牌请求;如果成功获取该特定令牌,则从该全局令牌桶中获取该第一令牌请求所请求的令牌数量个全局令牌。

Description

一种令牌获取方法、装置、服务器、用户终端及介质
本申请要求于2017年12月19日提交中国专利局、申请号为201711376057.1发明名称为“一种令牌获取方法、装置、服务器、终端设备及介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及通信技术领域,特别是涉及一种令牌获取方法、装置、服务器、用户终端及介质。
背景技术
随着云存储技术的迅速发展,出现了很多数据存储***为用户提供数据存储服务。例如:对象存储***,用户能够与该对象存储***交互,实现对象的上传和下载等。由于数据存储***面向的用户众多,而这些用户又共享有限的带宽资源,因此需要对各个用户使用的带宽资源进行限制。
目前,有些数据存储***,如:对象存储***,采用了全局令牌桶技术来实现带宽资源限制,该对象存储***包括前端的服务器和后端的存储***。
具体的,用户终端在向后端的存储***发送上传或下载等请求前,为了获得带宽资源,需要先向前端的服务器发送申请令牌的请求;前端的服务器根据该请求,通过预设的全局令牌桶获取令牌,将该令牌分配给用户终端,并通知用户终端;用户终端收到该通知后,用分配的令牌对应的带宽资源与后端的存储***交互,实现对象的上传或下载。
这种令牌获取方式可能会存在一个用户一次性获得了全局令牌桶中的所有的令牌的情况,则其他用户无法通过全局令牌桶获得令牌,这样会导致其他用户的请求不能及时地获取到全局令牌,影响其他用户的使用,而且可能导致***长时间处于无法为其他用户提供服务的异常状态。
发明内容
本申请实施例的目的在于提供一种令牌获取方法、装置、服务器、用户终端及介质,以防止***长时间处于无法为其他用户提供服务的异常状态。具体技术方案如下:
第一方面,本发明本申请实施例提供了一种令牌获取方法,应用于服务 器,上述方法包括:接收用户终端发送的第一令牌请求;根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;如果成功获取所述特定令牌,则从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌;其中,所述特定令牌桶中的令牌数量小于所述全局令牌桶中的令牌数量。
在一种实施方式中,所述方法还包括:如果成功从预设的全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌,则向所述用户终端发送所述用户终端所请求的令牌数量个全局令牌。
在一种实施方式中,所述方法还包括:如果获取全局令牌失败,则按照预设的拒绝策略,拒绝所述第一令牌请求或者在间隔第一预设时长后,再次从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
在一种实施方式中,所述方法还包括:如果获取所述特定令牌失败,则拒绝所述第一令牌请求;或者,如果获取所述特定令牌失败,则在间隔目标预设时长后,再次从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;或者,如果获取所述特定令牌失败,则向所述用户终端发送用于指示等待第一预设时长的等待指令,以使得所述用户终端接收所述等待指令,在间隔所述等待指令中的所述第一预设时长后,重新向所述服务器发送所述第一令牌请求。
在一种实施方式中,所述第一令牌请求中包含所述用户终端的带宽需求;所述根据所述第一令牌请求,确定所述用户终端所请求的令牌数量,包括:根据所述第一令牌请求中所述带宽需求对应的带宽,计算所述用户终端所请求的令牌数量。
在一种实施方式中,所述从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌之前,所述方法还包括:判断所述用户终端是否为预设的需要带宽限制的终端;所述从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌,包括:当判断出所述用户终端为预设的需要带宽限制的终端时,从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌。
在一种实施方式中,所述第一令牌请求中还包含所述用户终端的标识; 判断所述用户终端是否为预设的需要带宽限制的终端,包括:判断预设的需要带宽限制的用户标识中,是否包含所述用户终端的标识,如果是,判定所述用户终端为预设的需要带宽限制的终端。
在一种实施方式中,所述方法还包括:如果所述用户终端不为预设的需要带宽限制的终端,则判断所述用户终端所请求的令牌数量是否大于或等于所述全局令牌桶中的全局令牌的总数量;如果所述用户终端所请求的令牌数量大于或等于所述全局令牌桶中的所述全局令牌的总数量,则将所述用户终端设置为需要带宽限制的用户终端,为所述用户终端设置对应的特定令牌桶,并拒绝所述第一令牌请求;如果所述用户终端所请求的令牌数量小于所述全局令牌桶中的所述全局令牌的总数量,则从所述全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
在一种实施方式中,所述方法还包括:获取预设时间内,各个用户终端的令牌请求次数及令牌请求失败次数;当所述各个用户终端的令牌请求失败次数之和大于零时,如果未记录有惩罚用户终端,则将令牌请求次数最多的用户终端确定为惩罚用户终端,并将所确定的惩罚用户终端所对应特定令牌桶中特定令牌的总数量,设置为第一预设令牌数量,所述第一预设令牌数量小于所述全局令牌桶中的令牌数量;当所述各个用户终端的令牌请求失败次数之和等于零时,如果已记录有惩罚用户终端,则基于已记录的惩罚用户终端所对应特定令牌桶的已设置的令牌数量,增大已记录的惩罚用户终端对应特定令牌桶的特定令牌数量,得到增大后的特定令牌桶的特定令牌的总数量,所述增大后的特定令牌桶的特定令牌的总数量小于全局令牌桶中的令牌数量。
在一种实施方式中,所述方法还包括:如果获取全局令牌失败,获取当前时间用于处理令牌请求的工作线程的总数量;若所述总数量达到第一预设数量,则拒绝所述第一令牌请求,释放与所述第一令牌请求对应的工作线程;若所述总数量达到第二预设数量,且未达到第一预设数量,则判断所记录的惩罚用户终端中,是否包含所述用户终端;如果包含,则拒绝所述第一令牌请求,并释放该第一令牌请求对应的工作线程;如果不包含,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌;若所述总数量未达到第二预设数量,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
第二方面,本申请实施例提供了一种令牌获取方法,应用于用户终端, 上述方法包括:
发送用户终端的第一令牌请求至服务器,以使所述服务器根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;从预设的所述用户终端对应的特定令牌桶中获取所述用户终端所请求的令牌数量个特定令牌,所述特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量;如果获取所述特定令牌失败,则拒绝所述第一令牌请求;如果成功获取所述特定令牌,则从所述全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌;接收由所述服务器针对所述第一令牌请求发送的反馈信息。
在一种实施方式中,所述反馈信息包括:成功获取所述用户终端所请求的令牌数量个全局令牌;所述方法还包括:利用所述用户终端所请求的令牌数量个全局令牌,执行在数据存储***中的写入或读出。
第三方面,本申请实施例提供了一种令牌获取装置,应用于服务器,包括:第一接收模块,设置为接收用户终端发送的第一令牌请求;第一确定模块,设置为根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;第一获取模块,设置为从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌,所述特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量;第二获取模块,设置为如果成功获取所述特定令牌,则从所述全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
第四方面,本申请实施例提供了一种令牌获取装置,应用于用户终端,包括:发送模块,设置为发送用户终端的第一令牌请求至服务器,所述第一令牌请求用于通过服务器根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;预设的所述用户终端对应的特定令牌桶中获取所述第一令牌请求所述所请求的令牌数量个特定令牌,所述特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量;如果获取所述特定令牌失败,则拒绝所述第一令牌请求;如果成功获取所述特定令牌,则从所述全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌;接收模块,设置为接收由所述服务器针对所述第一令牌请求发送的反馈信息。
第五方面,本申请实施例提供了一种服务器包括:处理器、通信接口、存储器和通信总线,其中,处理器,通信接口,存储器通过总线完成相互间的通信;存储器,设置为存放计算机程序;处理器,设置为执行存储器上所 存放的程序,实现第一方面所述的方法步骤。
第六方面,本申请实施例提供了一种用户终端包括处理器、通信接口、存储器和通信总线,其中,处理器,通信接口,存储器通过总线完成相互间的通信;存储器,设置为存放计算机程序;处理器,设置为执行存储器上所存放的程序,实现第二方面所述的方法步骤。
第七方面,本申请实施例提供了一种计算机可读存储介质,所述存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现第一方面所述的方法步骤。
第八方面,本申请实施例提供了一种计算机可读存储介质,所述存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现第二方面所述的方法步骤。
第九方面,本申请实施例提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述第一方面所述的方法步骤。
第十方面,本申请实施例提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述第二方面所述的方法步骤。
第十一方面,本申请实施例提供了一种计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面所述的方法步骤。
第十二方面,本申请实施例提供了一种计算机程序,当其在计算机上运行时,使得计算机执行上述第二方面所述的方法步骤。
本申请实施例所提供方案中,对需要请求令牌的用户终端而言,从用户终端对应的特定令牌桶成功获取特定令牌,再从全局令牌桶中获取全局令牌,这样限制该用户终端直接从全局令牌桶中获取令牌;由于该特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量,这样该用户终端无法一次性从全局令牌桶中获得所有的全局令牌,从而保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态。
当然,实施本申请的任一产品或方法必不一定需要同时达到以上所述的所有优点。
附图说明
为了更清楚地说明本申请实施例和现有技术的技术方案,下面对实施例和现有技术中所需要使用的附图作简单地介绍,显而易见地,下面描述中的 附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例应用于服务器的令牌获取方法的第一种流程示意图;
图2为本申请实施例的应用于服务器的令牌获取方法的第二种流程示意图;
图3为本申请实施例的令牌获取方法中对惩罚用户终端进行奖惩的实现流程示意图;
图4为本申请实施例应用于用户终端侧的令牌获取方法的流程示意图;
图5为本申请实施例的应用于服务器的令牌获取装置的结构示意图;
图6为本申请实施例的应用于用户终端的令牌获取装置的结构示意图;
图7为本申请实施例的服务器的结构示意图;
图8为本申请实施例的用户终端的结构示意图。
具体实施方式
为使本申请的目的、技术方案、及优点更加清楚明白,以下参照附图并举实施例,对本申请进一步详细说明。显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
现有的实现方式,虽然实现了对用户使用的带宽资源进行限制,然而本申请发明人在实现本申请的过程中,发现现有技术对用户使用的带宽资源进行限制的方式,会出现如下问题:
如果一个用户一次性获得了全局令牌桶中的所有的令牌,则其他用户无法通过全局令牌桶获得令牌,导致其他用户的请求被拒绝,或者,其他用户的请求需要等待预设时长,在预设时长内全局令牌桶自动补给令牌,在全局令牌桶补给后满足该其他用户的请求时,其他用户再通过上述请求从全局令牌桶获得令牌,这样其他用户的请求可能等待全局令牌桶补给令牌的时间过长,从而可能导致***长时间处于无法为其他用户提供服务的异常状态。
基于现有技术存在的技术问题,发明人考虑到采用本申请实施例提供一种令牌获取方法、装置、服务器、用户终端及介质,对于需要请求令牌的用户终端,从该用户终端对应的特定令牌桶成功获取特定令牌,再从全局令牌桶中获取全局令牌,这样限制该用户终端直接从全局令牌桶中获取令牌。而 由于该特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量,这样该用户终端无法一次性从全局令牌桶中获得所有的全局令牌,从而保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态。
为便于理解,首先介绍一下,本申请实施例中特定令牌桶和全局令牌桶。特定令牌桶和全局令牌桶可以统称为令牌桶。令牌桶可以看作是一个存放预设数量令牌的容器。令牌桶具有令牌桶控制机制,该控制机制可以是按照设定速度或预设频率向桶中放置令牌,当然并不局限于此。并且,如果该令牌桶中的令牌不被获取,或者被获取的速度小于产生的速度,令牌就会不断地增多,直到把令牌桶填满。当令牌桶中令牌超出令牌桶的总令牌数量时,多出的令牌会溢出该令牌桶,这样令牌桶中令牌不再增加。
令牌桶的这种控制机制,可以实现带宽限制。也就是,用户请求从一个令牌桶中申请令牌,只有令牌申请成功才能进行后续操作,如果令牌申请失败,则需要等待或者被告知申请失败。这样达到全局带宽限制的作用。
基于对特定令牌桶和全局令牌桶的介绍,下面对本申请实施例所提供的令牌获取方法进行介绍。
本申请实施例针对服务器所提供的令牌获取方法,可以应用于数据存储***的服务器。
第一方面,为了避免一个用户终端一次性从全局令牌桶中获得所有的全局令牌,保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态,从服务器的角度,本申请实施例提供了一种令牌获取方法。
其中,本申请实施例所提供的一种令牌获取方法,应用于服务器,该方法可以包括如下步骤A1-A4:
步骤A1,接收用户终端发送的第一令牌请求;
步骤A2,根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;
步骤A3,从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;
步骤A4,如果成功获取所述特定令牌,则从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌;
其中,所述特定令牌桶中的令牌数量小于所述全局令牌桶中的令牌数量。
可选地,在一种实施方式中,所述方法还可以包括:
步骤A5,如果成功从预设的全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌,则向所述用户终端发送所述用户终端所请求的令牌数量个全局令牌。
可选地,在一种实施方式中,所述方法还可以包括:
步骤A6,如果获取全局令牌失败,则按照预设的拒绝策略,拒绝所述第一令牌请求或者在间隔第一预设时长后,再次从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
可选地,在一种实施方式中,所述方法还可以包括:
步骤A71,如果获取所述特定令牌失败,则拒绝所述第一令牌请求;或者,
步骤A72,如果获取所述特定令牌失败,则在间隔目标预设时长后,再次从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;或者,
步骤A73,如果获取所述特定令牌失败,则向所述用户终端发送用于指示等待第一预设时长的等待指令,以使得所述用户终端接收所述等待指令,在间隔所述等待指令中的所述第一预设时长后,重新向所述服务器发送所述第一令牌请求。
可选地,在一种实施方式中,所述第一令牌请求中包含所述用户终端的带宽需求;所述根据所述第一令牌请求,确定所述用户终端所请求的令牌数量,包括:根据所述第一令牌请求中所述带宽需求对应的带宽,计算所述用户终端所请求的令牌数量。
可选地,在一种实施方式中,所述从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌之前,所述方法还包括:
步骤A8,判断所述用户终端是否为预设的需要带宽限制的终端;
相应的,所述从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌,包括:当判断出所述用户终端为预设的需要带宽限制的终端时,从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌。
可选地,在一种实施方式中,所述第一令牌请求中还包含所述用户终端 的标识;判断所述用户终端是否为预设的需要带宽限制的终端,包括:判断预设的需要带宽限制的用户标识中,是否包含所述用户终端的标识,如果是,判定所述用户终端为预设的需要带宽限制的终端。
可选地,在一种实施方式中,所述方法还可以包括:
步骤A9,如果所述用户终端不为预设的需要带宽限制的终端,则判断所述用户终端所请求的令牌数量是否大于或等于所述全局令牌桶中的全局令牌的总数量;
步骤A10,如果所述用户终端所请求的令牌数量大于或等于所述全局令牌桶中的所述全局令牌的总数量,则将所述用户终端设置为需要带宽限制的用户终端,为所述用户终端设置对应的特定令牌桶,并拒绝所述第一令牌请求;
步骤A11,如果所述用户终端所请求的令牌数量小于所述全局令牌桶中的所述全局令牌的总数量,则从所述全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
可选地,在一种实施方式中,所述方法还可以包括:
步骤A12,获取预设时间内,各个用户终端的令牌请求次数及令牌请求失败次数;
步骤A13,当所述各个用户终端的令牌请求失败次数之和大于零时,如果未记录有惩罚用户终端,则将令牌请求次数最多的用户终端确定为惩罚用户终端,并将所确定的惩罚用户终端所对应特定令牌桶中特定令牌的总数量,设置为第一预设令牌数量,所述第一预设令牌数量小于所述全局令牌桶中的令牌数量;
步骤A14,当所述各个用户终端的令牌请求失败次数之和等于零时,如果已记录有惩罚用户终端,则基于已记录的惩罚用户终端所对应特定令牌桶的已设置的令牌数量,增大已记录的惩罚用户终端对应特定令牌桶的特定令牌数量,得到增大后的特定令牌桶的特定令牌的总数量,所述增大后的特定令牌桶的特定令牌的总数量小于全局令牌桶中的令牌数量。
可选地,在一种实施方式中,在设置有惩罚用户终端的前提下,所述方法还可以包括:
步骤A15,如果获取全局令牌失败,获取当前时间用于处理令牌请求的工作线程的总数量;
步骤A16,若所述总数量达到第一预设数量,则拒绝所述第一令牌请求,释放与所述第一令牌请求对应的工作线程;
步骤A17,若所述总数量达到第二预设数量,且未达到第一预设数量,则判断所记录的惩罚用户终端中,是否包含所述用户终端;如果包含,则拒绝所述第一令牌请求,并释放该第一令牌请求对应的工作线程;如果不包含,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌;
步骤A18,若所述总数量未达到第二预设数量,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
为了方案清楚,后续结合附图1-3对本申请实施例从服务器角度所提供的一种令牌获取方法进行介绍。关于上述的本申请实施例所提供的一种令牌获取方法的各个步骤的详细介绍内容,可以参见图1-图3所对应实施例中相应步骤的介绍内容。
下面结合附图1-3对本申请实施例从服务器角度所提供的一种令牌获取方法进行介绍。
如图1所示,本申请实施例所提供的一种令牌获取方法,应用于服务器,该方法可以包括如下步骤:
步骤101,接收用户终端发送的第一令牌请求。
在进入上述数据存储***之前可以通过用户名和密码验证登录,从而保证该用户名和用户密码,与预先存储用户信息的数据库中的用户名和用户密码相匹配,保护该用户的隐私。其中,该用户名即为用户访问该数据存储***所利用的用户标识。
用户终端可以为用户预先定制固定流量或者用户使用计费流量的终端设备,并且,该用户终端可以为不同品牌类型的终端设备。任何可以实现本申请实施例的用户终端均属于本申请实施例的保护范围。需要强调的是,用户终端为用户访问数据存储***所使用的终端。并且,对于一个用户而言,该用户可以在不同的用户终端上利用同一用户标识访问该数据存储***,而该数据存储***以用户标识作为区分不同用户的依据。本申请实施例所言的用户终端实质上等同于用户。
步骤102,根据该第一令牌请求,确定该用户终端所请求的令牌数量。
在一种具体实施例中,第一令牌请求可以包括该用户终端所请求的令牌数量。上述步骤102确定该用户终端所请求的令牌数量可以直接从第一令牌请求中获得所请求的令牌数量,方便快捷。
在其他具体实施例中,上述第一令牌请求中包含该用户终端的带宽需求。上述步骤102可以通过如下步骤,确定该用户终端所请求的令牌数量:
根据第一令牌请求中带宽需求对应的带宽,计算该用户终端所请求的令牌数量。
可选地,在一种实现方式中,根据第一令牌请求中带宽需求对应的带宽,计算该用户终端所请求的令牌数量,可以包括如下步骤:
获取预设带宽的大小与预设令牌的大小的对应关系;将第一令牌请求中的带宽需求对应的带宽与所获取的对应关系,按照预设运算规则进行运算;计算出该用户终端所请求的令牌数量。其中,所谓的令牌的大小指:令牌的数量。其中,该预设运算规则可以为除法运算规则或乘法运算规则。当然这里的预设运算规则仅仅是举例说明,任何可以实现本申请实施例的预设运算规则,均属于本申请实施例的保护范围,在此不一一举例。
例如:应用于除法运算规则时,上述步骤的具体实现步骤如下:上述预设带宽的大小与预设令牌的大小的对应关系为每个令牌对应的带宽大小,将该第一令牌请求中的带宽需求对应的带宽,除以每个令牌对应的带宽大小,得到商,将商作为该用户终端所请求的令牌数量。
示例性的,一个令牌允许发送1Byte数据,则每个令牌对应带宽大小为1B,第一令牌请求中带宽需求对应的带宽大小为100B,则确定的所请求的令牌数量为100个。需要说明的是,B是常用的带宽流量的单位符号。其中,B是字节的符号,字节是数据或数据流量的基本单位。1B就是1个Byte(字节)。
例如:应用于乘法运算规则时,上述步骤的具体实现步骤如下:上述预设带宽的大小与预设令牌的大小的对应关系为,预设令牌的大小与预设带宽的大小的比值,将该第一令牌请求中的带宽需求对应的带宽,乘以该比值,得到积,将积作为该用户终端所请求的令牌数量。
示例性的,10个令牌允许发送100Byte数据,则10个令牌对应带宽大小为100B,则令牌大小对应带宽大小的比值为0.1个/B,第一令牌请求中带宽需求对应的带宽大小为1000B,则确定的所请求的令牌数量为100个。可选的,每个令牌对应的对应带宽大小的取值范围可以为[1B,0.1KB],该取值范 围不作限定。其中,0.1KB就是0.1千Byte。
步骤103,判断该用户终端是否为预设的需要带宽限制的终端。如果是,则执行步骤104;
其中,预设的需要带宽限制的终端可以通过多种方式确定:
在一种具体实施例中,将预先设置的用户终端作为预设的需要带宽限制的终端。这样可以方便记录用户终端。用户终端作为预设的需要带宽限制的终端时,可以先存储该用户终端的标识,即使用用户终端的用户的用户标识,这样,有利于后期及时分配与标识对应的特定令牌桶,方便实现该用户终端的带宽限制。此时,所述判断该用户终端是否为预设的需要带宽限制的终端,可以包括:判断预先记录的预设的需要带宽限制的用户标识中,是否包含该用户终端的标识,如果包含,则说明该用户终端为预先记录的预设的需要带宽限制的终端。而如果不包含,判断该用户终端所请求的令牌数量大于或等于该全局令牌桶中的全局令牌的总数量时,将该用户终端的标识记录为预设的需要带宽限制的用户标识,将该用户终端作为预设的需要带宽限制的终端。
在其他具体实施例中,可以将具有固定带宽需求的用户终端作为预设的需要带宽限制的终端。这样可以满足不同的用户需求。此时,该第一令牌请求中可以包括带宽需求,判断该用户终端是否为预设的需要带宽限制的终端,可以包括:判断该带宽需求是否为预设的固定带宽需求,如果是,判定该用户终端为预设的需要带宽限制的终端。
步骤104,从预设的用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌,该特定令牌桶的令牌数量小于全局令牌桶的令牌数量。
上述特定令牌桶的令牌数量小于全局令牌桶的令牌数量,是指特定令牌桶的总令牌数量小于全局令牌桶的总令牌数量。这样可以防止用户终端一次性获得全局令牌桶中所有的令牌,以防止***长时间处于无法为其他用户提供服务的异常状态。
其中,为用户终端预先设置对应的特定令牌桶,是为了方便对每个用户终端进行针对性地限制。
步骤105,判断是否成功获取特定令牌,如果否,则执行步骤106;如果是,则执行步骤107。
步骤106,如果获取特定令牌失败,则拒绝所述第一令牌请求。
因为该特定令牌桶的特定令牌可能被拿去使用,或者可能被用过但释放,也可能被自动添加,所以特定令牌桶中的特定令牌的令牌数一直在变化。在特定令牌桶中的特定令牌的令牌数小于所请求的令牌数量时,则特定令牌桶不满足所请求的令牌数量,此时,服务器获取特定令牌失败。由于特定令牌桶是为了防止用户终端一次性从全局令牌桶中获得所有的全局令牌,因此这里特定令牌桶不满足用户终端所请求的令牌数量,则直接拒绝该第一令牌请求。
需要说明的是,在具体应用中,如果获取特定令牌失败,该服务器可以按照预设的拒绝策略来选择如下的任一种方式进行后续处理:
拒绝所述第一令牌请求;或者,
在间隔目标预设时长后,再次从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;或者,
如果获取所述特定令牌失败,则向所述用户终端发送用于指示等待第一预设时长的等待指令,以使得所述用户终端接收所述等待指令,在间隔所述等待指令中的所述第一预设时长后,重新向所述服务器发送所述第一令牌请求。
其中,所述的拒绝所述第一令牌请求的实现方式可以包括:产生拒绝第一令牌请求的拒绝指令,当然并不局限于此。需要强调的是,该服务器所选择的处理方法并不局限于上述所给出的三种方式。
这样用户终端可以针对该拒绝指令和等待指令进行处理,比如,根据拒绝指令,用户终端本次无法后端数据存储***交互,用户终端可以发送新的第一令牌请求。比如,根据等待指令,在等待第一预设时长达到时,重新发送该第一令牌请求。这样服务器可以对用户终端的第一令牌请求进行反馈,完成用户终端与服务器之间交互。
步骤107,从全局令牌桶中获取所请求的令牌数量个全局令牌。
从特定令牌桶中成功获取特定令牌时,则全局令牌桶中获取所请求的令牌数量个全局令牌。这样相当于串联了特定令牌桶和全局令牌桶,从而实现对用户终端的带宽限制。
应用本申请实施例中,对于请求令牌的用户终端而言,从用户终端对应的特定令牌桶成功获取特定令牌,再从全局令牌桶中获取全局令牌,这样限制该用户终端直接从全局令牌桶中获取令牌;由于该特定令牌桶中的令牌数 量小于全局令牌桶中的令牌数量,这样该用户终端无法一次性从全局令牌桶中获得所有的全局令牌,从而保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态。
当然,本申请实施例中,在全局令牌桶之前,可以只串联一个特定令牌桶。
在其他实施例中,在全局令牌桶之前,可以串联多个特定令牌桶。例如:该多个特定令牌桶包括第一特定令牌桶及第二特定令牌桶。在全局令牌桶之前,可以串联多个特定令牌桶具体的实现过程,在全局令牌桶之前串联一个第一特定令牌桶,然后在该第一特定令牌桶之前,再串联一个第二特定令牌桶,该第二特定令牌桶的令牌数量小于该第一令牌桶的令牌数量。也就是说,对于请求令牌的用户终端而言,利用两层特定令牌桶进行带宽限制,这样该用户终端一次性可申请全局令牌桶的全局令牌,所对应的数量就变少了,进一步保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态。
上述该第一特定令牌桶之前,再串联一个第二特定令牌桶的实现过程,与全局令牌桶之前,只串联了一个特定令牌桶的实现过程相同或者相似,在此不再赘述。这样,通过串联第一特定令牌桶和第二特定令牌桶,对于请求令牌的用户终端而言,从用户终端对应的第二特定令牌桶成功获取特定令牌后,再从用户终端对应的第一特定令牌桶中获取特定令牌,在从第一特定令牌桶中获取特定令牌成功后,才从全局令牌桶中获取全局令牌。当然以上设置两层特定令牌桶只是举例,任何可以利用本申请实施的特定令牌桶,保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌的方式,均属于本申请实施例的保护范围。
在其他具体实施方式中,基于图1的基础上,增加了步骤108至步骤114。如图2所示,步骤103,包括:判断预先记录的预设的需要带宽限制的用户标识中,是否包含该用户终端的标识。也就是,判断通过该用户终端访问该服务器和该数据存储***的用户是否为需要带宽限制的用户。如果是,则执行步骤104;如果否,也就是,该用户终端不为预设的需要带宽限制的终端,则执行步骤112;
步骤104,从预设的用户终端对应的特定令牌桶中获取所请求的令牌数量个特定令牌,该特定令牌桶的令牌数量小于全局令牌桶的令牌数量。
步骤105,判断是否成功获取特定令牌;如果是,则执行步骤108。
图2中的步骤104和步骤105,与图1中的步骤104和步骤105相同,均能够达到相同或相似的技术效果,在此不再赘述。
步骤108,判断是否成功从全局令牌桶中获取所请求的令牌数量个全局令牌。如果是,则执行步骤109,如果否,则执行步骤110;
步骤109,向该用户终端发送该所请求的令牌数量个的全局令牌;
其中,向该用户终端发送所请求的令牌数量个的全局令牌,该用户终端可以利用所请求的令牌数量个全局令牌,执行在数据存储***中的写入或读出。步骤110,按照预设的拒绝策略,拒绝所述第一令牌请求,或者等待第一预设时长,并执行步骤111。
也就是说,如果获取全局令牌失败,服务器可以按照预设的拒绝策略,拒绝所述第一令牌请求或者在间隔第一预设时长后,再次从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌,可以理解的是,获取全局令牌桶的全局令牌失败,服务器等待第一预设时长,从而达到限流的效果。但是,服务器也可以按照预设的拒绝策略拒绝所述第一令牌请求,避免该用户终端影响除该用户终端以外的其他用户终端的正常服务。另外,服务器如果获取全局令牌失败,该服务器可以向所述用户终端发送用于指示等待第一预设时长的等待指令,以使得所述用户终端接收所述等待指令,在间隔所述等待指令中的所述第一预设时长后,重新向所述服务器发送所述第一令牌请求。
步骤111,在等待该第一预设时长时,判断该第一令牌请求所等待的第一预设时长是否到达;如果否,则继续执行步骤111,如果是,则执行步骤108,若判断从全局令牌桶中获取所请求的令牌数量个全局令牌失败,则执行按照预设的拒绝策略拒绝所述第一令牌请求的步骤,该全局令牌桶每隔第二预设时长,增加预设数量个全局令牌。
这里按照每间隔第二预设时长写入的预设数量的全局令牌,预设数量可以为固定的数值,这样可以实现部分带宽的限制。
上述第一预设时长和第二预设时长可以根据用户需要进行设置,在此不做限定。第一预设时长可以和第二预设时长相同,第一预设时长与第二预设 时长也可以不同。
步骤112,判断该所请求的令牌数量是否大于或等于该全局令牌桶中的全局令牌的总数量;如果是,则执行步骤113,如果否,则执行步骤114;
步骤113,将用户终端的标识记录为预设的需要带宽限制的用户标识,为该用户终端设置对应的特定令牌桶,并拒绝该第一令牌请求;
步骤114,从所述全局令牌桶中获取所请求的令牌数量个全局令牌。
判断该所请求的令牌数量大于或等于该全局令牌桶中的全局令牌的总数量时,表明该用户终端将可能一次申请全局令牌桶的所有全局令牌,该用户终端称为异常流量的用户终端。因此,需要对该异常流量的用户终端的带宽进行限制。
示例性的,基于上述图1以及图2执行步骤的基础上,全局令牌桶每1秒内增加10个全局令牌。全局令牌桶初始的全局令牌的数量为25个,需要带宽限制的用户终端所请求的令牌数量为30个,在1秒后,获取全局令牌桶的全局令牌的数量为35个,此时,全局令牌桶中的全局令牌的数量大于所请求的令牌数量,这样用户终端可以从全局令牌桶中获取全局令牌。这样该用户终端无法一次性从全局令牌桶中获得所有的全局令牌,从而保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态。
通过记录该用户终端的标识为预设的需要带宽限制的用户标识,并设置与标识对应的特定令牌桶,记录该用户终端的标识方便快速发现异常流量的用户终端,利用该特定令牌桶实现对该用户终端的带宽进行限制。这样可以在异常流量发生时,快速定位到异常流量的根源,避免***长时间处于异常状态。
这里设置的与标识对应的特定令牌桶,可以数据存储***中已经存在的特定令牌桶,也可以新建立的特定令牌桶。
该所请求的令牌数量等于或超出该全局令牌桶中的全局令牌的总数量,表明第一令牌请求的所请求的令牌数量不合理,该用户终端将可能一次申请全局令牌桶的所有全局令牌,这样该用户终端可能影响除该用户终端以外的其他用户终端从全局令牌桶中请求令牌,因此为了防止***长时间处于无法为其他用户提供服务的异常状态,可以拒绝该第一令牌请求。
判断预先记录的预设的需要带宽限制的用户标识中,不包含该用户终端 的标识,并且判断该所请求的令牌数量小于该全局令牌桶中的全局令牌的总数量时,用户终端可以从全局令牌桶中获取所请求的令牌数量个全局令牌。
应用本申请实施例,判断所请求的令牌数量大于或等于该全局令牌桶中的全局令牌的总数量的用户终端,可以自动的发现异常流量的用户终端,然后为所述用户终端设置对应的特定令牌桶,并拒绝该第一令牌请求,可以控制该异常流量的用户终端,保证数据存储***的稳定性。
上述具体实现流程举例如下:
用户终端发送第一令牌请求至服务器;
服务器接收到该第一令牌请求,判断预先记录的预设的需要带宽限制的用户标识中不包含该用户终端的标识S,并确定所请求的令牌数量为200个;
此时,全局令牌桶的全局令牌的总数量为100个,由于200大于100,记录该用户终端的标识S为需要带宽限制的用户标识,为该用户终端设置一个特定令牌桶,该特定令牌桶中有90个特定令牌,并且拒绝这次的第一令牌请求;
用户终端重新再发送新的第一令牌请求至服务器;
服务器接收到该新的第一令牌请求,判断预先记录的预设的需要带宽限制的标识中包含该用户终端的标识S,并确定新的所请求的令牌数量为70个,则从特定令牌桶内获取特定令牌成功,然后从全局令牌桶中获取70个全局令牌。
需要说明的是,关于上述步骤A12-A14的详细流程,可以参照图3。如图3所示,步骤A12-A14的详细流程可以包括如下步骤:
步骤201,获取预设时间内,所有用户终端的令牌请求次数及令牌请求失败次数。也就是,获取预设时间内各个用户终端的令牌请求次数及令牌请求失败次数。
预设时间可以根据用户需要进行设置。预设时间的数值越小,则出现***长时间处于无法为其他用户提供服务的异常状态的可能性越小,但是,预设时间的数值过小,记录的频率过多,会增加运行负荷。因此为了权衡运行负载和判断异常状态的准确性,该预设时间的数值为1秒至10秒内,比如,5秒,6秒。
每个预设时间所记录数据可以清零,这样可以减少存储的负荷。或者,每个预设时间所记录数据也可以迁移到其他存储设备上,方便后期使用所记 录的数据。
上述在获取令牌请求次数及令牌请求失败次数的同时,还可以获取令牌请求成功次数。其中,令牌请求成功次数可以通过令牌请求次数与令牌请求失败次数作差计算得出,也可以通过计数器记录令牌请求成功次数获得。这里前者计算过程也会占用运行内存,后者也可以方便记录预设时间内的获取的所有用户终端的令牌请求成功次数。
可以理解的是,预设时间可以通过计时器实现,或者任何可以能够表明预设时间的代码实现。上述令牌请求次数、令牌请求失败次数和/或令牌请求成功次数,也可以通过计数器实现,或者任何可以能够记录令牌请求次数、令牌请求失败次数和/或令牌请求成功次数的代码实现。
在一种具体实施例中,步骤201可以通过如下步骤获取该预设时间内,所有用户终端的请求信息:
首先获取计时器的计时时间是否达到预设时间,在计时器的计时时间达到预设时间时,然后获取该预设时间内,所有用户终端的令牌请求次数及令牌请求失败次数。
上述获取也可以通过获取工具实现,还可以通过具有获取功能的代码实现。在此不作限定。
步骤202,判断所有用户终端的令牌请求失败次数之和是否等于零。如果是,则执行203;如果否,且该令牌请求失败次数大于零,则执行步骤205;
步骤203,判断是否存在惩罚用户终端,如果是,则执行步骤204;如果否,则执行结束。
步骤204,基于已设置的令牌数量,增大该惩罚用户终端对应特定令牌桶的特定令牌数量,得到增大后的该特定令牌桶的特定令牌的总数量,该增大后的该特定令牌桶的特定令牌的总数量小于全局令牌桶中的令牌数量。
上述已设置的令牌数量可能是只进行过一次设置的第一预设令牌数量,上述已设置的令牌数量也可能是已经进行增大了该惩罚用户终端对应特定令牌桶的特定令牌数量所得到的数量。
步骤205,判断是否存在惩罚用户终端,如果否,则执行步骤206;如果是,则执行结束;
如果已经记录有惩罚用户终端的标识,则表示存在惩罚用户终端,并且该惩罚用户终端对应特定令牌桶中特定令牌的总数量,已经被设置为第一预 设令牌数量。
步骤206,将令牌请求次数最多的用户终端确定为惩罚用户终端,然后执行步骤207。
惩罚用户终端是在预设时间内,所有用户终端的请求信息中查找出的令牌请求次数最多的用户终端。
步骤207,将该惩罚用户终端对应特定令牌桶中特定令牌的总数量设置为第一预设令牌数量,该第一预设令牌数量小于全局令牌桶中的令牌数量。由于该第一预设令牌数量小于全局令牌桶中的令牌数量,以完成对该惩罚用户终端的惩罚。
判断出所有用户终端的令牌请求失败次数之和不等于零,表明在预设时间内,服务器比较不稳定,比如中断服务或者出现过错误,在这个预设时间内,可以让惩罚用户终端请求特定令牌的总数量变少,这样可以保证该惩罚用户终端不影响除该惩罚用户终端的其他用户终端从全局令牌桶中请求令牌。
该第一预设令牌数量可以根据用户需要进行设置,也可以通过该惩罚用户终端令牌请求成功次数的令牌数量总和,与令牌请求失败次数的令牌数量总和进行运算得到,还可以通过预设时间内请求成功的令牌数量进行运算得到。
具体的,计算在预设时间内,该惩罚用户终端的每次请求成功的令牌数量,在所有请求成功的令牌数量查找出最小的令牌数量。将上述最小的令牌数量可以作为该第一预设令牌数量。在该最小的令牌数量大于预设数值时,上述第一预设令牌数量可以取值为预设数量。比如,该预设数量可以为1或2,任何满足小于上述最小的令牌数量的数值,均属于本申请实施例的保护范围,在此不一一举例。
步骤208,获取在该预设时间之后相邻的下一个预设时间内,所有用户终端的令牌请求次数及令牌请求失败次数。
步骤209,判断该预设时间之后相邻的下一个预设时间内,各个用户终端的令牌请求失败次数之和是否等于零。如果是,则执行步骤210。
步骤210,判断是否存在该惩罚用户终端,如果是,则执行步骤211;如果否,则执行结束。
步骤211,基于上述第一预设令牌数量,增大该惩罚用户终端对应特定令牌桶的特定令牌数量,得到增大后的该特定令牌桶的特定令牌的总数量,该 增大后的该特定令牌桶的特定令牌的总数量小于全局令牌桶中的令牌数量。
如果该预设时间之后相邻的下一个预设时间内,各个用户终端的令牌请求失败次数之和等于零,表明在预设时间内,服务器比较稳定,比如未出现中断服务或者未出现过错误,在这个预设时间内,可以让惩罚用户终端请求特定令牌的数目变多,这样可以满足该惩罚用户终端的需要。
基于上述第一预设令牌数量,增大该惩罚用户终端对应特定令牌桶的特定令牌数量,得到增大后的该特定令牌桶的特定令牌的总数量,可以将第一预设令牌数量增大预设比例倍,得到增大后的该特定令牌桶的特定令牌的总数量。任何能够实现增大后的该特定令牌桶的特定令牌的总数量的预设比例倍,均属于本申请实施例的保护范围。示例性的,第一预设令牌数量为10,增大后的该特定令牌桶的特定令牌的总数量为10,预设比例为1.2,则增大后的该特定令牌桶的特定令牌的总数量为12=1.2×10。
按照预设比例增大特定令牌桶的特定令牌的总数量,属于对该惩罚用户终端的奖励,并且这里的奖励属于逐渐奖励,可以保证***快速回归稳定,减少该惩罚用户终端对其他用户终端从全局令牌桶中请求令牌的影响。
为了减缓对惩罚用户终端的惩罚,可以在惩罚之后,可以设置惩罚用户终端的休眠时间。该休眠时间的数值为1秒至5秒内,比如5秒。
示例性的,假设预设比例为1.1,每5秒记录并统计当前5秒内的所有用户终端令牌请求成功总次数记为B、令牌请求失败总次数记为n、以及所有用户终端,获取令牌请求次数最多的用户终端记为b,确定该惩罚用户终端b令牌请求次数为m,令牌请求成功次数的令牌数量总和ts,令牌请求失败次数的令牌数量总和tf,令牌数量总和ts小于或等于全局令牌桶的总数量。当前5秒记录并统计数据完成后,进入当前5秒相邻的下一个5秒时,自动将上述当前5秒所记录并统计数据清零。
比如,全局令牌桶的全局令牌的总数量为100个,该惩罚用户终端b令牌请求次数为5次,每次该惩罚用户终端b请求40个令牌,那么用户令牌请求成功次数ts为2次,则令牌请求成功次数的令牌数量总和ts为80个,全局令牌桶的全局令牌的剩余数量为20个,那么用户令牌请求失败次数为3次,对应用户请求失败的令牌数量tf为120个。
惩罚:当前5秒内,如果n>0,设置惩罚用户终端对应特定令牌桶的特定令牌的总数量为第一预设令牌数量为max(2,ts-tf),以完成对惩罚用户终端对 应特定令牌桶的特定令牌的总数量进行限制。
奖励:当前5秒相邻的下一个5秒内,如果n=0,而且存在该惩罚用户终端,则在该当前5秒相邻的下一个5秒内,将该惩罚用户终端对应第一预设令牌数量乘以1.1,得到增大后的该特定令牌桶的特定令牌的总数量。
当前5秒相邻的下一个5秒相邻的下一个5秒内,如果n=0,而且存在该惩罚用户终端,则在该当前5秒相邻的下一个5秒相邻的下一个5秒内,将该惩罚用户终端对应上述增大后的该特定令牌桶的特定令牌的总数量乘以1.1,继续得到增大后的该特定令牌桶的特定令牌的总数量,直至满足该惩罚用户终端的预设奖励的次数,则不再对该惩罚用户终端进行奖励,该奖励的次数可以根据用户需要进行设置,且,增大后的该特定令牌桶的特定令牌的总数量小于全局令牌桶中的令牌数量。
可选的,基于图3所示的实施例内容,上述的步骤A15-A18的具体介绍如下a1-a4:
a1,如果获取全局令牌失败,获取当前时间用于处理令牌请求的工作线程的总数量;
a2,若当前时间用于处理令牌请求的工作线程的总数量达到第一预设数量,则拒绝所述第一令牌请求,释放与所述第一令牌请求对应的工作线程;
第一预设数量可以根据服务器的需要及用户需要进行设置。第一预设数量的取值范围为93%至98%。示例性的,第一预设数量为95%。
判断出当前时间用于处理令牌请求的工作线程的总数量,表明当前工作线程较多,工作负荷过大,容易造成数据存储***的瘫痪,因此拒绝所述第一令牌请求,释放与所述第一令牌请求对应的工作线程。这样保证数据存储***的稳定性。
a3,若当前时间用于处理令牌请求的工作线程的总数量达到第二预设数量,且未达到第一预设数量,则判断所记录的所述惩罚用户终端中,是否包含所述用户终端;如果包含,则拒绝所述第一令牌请求,并释放该第一令牌请求对应的工作线程;如果不包含,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌;第二预设数量可以根据服务器的需要及用户需要进行设置。第一预设数量的取值范围为89%至92%。可选的,第一预设数量为90%。第一预设数量大于第二预设数量。
判断当前时间用于处理令牌请求的工作线程的总数量达到第二预设数量, 表明当前工作线程还具有部分承载能力,可以拒绝部分第一令牌请求,释放所拒绝部分第一令牌请求对应的工作线程。这样保证数据存储***的稳定性。
如果所记录的所述惩罚用户终端中,包含所述用户终端,即所记录的令牌请求次数最多的用户终端包含所述用户终端,则拒绝所述第一令牌请求,并释放该第一令牌请求对应的工作线程。由于该请求次数最多的用户终端所占用的线程比较多,容易给***造成较大的负载,因此可以保证大部分用户终端的第一令牌请求都正常处理,可以拒绝该令牌请求次数最多的用户终端对应的第一令牌请求。
a4,若所述总数量未达到第二预设数量,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
如果判断出当前时间用于处理令牌请求的工作线程的总数量未达到第二预设数量,表明当前工作线程承载能力较强,将所有用户终端的第一令牌请求都可以正常处理,等待第一预设时长。这样保证数据存储***的稳定性。
应用本申请实施例,上述对令牌请求次数最多的惩罚用户终端进行惩罚,这种只惩罚惩罚用户终端可以保证***稳定性,也保证了其他用户终端可以从全局令牌桶中申请全局令牌,从而达到所有用户终端的公平性;在惩罚该惩罚用户终端之后,再采用逐渐奖励对该对惩罚用户终端进行奖励,可以保证***快速回归稳定,减少该惩罚用户终端对其他用户终端从全局令牌桶中请求令牌的影响。服务器自动实现获取所有用户终端,并对令牌请求次数最多的惩罚用户终端进行限制,不需要人工介入,避免人工操作失误的风险,服务器稳定以后,自动开放对惩罚用户终端的限制,以实现对惩罚用户终端的奖励。这种引入的惩罚和奖励,可以快速限制惩罚用户终端,使得***快速回归稳定。
第二方面,为了避免一个用户终端一次性从全局令牌桶中获得所有的全局令牌,保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态,本申请实施例针对用户终端所提供的令牌获取方法,可以应用于用户终端。从用户终端的角度,本申请实施例提供了一种令牌获取方法。
如图4所示,本申请实施例还提供一种令牌获取方法,应用于用户终端,包括如下步骤:
步骤31,发送用户终端的第一令牌请求至服务器,以使该服务器根据该第一令牌请求,确定该用户终端所请求的令牌数量;从预设的所述用户终端对应的特定令牌桶中获取该用户终端所请求的令牌数量个特定令牌,该特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量;如果获取所述特定令牌失败,则拒绝所述第一令牌请求;如果成功获取特定令牌,则从全局令牌桶中获取该所请求的令牌数量个全局令牌。
步骤32,接收由所述服务器针对所述第一令牌请求发送的反馈信息。
上述反馈信息可以包括:服务器如果获取所述全局令牌失败,则按照预设的拒绝策略产生,拒绝上述第一令牌请求的拒绝指令或等待第一预设时长的等待指令。
上述反馈信息还可以包括:成功获取所请求的令牌数量个全局令牌。相应的,用户终端可以接收到服务器成功获取的所请求的令牌数量个全局令牌。
用户终端在接收到该成功获取所请求的令牌数量个全局令牌的反馈信息之后,所述方法还包括:
利用该所请求的令牌数量个全局令牌,执行在数据存储***中的写入或读出。
应用本申请实施例中,用户终端发送第一令牌请求至服务器,由服务器从用户终端对应的特定令牌桶成功获取特定令牌,再从全局令牌桶中成功获取全局令牌后,这样限制该用户终端直接从全局令牌桶中获取令牌;由于该特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量,这样该用户终端无法一次性从全局令牌桶中获得所有的全局令牌,从而保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态。
如图5所示,本申请实施例还提供一种令牌获取装置,应用于服务器,包括:
第一接收模块41,设置为接收用户终端发送的第一令牌请求;
第一确定模块42,与上述的第一接收模块41相连,设置为根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;
第一获取模块43,与上述的第一确定模块42相连,设置为从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定 令牌,所述特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量;
第二获取模块44,与上述的第一获取模块43相连,设置为如果成功获取所述特定令牌,则从所述全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
应用本申请实施例中,对于请求令牌的用户终端而言,服务器从用户终端对应的特定令牌桶成功获取特定令牌,再从全局令牌桶中成功获取全局令牌后,这样限制该用户终端直接从全局令牌桶中获取令牌;由于该特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量,这样该用户终端无法一次性从全局令牌桶中获得所有的全局令牌,从而保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态。
可选地,在一种实施方式中,所述第二获取模块44还设置为:如果成功从预设的全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌,则向所述用户终端发送所述用户终端所请求的令牌数量个全局令牌。
可选地,在一种实施方式中,所述第二获取模块44还设置为:如果获取全局令牌失败,则按照预设的拒绝策略,拒绝所述第一令牌请求或者在间隔第一预设时长后,再次从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
可选地,在一种实施方式中,所述装置还包括:第一拒绝模块;所述第一拒绝模块设置为:如果获取所述特定令牌失败,则拒绝所述第一令牌请求;或者,如果获取所述特定令牌失败,则在间隔目标预设时长后,再次从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;或者,如果获取所述特定令牌失败,则向所述用户终端发送用于指示等待第一预设时长的等待指令,以使得所述用户终端接收所述等待指令,在间隔所述等待指令中的所述第一预设时长后,重新向所述服务器发送所述第一令牌请求。
可选地,在一种实施方式中,所述第一令牌请求中包含所述用户终端的带宽需求;所述第一确定模块42设置为:根据所述第一令牌请求中所述带宽需求对应的带宽,计算所述用户终端所请求的令牌数量。
可选地,在一种实施方式中,所述装置还包括:第一判断模块,设置为判断所述用户终端是否为预设的需要带宽限制的终端;所述第一获取模块43, 设置为当判断出所述用户终端为预设的需要带宽限制的终端时,从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌。
可选地,在一种实施方式中,,所述第一令牌请求中还包含所述用户终端的标识;所述第一判断模块设置为:判断预设的需要带宽限制的用户标识中,是否包含所述用户终端的标识,如果是,判定所述用户终端为预设的需要带宽限制的终端。
可选地,在一种实施方式中,所述装置还包括:第二判断模块,设置为如果所述用户终端不为所述预设的需要带宽限制的终端,则判断所述用户终端所请求的令牌数量是否大于或等于所述全局令牌桶中的全局令牌的总数量;第一处理模块,设置为如果大于或等于所述全局令牌桶中的所述全局令牌的总数量,则则将所述用户终端设置为需要带宽限制的用户终端,为所述用户终端设置对应的特定令牌桶,并拒绝所述第一令牌请求;第三获取模块,设置为如果小于所述全局令牌桶中的所述全局令牌的总数量,则从所述全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
可选地,在一种实施方式中,所述装置还包括:
第四获取模块,设置为获取预设时间内,各个用户终端的令牌请求次数及令牌请求失败次数;第二处理模块,设置为当所述各个用户终端的令牌请求失败次数之和大于零时,如果未记录有惩罚用户终端,则将令牌请求次数最多的用户终端确定为惩罚用户终端,并将所确定的惩罚用户终端所对应特定令牌桶中特定令牌的总数量,设置为第一预设令牌数量,所述第一预设令牌数量小于所述全局令牌桶中的令牌数量;第三处理模块,设置为当所述各个用户终端的令牌请求失败次数之和等于零时,如果已记录有惩罚用户终端,则基于已记录的惩罚用户终端所对应特定令牌桶的已设置的令牌数量,增大已记录的惩罚用户终端对应特定令牌桶的特定令牌数量,得到增大后的特定令牌桶的特定令牌的总数量,所述增大后的特定令牌桶的特定令牌的总数量小于全局令牌桶中的令牌数量。
可选地,在一种实施方式中,所述装置还包括:第四处理模块,设置为:如果获取全局令牌失败,获取当前时间用于处理令牌请求的工作线程的总数量;若所述总数量达到第一预设数量,则拒绝所述第一令牌请求,释放与所述第一令牌请求对应的工作线程;若所述总数量达到第二预设数量,且未达 到第一预设数量,则判断所记录的惩罚用户终端中,是否包含所述用户终端;如果包含,则拒绝所述第一令牌请求,并释放该第一令牌请求对应的工作线程;如果不包含,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌;若所述总数量未达到第二预设数量,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
如图6所示,本申请实施例还提供一种令牌获取装置,应用于用户终端,包括:
发送模块51,设置为发送用户终端的第一令牌请求至服务器,以使所述服务器根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;从预设的所述用户终端对应的特定令牌桶中获取所述用户终端所请求的令牌数量个特定令牌,所述特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量;如果获取所述特定令牌失败,则拒绝所述第一令牌请求;如果成功获取所述特定令牌,则从所述全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
接收模块52,与发送模块51相连,设置为接收由所述服务器针对所述第一令牌请求发送的反馈信息。
可选的,在一种实施方式中,所述反馈信息包括:成功获取所述所请求的令牌数量个全局令牌;
可选地,在一种实施方式中,所述令牌获取装置还包括:执行模块,设置为利用所述所请求的令牌数量个全局令牌,执行在数据存储***中的写入或读出。
本申请实施例还提供了一种服务器,包括处理器和机器可读存储介质,所述机器可读存储介质存储有能够被所述处理器执行的机器可执行指令,所述处理器被所述机器可执行指令促使:实现上述的令牌获取方法步骤。
相应于第一方面所示的方法,本申请实施例还提供了一种服务器,如图7所示,包括处理器61、通信接口62、存储器63和通信总线64,其中,处理器61,通信接口62,存储器63通过通信总线64完成相互间的通信,
存储器63,设置为存放计算机程序;
处理器61,设置为执行存储器63上所存放的程序时,实现本申请实施例 从服务器角度所提供的一种令牌获取方法的步骤。
本申请实施例还提供了一种用户终端,包括处理器和机器可读存储介质,所述机器可读存储介质存储有能够被所述处理器执行的机器可执行指令,所述处理器被所述机器可执行指令促使:实现上述的令牌获取方法步骤。
相应于第二方面所示的方法,本申请实施例还提供了一种用户终端,如图8所示,包括处理器71、通信接口72、存储器73和通信总线74,其中,处理器71,通信接口72,存储器73通过通信总线74完成相互间的通信,
存储器73,设置为存放计算机程序;
处理器71,设置为执行存储器73上所存放的程序时,实现本申请实施例从用户终端角度所提供的一种令牌获取方法的步骤。
上述用户终端/服务器提到的通信总线可以是外设部件互连标准(Peripheral Component Interconnect,PCI)总线或扩展工业标准结构(Extended Industry Standard Architecture,EISA)总线等。该通信总线可以分为地址总线、数据总线、控制总线等。为便于表示,图中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。
通信接口用于上述用户终端/服务器与其他设备之间的通信。
存储器可以包括随机存取存储器(Random Access Memory,RAM),也可以包括非易失性存储器(Non-Volatile Memory,NVM),例如至少一个磁盘存储器。可选的,存储器还可以是至少一个位于远离前述处理器的存储装置。
上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(Digital Signal Processing,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。
本申请实施例提供的方法可以应用于用户终端。具体的,该用户终端可以为:台式计算机、便携式计算机、智能移动终端、服务器等。在此不作限定,任何可以实现本申请的用户终端,均属于本申请的保护范围。
相应于第一方面所示的方法,本申请实施例提供了一种计算机可读存储介质,所述存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现上述的令牌获取方法步骤。
相应于第二方面所示的方法,本申请实施例提供了一种计算机可读存储介质,所述存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现上述的令牌获取方法步骤。
相应于第一方面所示的方法,本申请实施例提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述的令牌获取方法步骤。
相应于第二方面所示的方法,本申请实施例提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述的令牌获取方法步骤。
相应于第一方面所示的方法,本申请实施例提供了一种计算机程序,当其在计算机上运行时,使得计算机执行上述的令牌获取方法的步骤。
相应于第二方面所示的方法,本申请实施例提供了一种计算机程序,当其在计算机上运行时,使得计算机执行上述的令牌获取方法的步骤。
对于令牌获取装置/服务器/用户终端/存储介质/包含指令的计算机程序产品/计算机程序实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
本说明书中的各个实施例均采用相关的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于令牌获取装置/服务器/用户终端/存储介质/包含指令的计算机程序产品/计算机程序实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
以上所述仅为本申请的较佳实施例而已,并不用以限制本申请,凡在本申请的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在 本申请保护的范围之内。
工业实用性
基于本申请实施例提供的上述一种令牌获取方法、装置、服务器、用户终端及介质,对需要请求令牌的用户终端而言,从用户终端对应的特定令牌桶成功获取特定令牌,再从全局令牌桶中获取全局令牌,这样限制该用户终端直接从全局令牌桶中获取令牌;由于该特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量,这样该用户终端无法一次性从全局令牌桶中获得所有的全局令牌,从而保证除该用户终端以外的其他用户终端可以从全局令牌桶中请求令牌,防止***长时间处于无法为其他用户提供服务的异常状态。

Claims (23)

  1. 一种令牌获取方法,应用于服务器,所述方法包括:
    接收用户终端发送的第一令牌请求;
    根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;
    从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;
    如果成功获取所述特定令牌,则从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌;
    其中,所述特定令牌桶中的令牌数量小于所述全局令牌桶中的令牌数量。
  2. 如权利要求1所述的令牌获取方法,其中,所述方法还包括:
    如果成功从预设的全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌,则向所述用户终端发送所述用户终端所请求的令牌数量个全局令牌。
  3. 根据权利要求2所述的方法,其中,所述方法还包括:
    如果获取全局令牌失败,则按照预设的拒绝策略,拒绝所述第一令牌请求或者在间隔第一预设时长后,再次从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
  4. 如权利要求1所述的令牌获取方法,其中,所述方法还包括:
    如果获取所述特定令牌失败,则拒绝所述第一令牌请求;
    或者,
    如果获取所述特定令牌失败,则在间隔目标预设时长后,再次从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;
    或者,
    如果获取所述特定令牌失败,则向所述用户终端发送用于指示等待第一预设时长的等待指令,以使得所述用户终端接收所述等待指令,在间隔所述等待指令中的所述第一预设时长后,重新向所述服务器发送所述第一令牌请求。
  5. 如权利要求1-4任一项所述的令牌获取方法,其中,所述第一令牌请求中包含所述用户终端的带宽需求;
    所述根据所述第一令牌请求,确定所述用户终端所请求的令牌数量,包 括:
    根据所述第一令牌请求中所述带宽需求对应的带宽,计算所述用户终端所请求的令牌数量。
  6. 根据权利要求1-4任一项所述的令牌获取方法,其中,所述从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌之前,所述方法还包括:
    判断所述用户终端是否为预设的需要带宽限制的终端;
    所述从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌,包括:
    当判断出所述用户终端为预设的需要带宽限制的终端时,从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌。
  7. 根据权利要求6所述的方法,其中,所述第一令牌请求中还包含所述用户终端的标识;
    判断所述用户终端是否为预设的需要带宽限制的终端,包括:
    判断预设的需要带宽限制的用户标识中,是否包含所述用户终端的标识,如果是,判定所述用户终端为预设的需要带宽限制的终端。
  8. 如权利要求6所述的令牌获取方法,其中,所述方法还包括:
    如果所述用户终端不为预设的需要带宽限制的终端,则判断所述用户终端所请求的令牌数量是否大于或等于所述全局令牌桶中的全局令牌的总数量;
    如果所述用户终端所请求的令牌数量大于或等于所述全局令牌桶中的所述全局令牌的总数量,则将所述用户终端设置为需要带宽限制的用户终端,为所述用户终端设置对应的特定令牌桶,并拒绝所述第一令牌请求;
    如果所述用户终端所请求的令牌数量小于所述全局令牌桶中的所述全局令牌的总数量,则从所述全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
  9. 如权利要求1至8任一项所述的令牌获取方法,其中,所述方法还包括:
    获取预设时间内,各个用户终端的令牌请求次数及令牌请求失败次数;
    当所述各个用户终端的令牌请求失败次数之和大于零时,如果未记录有惩罚用户终端,则将令牌请求次数最多的用户终端确定为惩罚用户终端,并 将所确定的惩罚用户终端所对应特定令牌桶中特定令牌的总数量,设置为第一预设令牌数量,所述第一预设令牌数量小于所述全局令牌桶中的令牌数量;
    当所述各个用户终端的令牌请求失败次数之和等于零时,如果已记录有惩罚用户终端,则基于已记录的惩罚用户终端所对应特定令牌桶的已设置的令牌数量,增大已记录的惩罚用户终端对应特定令牌桶的特定令牌数量,得到增大后的特定令牌桶的特定令牌的总数量,所述增大后的特定令牌桶的特定令牌的总数量小于全局令牌桶中的令牌数量。
  10. 如权利要求9所述的令牌获取方法,其中,所述方法还包括:
    如果获取全局令牌失败,获取当前时间用于处理令牌请求的工作线程的总数量;
    若所述总数量达到第一预设数量,则拒绝所述第一令牌请求,释放与所述第一令牌请求对应的工作线程;
    若所述总数量达到第二预设数量,且未达到第一预设数量,则判断所记录的惩罚用户终端中,是否包含所述用户终端;如果包含,则拒绝所述第一令牌请求,并释放该第一令牌请求对应的工作线程;如果不包含,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌;
    若所述总数量未达到第二预设数量,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
  11. 一种令牌获取装置,应用于服务器,所述令牌获取装置包括:
    第一接收模块,设置为接收用户终端发送的第一令牌请求;
    第一确定模块,设置为根据所述第一令牌请求,确定所述用户终端所请求的令牌数量;
    第一获取模块,设置为从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌,所述特定令牌桶中的令牌数量小于全局令牌桶中的令牌数量;
    第二获取模块,设置为如果成功获取所述特定令牌,则从所述全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
  12. 根据权利要求11所述的令牌获取装置,其中,所述第二获取模块还设置为:如果成功从预设的全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌,则向所述用户终端发送所述用户终端所请求的令牌数量个全 局令牌。
  13. 根据权利要求12所述的令牌获取装置,其中,所述第二获取模块还设置为:如果获取全局令牌失败,则按照预设的拒绝策略,拒绝所述第一令牌请求或者在间隔第一预设时长后,再次从预设的全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
  14. 根据权利要求11所述的令牌获取装置,其中,所述装置还包括:第一拒绝模块;
    所述第一拒绝模块设置为:如果获取所述特定令牌失败,则拒绝所述第一令牌请求;或者,
    如果获取所述特定令牌失败,则在间隔目标预设时长后,再次从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌;或者,
    如果获取所述特定令牌失败,则向所述用户终端发送用于指示等待第一预设时长的等待指令,以使得所述用户终端接收所述等待指令,在间隔所述等待指令中的所述第一预设时长后,重新向所述服务器发送所述第一令牌请求。
  15. 如权利要求11-14任一项所述的令牌获取装置,其中,所述第一令牌请求中包含所述用户终端的带宽需求;
    所述第一确定模块设置为:
    根据所述第一令牌请求中所述带宽需求对应的带宽,计算所述用户终端所请求的令牌数量。
  16. 根据权利要求11-14任一项所述的令牌获取装置,其中,所述装置还包括:
    第一判断模块,设置为判断所述用户终端是否为预设的需要带宽限制的终端;
    所述第一获取模块,设置为当判断出所述用户终端为预设的需要带宽限制的终端时,从预设的所述用户终端对应的特定令牌桶中,获取所述用户终端所请求的令牌数量个特定令牌。
  17. 如权利要求16所述的令牌获取装置,其中,所述第一令牌请求中还包含所述用户终端的标识;
    所述第一判断模块设置为:判断预设的需要带宽限制的用户标识中,是 否包含所述用户终端的标识,如果是,判定所述用户终端为预设的需要带宽限制的终端。
  18. 如权利要求16所述的令牌获取装置,其中,所述装置还包括:
    第二判断模块,设置为如果所述用户终端不为所述预设的需要带宽限制的终端,则判断所述用户终端所请求的令牌数量是否大于或等于所述全局令牌桶中的全局令牌的总数量;
    第一处理模块,设置为如果大于或等于所述全局令牌桶中的所述全局令牌的总数量,则则将所述用户终端设置为需要带宽限制的用户终端,为所述用户终端设置对应的特定令牌桶,并拒绝所述第一令牌请求;
    第三获取模块,设置为如果小于所述全局令牌桶中的所述全局令牌的总数量,则从所述全局令牌桶中,获取所述用户终端所请求的令牌数量个全局令牌。
  19. 如权利要求11至18任一项所述的令牌获取装置,其中,所述装置还包括:
    第四获取模块,设置为获取预设时间内,各个用户终端的令牌请求次数及令牌请求失败次数;
    第二处理模块,设置为当所述各个用户终端的令牌请求失败次数之和大于零时,如果未记录有惩罚用户终端,则将令牌请求次数最多的用户终端确定为惩罚用户终端,并将所确定的惩罚用户终端所对应特定令牌桶中特定令牌的总数量,设置为第一预设令牌数量,所述第一预设令牌数量小于所述全局令牌桶中的令牌数量;
    第三处理模块,设置为当所述各个用户终端的令牌请求失败次数之和等于零时,如果已记录有惩罚用户终端,则基于已记录的惩罚用户终端所对应特定令牌桶的已设置的令牌数量,增大已记录的惩罚用户终端对应特定令牌桶的特定令牌数量,得到增大后的特定令牌桶的特定令牌的总数量,所述增大后的特定令牌桶的特定令牌的总数量小于全局令牌桶中的令牌数量。
  20. 如权利要求19所述的令牌获取装置,其中,所述装置还包括:
    第四处理模块,设置为:如果获取全局令牌失败,获取当前时间用于处理令牌请求的工作线程的总数量;若所述总数量达到第一预设数量,则拒绝所述第一令牌请求,释放与所述第一令牌请求对应的工作线程;若所述总数量达到第二预设数量,且未达到第一预设数量,则判断所记录的惩罚用户终 端中,是否包含所述用户终端;如果包含,则拒绝所述第一令牌请求,并释放该第一令牌请求对应的工作线程;如果不包含,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌;若所述总数量未达到第二预设数量,则在间隔第一预设时长后,再次从全局令牌桶中获取所述用户终端所请求的令牌数量个全局令牌。
  21. 一种服务器,包括处理器和机器可读存储介质,所述机器可读存储介质存储有能够被所述处理器执行的机器可执行指令,所述处理器被所述机器可执行指令促使:实现权利要求1-10任一所述的方法步骤。
  22. 一种计算机可读存储介质,所述存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现权利要求1-10任一所述的方法步骤。
  23. 一种计算机程序,当其在计算机上运行时,使得计算机执行权利要求1-10任一项所述的方法步骤。
PCT/CN2018/122042 2017-12-19 2018-12-19 一种令牌获取方法、装置、服务器、用户终端及介质 WO2019120217A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201711376057.1 2017-12-19
CN201711376057.1A CN109936511B (zh) 2017-12-19 2017-12-19 一种令牌获取方法、装置、服务器、终端设备及介质

Publications (1)

Publication Number Publication Date
WO2019120217A1 true WO2019120217A1 (zh) 2019-06-27

Family

ID=66983790

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/122042 WO2019120217A1 (zh) 2017-12-19 2018-12-19 一种令牌获取方法、装置、服务器、用户终端及介质

Country Status (2)

Country Link
CN (1) CN109936511B (zh)
WO (1) WO2019120217A1 (zh)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112084090A (zh) * 2020-09-03 2020-12-15 深信服科技股份有限公司 服务器管理方法、服务器、管理终端及存储介质
CN112787950A (zh) * 2021-01-28 2021-05-11 西安交通大学 一种公平网络流量管控方法及装置
CN113765818A (zh) * 2020-06-28 2021-12-07 北京沃东天骏信息技术有限公司 分布式限流方法、装置、设备、存储介质和***
CN114070847A (zh) * 2020-07-27 2022-02-18 腾讯科技(深圳)有限公司 服务器的限流方法、装置、设备及存储介质
CN114124399A (zh) * 2021-10-22 2022-03-01 杭州安恒信息安全技术有限公司 数据接入方法、装置和计算机设备
CN114374652A (zh) * 2022-01-11 2022-04-19 同方有云(北京)科技有限公司 热磁存储和蓝光存储之间的数据传输限速方法及装置
CN114584519A (zh) * 2022-05-05 2022-06-03 飞狐信息技术(天津)有限公司 一种消息中间件的限流方法及消息中间件
CN115225580A (zh) * 2022-06-10 2022-10-21 新浪网技术(中国)有限公司 一种针对多处理器核的业务隔离限速方法和装置

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111049756B (zh) * 2019-12-24 2023-04-07 北京奇艺世纪科技有限公司 请求响应方法、装置、电子设备及计算机可读存储介质
CN111447150B (zh) * 2020-02-29 2023-07-28 中国平安财产保险股份有限公司 访问请求限流方法、服务器及存储介质
CN113472681A (zh) * 2020-03-30 2021-10-01 阿里巴巴集团控股有限公司 流量限速方法及装置
CN114095444B (zh) * 2020-07-15 2023-11-10 中移物联网有限公司 限流方法、装置及电子设备
CN115080657A (zh) * 2021-03-10 2022-09-20 ***通信集团山东有限公司 一种应用于分布式存储的操作令牌分配方法、***及设备
CN114979012B (zh) * 2022-05-31 2024-06-21 郑州浪潮数据技术有限公司 一种网络流量的限流方法、***、装置及计算机存储介质
CN114826774B (zh) * 2022-06-02 2024-01-30 天翼数字生活科技有限公司 一种终端设备日志请求控制方法、服务端和***

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101227410A (zh) * 2008-02-03 2008-07-23 杭州华三通信技术有限公司 流量监管方法及流量监管设备
CN101674247A (zh) * 2009-10-21 2010-03-17 中兴通讯股份有限公司 一种对业务流量进行监管的方法及其装置
CN102118269A (zh) * 2011-02-28 2011-07-06 华为技术有限公司 一种令牌发放方法和***
CN105939285A (zh) * 2015-08-21 2016-09-14 杭州迪普科技有限公司 报文转发方法及装置

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9712453B1 (en) * 2012-03-26 2017-07-18 Amazon Technologies, Inc. Adaptive throttling for shared resources
CN106843170B (zh) * 2016-11-30 2019-06-14 浙江中控软件技术有限公司 基于令牌的任务调度方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101227410A (zh) * 2008-02-03 2008-07-23 杭州华三通信技术有限公司 流量监管方法及流量监管设备
CN101674247A (zh) * 2009-10-21 2010-03-17 中兴通讯股份有限公司 一种对业务流量进行监管的方法及其装置
CN102118269A (zh) * 2011-02-28 2011-07-06 华为技术有限公司 一种令牌发放方法和***
CN105939285A (zh) * 2015-08-21 2016-09-14 杭州迪普科技有限公司 报文转发方法及装置

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113765818A (zh) * 2020-06-28 2021-12-07 北京沃东天骏信息技术有限公司 分布式限流方法、装置、设备、存储介质和***
CN114070847A (zh) * 2020-07-27 2022-02-18 腾讯科技(深圳)有限公司 服务器的限流方法、装置、设备及存储介质
CN114070847B (zh) * 2020-07-27 2024-01-23 腾讯科技(深圳)有限公司 服务器的限流方法、装置、设备及存储介质
CN112084090A (zh) * 2020-09-03 2020-12-15 深信服科技股份有限公司 服务器管理方法、服务器、管理终端及存储介质
CN112084090B (zh) * 2020-09-03 2024-02-23 深信服科技股份有限公司 服务器管理方法、服务器、管理终端及存储介质
CN112787950A (zh) * 2021-01-28 2021-05-11 西安交通大学 一种公平网络流量管控方法及装置
CN114124399A (zh) * 2021-10-22 2022-03-01 杭州安恒信息安全技术有限公司 数据接入方法、装置和计算机设备
CN114124399B (zh) * 2021-10-22 2024-04-16 杭州安恒信息安全技术有限公司 数据接入方法、装置和计算机设备
CN114374652B (zh) * 2022-01-11 2024-01-16 同方有云(北京)科技有限公司 热磁存储和蓝光存储之间的数据传输限速方法及装置
CN114374652A (zh) * 2022-01-11 2022-04-19 同方有云(北京)科技有限公司 热磁存储和蓝光存储之间的数据传输限速方法及装置
CN114584519B (zh) * 2022-05-05 2022-09-16 飞狐信息技术(天津)有限公司 一种消息中间件的限流方法及消息中间件
CN114584519A (zh) * 2022-05-05 2022-06-03 飞狐信息技术(天津)有限公司 一种消息中间件的限流方法及消息中间件
CN115225580A (zh) * 2022-06-10 2022-10-21 新浪网技术(中国)有限公司 一种针对多处理器核的业务隔离限速方法和装置
CN115225580B (zh) * 2022-06-10 2024-02-02 新浪技术(中国)有限公司 一种针对多处理器核的业务隔离限速方法和装置

Also Published As

Publication number Publication date
CN109936511B (zh) 2020-12-25
CN109936511A (zh) 2019-06-25

Similar Documents

Publication Publication Date Title
WO2019120217A1 (zh) 一种令牌获取方法、装置、服务器、用户终端及介质
CN110222533B (zh) 分布式数据安全应用方法、***及电子设备
US11507417B2 (en) Job scheduling based on job execution history
US20170185454A1 (en) Method and Electronic Device for Determining Resource Consumption of Task
CN109582452B (zh) 一种容器调度方法、调度装置及电子设备
WO2018058998A1 (zh) 一种数据加载方法、终端和计算集群
CN107819797B (zh) 访问请求处理方法和装置
CN110221775B (zh) 存储***中令牌的分配方法和装置
CN106533961B (zh) 一种流量控制方法及装置
CN113067875A (zh) 基于微服务网关动态流控的访问方法和装置以及设备
CN111562884B (zh) 一种数据存储方法、装置及电子设备
CN106952085B (zh) 一种数据存储与业务处理的方法及装置
CN115190078B (zh) 一种访问流量控制方法、装置、设备以及存储介质
CN111092814B (zh) 业务办理请求报文分配方法及设备
CN110163554B (zh) 工作流的运行方法、装置、服务器和存储介质
CN111709723A (zh) Rpa业务流程智能处理方法、装置、计算机设备和存储介质
CN114500381A (zh) 网络带宽限制方法、***、电子设备及可读存储介质
CN109544347B (zh) 尾差分配方法、计算机可读存储介质及尾差分配***
CN114143327A (zh) 集群资源配额分配方法、装置及电子设备
CN111831408A (zh) 异步任务处理方法、装置、电子设备及介质
CN110311862B (zh) 一种服务链映射方法及装置
KR20190094096A (ko) 문서 정보 입력 방법, 장치, 서버, 그리고 저장 매체
CN112131478A (zh) 交易检测方法及装置
CN105519055A (zh) 一种I/O通道QoS动态均衡方法及装置
CN115113947A (zh) 流程引擎的配置方法、终端设备及计算机可读存储介质

Legal Events

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

Ref document number: 18893261

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 24/09/2020)

122 Ep: pct application non-entry in european phase

Ref document number: 18893261

Country of ref document: EP

Kind code of ref document: A1