CN116527589A - Service request processing method and device, electronic equipment and storage medium - Google Patents

Service request processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN116527589A
CN116527589A CN202310457420.1A CN202310457420A CN116527589A CN 116527589 A CN116527589 A CN 116527589A CN 202310457420 A CN202310457420 A CN 202310457420A CN 116527589 A CN116527589 A CN 116527589A
Authority
CN
China
Prior art keywords
tokens
time length
service request
stored
calculating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310457420.1A
Other languages
Chinese (zh)
Inventor
曹敏隆
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Zhongyuan Network Co ltd
Original Assignee
Shanghai Zhongyuan Network Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Zhongyuan Network Co ltd filed Critical Shanghai Zhongyuan Network Co ltd
Priority to CN202310457420.1A priority Critical patent/CN116527589A/en
Publication of CN116527589A publication Critical patent/CN116527589A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/215Flow control; Congestion control using token-bucket
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the invention provides a service request processing method, a device, electronic equipment and a storage medium. The service request processing method comprises the following steps: acquiring a first number of tokens required by a service request to be processed and a second number of currently stored tokens; according to the first quantity, the second quantity and the preset relation information of the single token extraction time length and the stored token quantity, calculating the time length required for extracting the first quantity of tokens, wherein the relation information comprises: when the number of the storage tokens is larger than or equal to a preset threshold value, the single token extraction time length is positively related to the number of the storage tokens, and when the number of the storage tokens is smaller than or equal to the preset threshold value, the single token extraction time length is unchanged along with the change of the number of the storage tokens; and after delaying the duration, taking out the first number of tokens to be distributed to the service request to be processed, and processing the service request to be processed. The embodiment of the invention can be more suitable for the current processing capacity of the server and improve the accuracy of current limiting.

Description

Service request processing method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a service request processing method, a device, an electronic device, and a storage medium.
Background
With the rapid development of computer technology, a server often faces a large number of service requests, so in order to ensure the stability of the server, a current limiting measure is usually set on the server. The current limiting measure is an advantageous measure for protecting the server, and can effectively protect the server from overload, so that the server can be in a normal running state.
In the prior art, a token bucket current limiting mode is generally adopted for current limiting. In the token bucket throttling mode, a server generates tokens at a constant rate and puts the tokens into a token bucket, after receiving a service request, the service request can be processed after the tokens are taken out from the token bucket and distributed to the service request, and if the tokens in the token bucket are insufficient, the service request is paused.
However, in practical applications, the processing capacity of the server is not constant, but the token bucket throttling method generates tokens at a constant rate to perform throttling, which does not take into account the change of the processing capacity of the server, so that the accuracy of the token bucket throttling method in the prior art is low.
Disclosure of Invention
The embodiment of the invention aims to provide a service request processing method, a device, electronic equipment and a storage medium, so as to improve the accuracy of service end current limiting. The specific technical scheme is as follows:
In a first aspect of the present invention, there is provided a service request processing method, including:
acquiring a first number of tokens required by a service request to be processed and a second number of currently stored tokens;
calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the number of stored tokens; the relationship information includes: when the number of the storage tokens is larger than or equal to a preset threshold value, the single token fetching time length is positively related to the number of the storage tokens, and when the number of the storage tokens is smaller than or equal to the preset threshold value, the single token fetching time length is kept unchanged along with the change of the number of the storage tokens;
and after the time length is delayed, the first number of tokens are taken out and distributed to the service request to be processed, and the service request to be processed is processed.
Optionally, the relation information is a function image, wherein a horizontal axis of the function image represents the number of the stored tokens, and a vertical axis represents the single token fetching duration; the calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the stored token number, including: calculating the remaining number of the second number minus the first number; and calculating the area surrounded by the partial function images between the residual quantity and the second quantity and the transverse axis, and taking the area as the time length required for taking out the tokens of the first quantity.
Optionally, the function image includes a hyperbolic tangent function part, where the hyperbolic tangent function part indicates that the single token fetching duration is positively related to the number of stored tokens when the number of stored tokens is greater than or equal to a preset threshold.
Optionally, the function image includes a constant function part, where the constant function part indicates that the single token fetching time length remains unchanged with the change of the number of the storage tokens when the number of the storage tokens is less than or equal to the preset threshold value.
Optionally, the calculating an area surrounded by the partial function image between the remaining number and the second number and the horizontal axis includes: and under the condition that the residual quantity and the second quantity are both positioned in the hyperbolic tangent function part, carrying out integral calculation on the partial function image to obtain the area surrounded by the partial function image and the transverse axis.
Optionally, the calculating an area surrounded by the partial function image between the remaining number and the second number and the horizontal axis includes: calculating a rectangular area surrounded by the partial function image and the transverse axis under the condition that the residual quantity and the second quantity are both positioned in the constant function part, so as to obtain an area surrounded by the partial function image and the transverse axis; and under the condition that the residual quantity is positioned in the constant function part and the second quantity is positioned in the hyperbolic tangent function part, carrying out integral calculation on the image positioned in the hyperbolic tangent function part in the partial function image to obtain a first area, calculating the rectangular area surrounded by the image positioned in the constant function part and the transverse axis in the partial function image to obtain a second area, and taking the sum of the first area and the second area as the area surrounded by the partial function image and the transverse axis.
Optionally, before calculating the time period required for fetching the first number of tokens according to the first number, the second number, and the preset relation information of the single token fetch time period and the number of stored tokens, the method further includes: judging whether the second number is larger than or equal to the first number; the calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the stored token number, including: and when the second number is greater than or equal to the first number, calculating the time length required for taking out the first number of tokens according to the first number, the second number and the preset relation information of the single token taking-out time length and the number of stored tokens.
In a second aspect of the present invention, there is also provided a service request processing apparatus, the apparatus including:
the acquisition module is used for acquiring a first number of tokens required by the service request to be processed and a second number of currently stored tokens;
the calculating module is used for calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the number of stored tokens; the relationship information includes: when the number of the storage tokens is larger than or equal to a preset threshold value, the single token fetching time length is positively related to the number of the storage tokens, and when the number of the storage tokens is smaller than or equal to the preset threshold value, the single token fetching time length is kept unchanged along with the change of the number of the storage tokens;
And the processing module is used for taking out the first number of tokens to be distributed to the service request to be processed after delaying the duration and processing the service request to be processed.
Optionally, the relation information is a function image, wherein a horizontal axis of the function image represents the number of the stored tokens, and a vertical axis represents the single token fetching duration; the computing module includes: a first calculation unit configured to calculate a remaining number of the second number minus the first number; and the second calculating unit is used for calculating the area surrounded by the partial function images between the residual quantity and the second quantity and the transverse axis, and taking the area as the time length required for taking out the tokens of the first quantity.
Optionally, the function image includes a hyperbolic tangent function part, where the hyperbolic tangent function part indicates that the single token fetching duration is positively related to the number of stored tokens when the number of stored tokens is greater than or equal to a preset threshold.
Optionally, the function image includes a constant function part, where the constant function part indicates that the single token fetching time length remains unchanged with the change of the number of the storage tokens when the number of the storage tokens is less than or equal to the preset threshold value.
Optionally, the second computing unit includes: and the first calculating subunit is used for carrying out integral calculation on the partial function image to obtain the area surrounded by the partial function image and the transverse axis under the condition that the residual quantity and the second quantity are both positioned on the hyperbolic tangent function part.
Optionally, the second computing unit includes: the second calculating subunit is configured to calculate a rectangular area surrounded by the partial function image and the transverse axis to obtain an area surrounded by the partial function image and the transverse axis when the remaining number and the second number are both located in the constant function portion; and the third calculation subunit is used for carrying out integral calculation on the image positioned in the hyperbolic tangent function part in the partial function image to obtain a first area when the residual quantity is positioned in the constant function part and the second quantity is positioned in the hyperbolic tangent function part, calculating the rectangular area surrounded by the image positioned in the constant function part and the transverse axis in the partial function image to obtain a second area, and taking the sum of the first area and the second area as the area surrounded by the partial function image and the transverse axis.
Optionally, the apparatus further comprises: the judging module is used for judging whether the second number is larger than or equal to the first number; the calculation module is specifically configured to calculate, when the determination module determines that the second number is greater than or equal to the first number, a duration required for taking out the first number of tokens according to the first number, the second number, and relationship information of a preset single token taking-out duration and a preset stored token number.
In yet another aspect of the present invention, there is also provided an electronic device including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory perform communication with each other through the communication bus; a memory for storing a computer program; and the processor is used for realizing any one of the service request processing methods when executing the program stored in the memory.
In yet another aspect of the implementation of the present invention, there is also provided a computer readable storage medium having instructions stored therein, which when executed on a computer, cause the computer to implement any of the service request processing methods described above.
In yet another aspect of the implementation of the present invention, there is also provided a computer program product containing instructions that, when run on a computer, cause the computer to implement the service request processing method of any one of the above.
According to the service request processing method, the device, the electronic equipment and the storage medium, based on the characteristics that the processing capacity of the service end is relatively poor when the service end is just started or the service request is not received for a long time, and the processing capacity of the service end is recovered and stabilized at a normal level after a series of service request loads and preheats, the relation information of the single token taking-out time length and the number of stored tokens is preset according to the change condition of the processing capacity of the service end. The number of the storage tokens is used for representing the processing capacity of the server, and the larger the number of the storage tokens is, the smaller the number of the service requests currently received by the server is, and the worse the processing capacity of the server is at the moment; the single token fetching duration represents the speed of fetching tokens under the condition of corresponding stored token quantity, and the larger the stored token quantity is, the worse the processing capacity of the server side is indicated, and the longer the single token fetching duration is needed to carry out current limiting to a greater extent. Therefore, when the number of the stored tokens is larger than or equal to a preset threshold, the single token fetching time length is positively related to the number of the stored tokens, and when the number of the stored tokens is smaller than or equal to the preset threshold, the single token fetching time length is unchanged along with the change of the number of the stored tokens, so that the single token fetching time length can be changed based on the change of the processing capacity of the server. After receiving the service request to be processed, the current flow is limited according to the relation information of the preset single token extraction time length and the number of the stored tokens, so that the current processing capacity of the server can be more adapted, and the accuracy of the flow limitation is improved. The service end is protected in a cold start current limiting mode which is closer to the real load condition of the service end, so that the situation that the service end is broken down by sudden flow to cause flow overload, service cascade avalanche occurs, and the whole service cannot be used is avoided.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
Fig. 1 is a flowchart of steps of a service request processing method in an embodiment of the present invention.
Fig. 2 is a schematic diagram of a functional image according to an embodiment of the present invention.
Fig. 3 is a flowchart illustrating steps of another service request processing method according to an embodiment of the present invention.
Fig. 4 is a block diagram of a service request processing device according to an embodiment of the present invention.
Fig. 5 is a block diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the accompanying drawings in the embodiments of the present invention.
The embodiment of the invention is improved on the basis of the token bucket current limiting mode, so that the current limiting mode is more suitable for the change of the processing capacity of the server.
The token bucket throttling mode is that a token bucket for storing tokens is arranged, the server generates tokens at a constant rate and puts the tokens into the token bucket, after receiving a service request, the service request can be processed after the tokens are firstly taken out from the token bucket and distributed to the service request, and if the tokens in the token bucket are insufficient, the service request can be paused.
However, in practical application, when the service end is just started or does not receive a service request for a long time, the processing capacity is relatively poor, because all resources of the service end are not loaded and preheated, and after a series of service requests are loaded and preheated, the processing capacity of the service end is recovered and stabilized at a normal level. Therefore, in the embodiment of the invention, based on the change condition of the processing capacity of the server, the relation information of the single token extraction time length and the number of the stored tokens is preset, and the current limitation is performed based on the relation information. And will be described in detail below.
The service request processing method in the embodiment of the invention can be executed on the server side.
Fig. 1 is a flowchart of steps of a service request processing method in an embodiment of the present invention.
As shown in fig. 1, the service request processing method may include the steps of:
step 101, a first number of tokens required for a pending service request and a second number of currently stored tokens are acquired.
For example, the server may obtain, after receiving the pending service request, a first number of tokens required for the pending service request and a second number of currently stored tokens. The server may also obtain, at a preset time interval, a first number of tokens required for the service request to be processed and a second number of currently stored tokens. The specific value of the time interval may be set according to actual requirements, which is not limited in this embodiment.
The server acquires the number of tokens required by the service request to be processed, and takes the number of tokens required by the service request to be processed as a first number. In the token bucket throttling mode, a pending service request may be allocated a token before continuing to process the pending service request, i.e., a pending service request requires a token. Therefore, the server side can acquire the number of the service requests to be processed, and the number of the service requests to be processed is used as the first number of tokens required by the service requests to be processed.
The server acquires the number of the currently stored tokens in the token bucket, and takes the number of the currently stored tokens in the token bucket as a second number.
Step 102, calculating the time length required for fetching the first number of tokens according to the first number, the second number and the preset relation information of the single token fetching time length and the number of stored tokens.
In the embodiment of the invention, the relation between the processing capacity of the server and the number of the stored tokens in the token bucket is considered, the processing capacity of the server is represented by the number of the stored tokens, and the larger the number of the stored tokens is, the smaller the number of the service requests currently received by the server is, and the worse the processing capacity of the server is at the moment; the single token fetching duration represents the speed of fetching tokens under the condition of corresponding stored token quantity, and the larger the stored token quantity is, the worse the processing capacity of the server side is indicated, and the longer the single token fetching duration is needed to carry out current limiting to a greater extent.
Therefore, based on the characteristic that the processing capacity of the service end is recovered and stabilized at a normal level after a series of service request loading and preheating when the service end is just started or does not receive a service request for a long time, the setting of the relation information of the single token extraction duration and the number of stored tokens according to the change condition of the processing capacity of the service end comprises: when the number of the stored tokens is greater than or equal to a preset threshold, the single token extraction duration is positively correlated to the number of the stored tokens, and when the number of the stored tokens is less than or equal to the preset threshold, the single token extraction duration is unchanged along with the change of the number of the stored tokens, so that the single token extraction duration can be changed based on the change of the processing capacity of the server.
In an alternative embodiment, the relationship information of the single token fetching duration and the number of stored tokens may be a function image of the single token fetching duration with respect to the number of stored tokens, where the horizontal axis of the function image represents the number of stored tokens and the vertical axis represents the single token fetching duration.
When constructing the function image of the single token extraction time length about the number of storage tokens, the maximum value of the number of storage tokens can be set according to actual requirements, the single token extraction time length corresponding to the maximum value of the number of storage tokens, the preset threshold value corresponding to the number of storage tokens and the single token extraction time length corresponding to the preset threshold value can be constructed based on the preset numerical values, the function image which can indicate that the single token extraction time length is positively related to the number of storage tokens when the number of storage tokens is greater than or equal to the preset threshold value, and the single token extraction time length remains unchanged along with the change of the number of storage tokens when the number of storage tokens is less than or equal to the preset threshold value.
Illustratively, the process of calculating the time length required for fetching the first number of tokens according to the first number, the second number and the relationship information of the preset single token fetch time length and the stored token number may include the following steps A1 to A2:
and A1, calculating the residual quantity obtained by subtracting the first quantity from the second quantity.
The first number refers to the number of tokens required by the service request to be processed, the second number refers to the number of tokens currently stored in the token bucket, and therefore, the difference between the second number and the first number refers to the number of tokens remaining in the token bucket after the tokens required by the service request to be processed are taken out from the tokens currently stored in the token bucket.
And A2, calculating the area surrounded by the partial function image between the residual quantity and the second quantity and the transverse axis, and taking the area as the time length required for taking out the tokens of the first quantity.
And intercepting a partial function image between the residual quantity and the second quantity from a function image of the single token extraction time length with respect to the quantity of the stored tokens, wherein the partial function image can represent the changing process of the corresponding single token extraction time length in the process of extracting the tokens (namely the first quantity of tokens) required by the service request to be processed from the tokens currently stored in the token bucket, namely each token in the first quantity of tokens to be extracted has a corresponding token extraction time length. The time length required for fetching the first number of tokens can be obtained by accumulating the time length for fetching each token in the first number of tokens. Therefore, in the embodiment of the present invention, the area surrounded by the partial function image and the horizontal axis may be calculated, and the calculated area is taken as the time length required for taking out the first number of tokens.
In an alternative embodiment, the function image of the number of stored tokens as a function of the single token fetch duration needs to be able to represent the following characteristics: when the number of the storage tokens is larger than or equal to a preset threshold value, the single token fetching time length is positively related to the number of the storage tokens, and when the number of the storage tokens is smaller than or equal to the preset threshold value, the single token fetching time length is unchanged along with the change of the number of the storage tokens. Thus, the function image may include a hyperbolic tangent function portion and a constant function portion, wherein the hyperbolic tangent function portion may represent that the single token fetch duration is positively correlated with the stored token number when the stored token number is equal to or greater than a preset threshold; the constant function portion may indicate that the single token fetch time length remains unchanged with a change in the number of stored tokens when the number of stored tokens is equal to or smaller than the preset threshold.
The expression corresponding to the function image of the single token fetching duration with respect to the number of stored tokens can be expressed as follows:
where y represents the single token fetch duration, x represents the number of stored tokens, x Representation ofMaximum value of preset number of storage tokens, x 0 And B represents the single token extraction time length corresponding to the preset threshold value, and A represents the coefficient of the hyperbolic tangent function part. Assuming that the single token fetch duration corresponding to the maximum value x 'of the preset number of stored tokens is D, then, according to tanh (Ax')=d and tanh (Ax 0 ) The coefficient a can be calculated by =b.
Referring to fig. 2, a schematic diagram of a functional image in an embodiment of the invention is shown. As shown in fig. 2, in the function image of the single token extraction duration with respect to the number of stored tokens, the straight line portion represents a constant function portion, the curve portion represents a hyperbolic tangent function portion, and a boundary point exists between the constant function portion and the hyperbolic tangent function portion, and the boundary point corresponds to the preset threshold value. The hyperbolic tangent function part can correspond to a cold start stage of a server, and in the cold start process, the single token fetching time length is reduced along with the reduction of the number of stored tokens. The constant function part can correspond to a stable stage after the cold start of the server is completed, and the single token taking-out duration is stable and unchanged after the cold start is completed.
Illustratively, the process of calculating the area enclosed by the partial function image between the remaining number and the second number and the horizontal axis may include the following cases:
(1) And under the condition that the residual quantity and the second quantity are both positioned in the hyperbolic tangent function part, carrying out integral calculation on the partial function image to obtain the area surrounded by the partial function image and the transverse axis.
The partial function image may be subjected to an integral calculation using an integral formula of a hyperbolic tangent function as shown below, for example:
wherein C represents a preset constant.
(2) And under the condition that the residual quantity and the second quantity are both positioned in the constant function part, calculating a rectangular area surrounded by the partial function image and the transverse axis, and obtaining the area surrounded by the partial function image and the transverse axis.
For example, the remaining number is x 1 The second number is x 2 And if the constant function part is y=b, the rectangular area enclosed by the partial function image and the transverse axis is: (x) 2 -x 1 )×B。
(3) And under the condition that the residual quantity is positioned in the constant function part and the second quantity is positioned in the hyperbolic tangent function part, carrying out integral calculation on the image positioned in the hyperbolic tangent function part in the partial function image to obtain a first area, calculating the rectangular area surrounded by the image positioned in the constant function part and the transverse axis in the partial function image to obtain a second area, and taking the sum of the first area and the second area as the area surrounded by the partial function image and the transverse axis.
For example, the remaining number is x 1 The second number is x 2 The preset threshold value is x 0 Then for x 1 And x 0 The function image between the two is calculated to obtain a rectangular area surrounded by the function image and the transverse axis to obtain a second area, and the function image is specific to x 0 And x 2 And integrating the function images to obtain a first area, calculating the sum of the first area and the second area, and taking the sum as the area surrounded by the partial function images and the transverse axis.
Step 103, after delaying the duration, taking out the first number of tokens to be distributed to the service request to be processed, and processing the service request to be processed.
After the time length required for taking out the first number of tokens is calculated, after the time length is delayed, the first number of tokens are taken out and distributed to the service request to be processed, and the service request to be processed is processed, so that more accurate current limiting can be further performed based on the current processing capacity of the server on the basis of token bucket current limiting. When the current processing capacity of the server is low, the time required for taking out the first number of tokens is also long, so that the delay time is long, and the processing pressure of the server can be low.
Fig. 3 is a flowchart illustrating steps of another service request processing method according to an embodiment of the present invention.
As shown in fig. 3, the service request processing method may include the steps of:
step 301, a first number of tokens required for a pending service request and a second number of currently stored tokens are obtained.
Step 302, determining whether the second number is greater than or equal to the first number. If yes, go to step 303; if not, return to step 302.
The first number represents the number of tokens required for the pending service request and the second number represents the number of currently stored tokens.
If the second number is greater than or equal to the first number, which indicates that the currently stored token can meet the requirement of the service request to be processed, step 303 may be continued in this case, and more accurate current limiting may be performed based on the processing capability of the server.
If the second number is smaller than the first number, it indicates that the currently stored token cannot meet the requirement of the service request to be processed, in this case, the server needs to wait for the token to be generated until the token stored in the token bucket can meet the requirement of the service request to be processed, and then step 303 is executed continuously.
Step 303, calculating the time length required for fetching the first number of tokens according to the first number, the second number and the preset relation information of the single token fetching time length and the number of stored tokens.
And step 304, after the time is delayed, the first number of tokens are taken out and distributed to the service request to be processed, and the service request to be processed is processed.
With respect to the specific procedures of step 303 and step 304, reference may be made to the above description of fig. 1, and this embodiment will not be discussed in detail here.
Fig. 4 is a block diagram of a service request processing device according to an embodiment of the present invention.
As shown in fig. 4, the service request processing apparatus may include the following modules:
an obtaining module 401, configured to obtain a first number of tokens required for the service request to be processed and a second number of currently stored tokens;
a calculating module 402, configured to calculate a duration required for extracting the first number of tokens according to the first number, the second number, and the preset relationship information between a single token extraction duration and a stored number of tokens; the relationship information includes: when the number of the storage tokens is larger than or equal to a preset threshold value, the single token fetching time length is positively related to the number of the storage tokens, and when the number of the storage tokens is smaller than or equal to the preset threshold value, the single token fetching time length is kept unchanged along with the change of the number of the storage tokens;
And the processing module 403 is configured to, after delaying the duration, take out the first number of tokens and allocate the tokens to the service request to be processed, and process the service request to be processed.
Optionally, the relation information is a function image, wherein a horizontal axis of the function image represents the number of the stored tokens, and a vertical axis represents the single token fetching duration; the computing module 402 includes: a first calculation unit configured to calculate a remaining number of the second number minus the first number; and the second calculating unit is used for calculating the area surrounded by the partial function images between the residual quantity and the second quantity and the transverse axis, and taking the area as the time length required for taking out the tokens of the first quantity.
Optionally, the function image includes a hyperbolic tangent function part, where the hyperbolic tangent function part indicates that the single token fetching duration is positively related to the number of stored tokens when the number of stored tokens is greater than or equal to a preset threshold.
Optionally, the function image includes a constant function part, where the constant function part indicates that the single token fetching time length remains unchanged with the change of the number of the storage tokens when the number of the storage tokens is less than or equal to the preset threshold value.
Optionally, the second computing unit includes: and the first calculating subunit is used for carrying out integral calculation on the partial function image to obtain the area surrounded by the partial function image and the transverse axis under the condition that the residual quantity and the second quantity are both positioned on the hyperbolic tangent function part.
Optionally, the second computing unit includes: the second calculating subunit is configured to calculate a rectangular area surrounded by the partial function image and the transverse axis to obtain an area surrounded by the partial function image and the transverse axis when the remaining number and the second number are both located in the constant function portion; and the third calculation subunit is used for carrying out integral calculation on the image positioned in the hyperbolic tangent function part in the partial function image to obtain a first area when the residual quantity is positioned in the constant function part and the second quantity is positioned in the hyperbolic tangent function part, calculating the rectangular area surrounded by the image positioned in the constant function part and the transverse axis in the partial function image to obtain a second area, and taking the sum of the first area and the second area as the area surrounded by the partial function image and the transverse axis.
Optionally, the apparatus further comprises: the judging module is used for judging whether the second number is larger than or equal to the first number; the calculating module 402 is specifically configured to calculate, when the determining module determines that the second number is greater than or equal to the first number, a duration required for extracting the first number of tokens according to the first number, the second number, and relationship information between a preset single token extraction duration and a stored token number.
In the embodiment of the invention, based on the characteristic that the processing capacity of the server is recovered and stabilized at a normal level after a series of service requests are loaded and preheated when the service is just started or the service request is not received for a long time, the relation information of the single token taking-out time length and the number of stored tokens is preset according to the change condition of the processing capacity of the server. The number of the storage tokens is used for representing the processing capacity of the server, and the larger the number of the storage tokens is, the smaller the number of the service requests currently received by the server is, and the worse the processing capacity of the server is at the moment; the single token fetching duration represents the speed of fetching tokens under the condition of corresponding stored token quantity, and the larger the stored token quantity is, the worse the processing capacity of the server side is indicated, and the longer the single token fetching duration is needed to carry out current limiting to a greater extent. Therefore, when the number of the stored tokens is larger than or equal to a preset threshold, the single token fetching time length is positively related to the number of the stored tokens, and when the number of the stored tokens is smaller than or equal to the preset threshold, the single token fetching time length is unchanged along with the change of the number of the stored tokens, so that the single token fetching time length can be changed based on the change of the processing capacity of the server. After receiving the service request to be processed, the current flow is limited according to the relation information of the preset single token extraction time length and the number of the stored tokens, so that the current processing capacity of the server can be more adapted, and the accuracy of the flow limitation is improved.
The embodiment of the invention also provides an electronic device, as shown in fig. 5, which comprises a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502 and the memory 503 complete communication with each other through the communication bus 504.
A memory 503 for storing a computer program;
the processor 501 is configured to execute the program stored in the memory 503, and implement the following steps:
acquiring a first number of tokens required by a service request to be processed and a second number of currently stored tokens;
calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the number of stored tokens; the relationship information includes: when the number of the storage tokens is larger than or equal to a preset threshold value, the single token fetching time length is positively related to the number of the storage tokens, and when the number of the storage tokens is smaller than or equal to the preset threshold value, the single token fetching time length is kept unchanged along with the change of the number of the storage tokens;
and after the time length is delayed, the first number of tokens are taken out and distributed to the service request to be processed, and the service request to be processed is processed.
Optionally, the relation information is a function image, wherein a horizontal axis of the function image represents the number of the stored tokens, and a vertical axis represents the single token fetching duration; the calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the stored token number, including: calculating the remaining number of the second number minus the first number; and calculating the area surrounded by the partial function images between the residual quantity and the second quantity and the transverse axis, and taking the area as the time length required for taking out the tokens of the first quantity.
Optionally, the function image includes a hyperbolic tangent function part, where the hyperbolic tangent function part indicates that the single token fetching duration is positively related to the number of stored tokens when the number of stored tokens is greater than or equal to a preset threshold.
Optionally, the function image includes a constant function part, where the constant function part indicates that the single token fetching time length remains unchanged with the change of the number of the storage tokens when the number of the storage tokens is less than or equal to the preset threshold value.
Optionally, the calculating an area surrounded by the partial function image between the remaining number and the second number and the horizontal axis includes: and under the condition that the residual quantity and the second quantity are both positioned in the hyperbolic tangent function part, carrying out integral calculation on the partial function image to obtain the area surrounded by the partial function image and the transverse axis.
Optionally, the calculating an area surrounded by the partial function image between the remaining number and the second number and the horizontal axis includes: calculating a rectangular area surrounded by the partial function image and the transverse axis under the condition that the residual quantity and the second quantity are both positioned in the constant function part, so as to obtain an area surrounded by the partial function image and the transverse axis; and under the condition that the residual quantity is positioned in the constant function part and the second quantity is positioned in the hyperbolic tangent function part, carrying out integral calculation on the image positioned in the hyperbolic tangent function part in the partial function image to obtain a first area, calculating the rectangular area surrounded by the image positioned in the constant function part and the transverse axis in the partial function image to obtain a second area, and taking the sum of the first area and the second area as the area surrounded by the partial function image and the transverse axis.
Optionally, before calculating the time period required for fetching the first number of tokens according to the first number, the second number, and the preset relation information of the single token fetch time period and the number of stored tokens, the method further includes: judging whether the second number is larger than or equal to the first number; the calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the stored token number, including: and when the second number is greater than or equal to the first number, calculating the time length required for taking out the first number of tokens according to the first number, the second number and the preset relation information of the single token taking-out time length and the number of stored tokens.
The communication bus mentioned by the above terminal may be a peripheral component interconnect standard (Peripheral ComponentInterconnect, abbreviated as PCI) bus or an extended industry standard architecture (Extended Industry StandardArchitecture, abbreviated as EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the terminal and other devices.
The memory may include random access memory (Random Access Memory, RAM) or non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; but also digital signal processors (Digital Signal Processing, DSP for short), application specific integrated circuits (Application SpecificIntegrated Circuit, ASIC for short), field-programmable gate arrays (Field-Programmable GateArray, FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present invention, a computer readable storage medium is provided, where instructions are stored, which when executed on a computer, cause the computer to implement the service request processing method according to any one of the foregoing embodiments.
In yet another embodiment of the present invention, a computer program product containing instructions that, when executed on a computer, cause the computer to implement the service request processing method according to any of the above embodiments is also provided.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (10)

1. A method for processing a service request, the method comprising:
acquiring a first number of tokens required by a service request to be processed and a second number of currently stored tokens;
calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the number of stored tokens; the relationship information includes: when the number of the storage tokens is larger than or equal to a preset threshold value, the single token fetching time length is positively related to the number of the storage tokens, and when the number of the storage tokens is smaller than or equal to the preset threshold value, the single token fetching time length is kept unchanged along with the change of the number of the storage tokens;
and after the time length is delayed, the first number of tokens are taken out and distributed to the service request to be processed, and the service request to be processed is processed.
2. The method of claim 1, wherein the relationship information is a function image, a horizontal axis of the function image representing the number of stored tokens and a vertical axis representing the single token retrieval duration; the calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the stored token number, including:
calculating the remaining number of the second number minus the first number;
and calculating the area surrounded by the partial function images between the residual quantity and the second quantity and the transverse axis, and taking the area as the time length required for taking out the tokens of the first quantity.
3. The method of claim 2, wherein the function image includes a hyperbolic tangent function portion that indicates that the single token fetch duration is positively correlated with the number of stored tokens when the number of stored tokens is greater than or equal to a preset threshold.
4. A method according to claim 2 or 3, wherein the function image comprises a constant function portion representing that the length of the single token fetch remains unchanged as the number of stored tokens changes when the number of stored tokens is equal to or less than the preset threshold.
5. A method according to claim 3, wherein said calculating the area enclosed by the partial function image between the remaining number and the second number and the transverse axis comprises:
and under the condition that the residual quantity and the second quantity are both positioned in the hyperbolic tangent function part, carrying out integral calculation on the partial function image to obtain the area surrounded by the partial function image and the transverse axis.
6. The method of claim 4, wherein said calculating an area enclosed by the partial function image and the horizontal axis between the remaining number and the second number comprises:
calculating a rectangular area surrounded by the partial function image and the transverse axis under the condition that the residual quantity and the second quantity are both positioned in the constant function part, so as to obtain an area surrounded by the partial function image and the transverse axis;
and under the condition that the residual quantity is positioned in the constant function part and the second quantity is positioned in the hyperbolic tangent function part, carrying out integral calculation on the image positioned in the hyperbolic tangent function part in the partial function image to obtain a first area, calculating the rectangular area surrounded by the image positioned in the constant function part and the transverse axis in the partial function image to obtain a second area, and taking the sum of the first area and the second area as the area surrounded by the partial function image and the transverse axis.
7. The method of claim 1, wherein the step of determining the position of the substrate comprises,
before calculating the time length required for fetching the first number of tokens according to the first number, the second number and the preset relation information of the single token fetching time length and the number of stored tokens, the method further comprises: judging whether the second number is larger than or equal to the first number;
the calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the stored token number, including: and when the second number is greater than or equal to the first number, calculating the time length required for taking out the first number of tokens according to the first number, the second number and the preset relation information of the single token taking-out time length and the number of stored tokens.
8. A service request processing apparatus, the apparatus comprising:
the acquisition module is used for acquiring a first number of tokens required by the service request to be processed and a second number of currently stored tokens;
the calculating module is used for calculating the time length required for extracting the first number of tokens according to the first number, the second number and the preset relation information of the single token extraction time length and the number of stored tokens; the relationship information includes: when the number of the storage tokens is larger than or equal to a preset threshold value, the single token fetching time length is positively related to the number of the storage tokens, and when the number of the storage tokens is smaller than or equal to the preset threshold value, the single token fetching time length is kept unchanged along with the change of the number of the storage tokens;
And the processing module is used for taking out the first number of tokens to be distributed to the service request to be processed after delaying the duration and processing the service request to be processed.
9. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method according to any of claims 1-7 when executing a program stored on a memory.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-7.
CN202310457420.1A 2023-04-25 2023-04-25 Service request processing method and device, electronic equipment and storage medium Pending CN116527589A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310457420.1A CN116527589A (en) 2023-04-25 2023-04-25 Service request processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310457420.1A CN116527589A (en) 2023-04-25 2023-04-25 Service request processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116527589A true CN116527589A (en) 2023-08-01

Family

ID=87400531

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310457420.1A Pending CN116527589A (en) 2023-04-25 2023-04-25 Service request processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116527589A (en)

Similar Documents

Publication Publication Date Title
US11605087B2 (en) Method and apparatus for identifying identity information
CN112650576B (en) Resource scheduling method, device, equipment, storage medium and computer program product
CN111597040B (en) Resource allocation method, device, storage medium and electronic equipment
CN107172171B (en) Service request processing method and device and computer readable storage medium
CN108390856B (en) DDoS attack detection method and device and electronic equipment
CN111367651A (en) Service current limiting system, method and device and electronic equipment
CN110020383B (en) Page data request processing method and device
CN111562884B (en) Data storage method and device and electronic equipment
CN111352791A (en) System application detection method and device, terminal equipment and storage medium
CN110069217B (en) Data storage method and device
CN116527589A (en) Service request processing method and device, electronic equipment and storage medium
CN107844593A (en) Video data placement method and device in a kind of Distributed Computing Platform
CN117118698A (en) Access flow limiting method, device and equipment of metadata server
CN110851286B (en) Thread management method and device, electronic equipment and storage medium
CN110351334B (en) Service request processing method and device and payment service request processing method and device
CN110187957B (en) Queuing method and device for downloading tasks and electronic equipment
CN114374657A (en) Data processing method and device
CN111666020B (en) Method and device for switching document pages, electronic equipment and storage medium
CN113051077A (en) User request processing method and device, terminal equipment and storage medium
CN117915476B (en) Information integration system processing method and system
CN115442432B (en) Control method, device, equipment and storage medium
CN116431327B (en) Task current limiting processing method and fort machine
CN113849133B (en) Processing method and device of privacy data, electronic equipment and storage medium
CN113568733B (en) Resource allocation method, device, electronic equipment and storage medium
CN110784479B (en) Data verification method and device, electronic equipment and storage medium

Legal Events

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