Request processing method, device, electronic device, storage medium and computer program product

By counting the number of requests in the service node and sending token issuance requests to the token bucket, tokens are distributed according to a preset cycle, which solves the problem of frequent token bucket interactions under high concurrency and improves the stability and efficiency of request processing. Adapt to traffic changes.

CN118413490BActive Publication Date: 2024-09-27CHENGDU NEW HOPE FINANCIAL INFORMATION CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410865521.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-09-27
Estimated Expiration
2044-07-01

AI Technical Summary

Technical Problem

In high-concurrency scenarios, frequent interactions with token buckets increase network pressure and affect the stability of request processing.

Method used

By counting the number of requests per unit time, if it reaches or exceeds the preset threshold, a token issuance request is sent to the token bucket, and tokens are distributed according to the preset period, reducing the frequency of interaction between the service node and the token bucket, and issuing tokens during the peak traffic period. Change the acquisition method to improve stability.

Benefits of technology

It reduces the access pressure on the token bucket, improves the stability and efficiency of request processing, adapts to traffic changes, and ensures the resource availability of the target service.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118413490B
    Figure CN118413490B
Patent Text Reader

Abstract

The present application provides a request processing method, device, electronic device, storage medium and computer program, which relate to the field of data processing technology. The method is applied to a service node; the method includes: counting the first number of requests received per unit time; if the first number of requests is not less than a first preset threshold, sending a first token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of first tokens to the service node according to a preset first token issuance cycle based on the first token issuance request; based on the first token, processing the requests received after the first number of requests is not less than the first preset threshold. The device is used to execute the above method. The present application changes the way the service node obtains tokens based on the traffic conditions of the service node, so that in the process of processing requests, the interaction with the token bucket is reduced, thereby reducing the access pressure of the token bucket and improving the stability of request processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a request processing method, device, electronic device, storage medium and computer program. Background Art

[0002] In computer networks, in order to solve the network congestion problem caused by burst network traffic, the traffic is sent out at a relatively uniform speed. The token bucket algorithm is the most commonly used algorithm in network traffic shaping and rate limiting. It can control the amount of data sent to the network and allow burst data to be sent.

[0003] In a multi-service node deployment scenario, every time a request arrives, the service needs to apply for a token from the token bucket, which requires frequent interactions with the token bucket. In a high-concurrency scenario, frequent network interactions will greatly increase the pressure on the token bucket, thus affecting the stability of request processing. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a request processing method, device, electronic device, storage medium and computer program, which are used to reduce the interaction with the token bucket during the process of processing the request, thereby reducing the access pressure of the token bucket and improving the stability of request processing.

[0005] In the first aspect, an embodiment of the present application provides a request processing method, which is applied to a service node; the method includes: counting the first number of requests received per unit time; if the first number of requests is not less than a first preset threshold, sending a first token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of first tokens to the service node based on the first token issuance request according to a preset first token issuance period; the first token issuance request is used to characterize that the service node passively obtains tokens from the service where the token bucket is located; and processing requests received after the first number of requests is not less than the first preset threshold based on the first token.

[0006] In the embodiment of the present application, after the server sends the first token issuance request to the service where the token bucket is located, the service where the token bucket is located actively distributes tokens to the service node according to the first token issuance cycle. Therefore, the service node does not apply for a token from the service where the token bucket is located to access the target service every time it receives a request, which reduces the frequency of interaction between the service node and the service where the token bucket is located, thereby reducing the access pressure of the service where the token bucket is located. In addition, the number of the first tokens distributed may be different in different token issuance cycles, which not only realizes the control of requests to access the target service through tokens, but also improves the stability of request processing.

[0007] In some embodiments, the method also includes: in the process of processing the requests received after the number of first requests is not less than the first preset threshold based on the first token, if the number of second requests received by any service node of the service where the service node is located is not less than the second preset threshold, then sending a first token acquisition request to the service where the token bucket is located to obtain the second token sent by the service where the token bucket is located; the second preset threshold is greater than the first preset threshold; the first token acquisition request is used to characterize that the service node actively obtains tokens from the service where the token bucket is located; based on the second token, processing the requests received after the number of second requests is not less than the second preset threshold.

[0008] In an embodiment of the present application, if the number of second requests received by any service node of the service where the service node is located is not less than the second preset threshold, it indicates that the service where the service node is located has entered a traffic peak. At this time, it is necessary to change the service node's passive token acquisition method to an active token acquisition method to improve the stability of request processing.

[0009] In some embodiments, after processing the request received after the number of second requests is not less than the second preset threshold based on the second token, the method also includes: if there exists in the service where the service node is located a target service node whose number of received requests is not less than the first preset threshold within a preset continuous time period, and the number of requests received by all service nodes of the service where the service node is located within the preset continuous time period is less than the second preset threshold, then the service node sends a second token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of third tokens to the service node according to the preset second token issuance cycle based on the second token issuance request.

[0010] In the embodiment of the present application, taking into account that the traffic situation of the service node is constantly changing, but the instantaneous or short-term changes are not sufficient to characterize the overall situation of the service node traffic, therefore, if the number of requests of all service nodes is less than the second preset threshold value within a continuous time period, and there is a service node whose number of requests is not less than the first preset threshold value, the token acquisition method is changed to improve the stability of request processing.

[0011] In some embodiments, the method also includes: in the process of processing requests received after the number of first requests is not less than a first preset threshold based on the first token, if the number of received requests is greater than the number of first tokens, sending a second token acquisition request to the service where the token bucket is located to obtain a fourth token sent by the service where the token bucket is located; the second token acquisition request is used to characterize that the service node actively obtains tokens from the service where the token bucket is located; and processing unprocessed requests according to the fourth token.

[0012] In the embodiment of the present application, when the pre-distributed tokens are not enough to process the received requests, the service node actively applies to the service where the token bucket is located to obtain tokens, thereby improving the efficiency and stability of request processing.

[0013] In some embodiments, after sending a first token acquisition request to the service where the token bucket is located, the method also includes: receiving a waiting identifier sent by the service where the token bucket is located, the waiting identifier includes a waiting time; sending the waiting identifier to a service node when there is no token in the token bucket; resending the first token acquisition request to the service where the token bucket is located according to the waiting time, and if the second token is not obtained, updating the waiting time based on the newly received waiting identifier; resending the first token acquisition request to the service where the token bucket is located based on the updated waiting time until the second token is obtained.

[0014] In an embodiment of the present application, if the token cannot be obtained for the first time, it indicates that there are no tokens available in the token bucket, which also indirectly indicates that the resources of the target service that needs to be accessed have reached the upper limit. At this time, the request of the service node needs to wait for processing, so as to improve the stability of request processing.

[0015] In some embodiments, the number of first tokens is dynamically calculated according to the following formula: ,in, represents the number of first tokens, represents the floor function, Indicates the total number of tokens remaining in the token bucket. Indicates percentage; Indicates the total number of service nodes of the service to which the service node belongs.

[0016] In the embodiment of the present application, considering that the number of tokens in the token bucket is changing dynamically, the number of first tokens is dynamically calculated through a formula, so that the number of first tokens distributed in each first token issuance cycle may be the same or different, thereby achieving flexible acquisition of different numbers of tokens and improving the flexibility of request processing. And by setting a percentage, there is always a certain amount of stock tokens in the token bucket to process burst traffic, thereby improving the stability of request processing.

[0017] In some embodiments, the service where the token bucket is located distributes a preset number of first tokens to the service node according to a preset first token issuance period based on the first token issuance request, including: determining the relationship between the number of tokens in the token bucket and the total number of service nodes of the service where the service node is located; if the number of tokens is greater than the total number of service nodes, executing the step of distributing a preset number of first tokens to the service node.

[0018] In the embodiment of the present application, taking into account the situation that the number of tokens may be insufficient for distribution, the step of distributing tokens is only executed when the number of tokens is sufficient for distribution. Therefore, the interaction frequency between the service where the token bucket is located and the service node is reduced to a certain extent, reducing the pressure on the token bucket, thereby improving the stability of the service where the token bucket is located, thereby improving the stability of request processing.

[0019] In some embodiments, the method further includes: if the number of requests received by all service nodes of the service where the service node is located is less than a first preset threshold, sending the request to the target service for processing.

[0020] In the embodiment of the present application, when the traffic is low, tokens are not used, but requests are processed directly, which improves the efficiency of request processing while reducing the frequency of interaction between the service node and the service where the token bucket is located.

[0021] In a second aspect, an embodiment of the present application provides a request processing device, which includes: a statistical module, which is used to count the first number of requests received per unit time; a token issuance module, which is used to send a first token issuance request to the service where the token bucket is located if the first number of requests is not less than a first preset threshold, so that the service where the token bucket is located distributes a preset number of first tokens to the service node based on the first token issuance request according to a preset first token issuance period; the first token issuance request is used to characterize that the service node passively obtains tokens from the service where the token bucket is located; and a processing module, which is used to process requests received after the first number of requests is not less than the first preset threshold based on the first token.

[0022] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, a storage medium and a bus, wherein the processor and the memory communicate with each other through the bus; the memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method steps of the first aspect.

[0023] In a fourth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium, comprising: the computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the method steps of the first aspect.

[0024] In a fifth aspect, an embodiment of the present application provides a computer program product, including: a computer program, which executes the method steps of the first aspect when executed by a processor.

[0025] Beneficial effects of this application:

[0026] In the embodiment of the present application, after the server sends the first token issuance request to the service where the token bucket is located, the service where the token bucket is located actively distributes tokens to the service node according to the first token issuance cycle. Therefore, the service node does not apply for a token from the service where the token bucket is located to access the target service every time it receives a request, which reduces the frequency of interaction between the service node and the service where the token bucket is located, thereby reducing the access pressure of the service where the token bucket is located. In addition, the number of distributed first tokens may be different in different token distribution cycles, which not only realizes the control of requests to access the target service through tokens, but also improves the stability of request processing. In addition, if the number of second requests received by any service node of the service where the service node is located is not less than the second preset threshold, it indicates that the service where the service node is located has entered a traffic peak. At this time, it is necessary to change the way the service node passively obtains tokens to the way it actively obtains tokens, thereby improving the stability of request processing.

[0027] Other features and advantages of the present application will be described in the subsequent description, and in part will become apparent from the description, or will be understood by implementing the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0029] Figure 1 A flowchart of a request processing method provided in an embodiment of the present application;

[0030] Figure 2 A schematic diagram of the structure of a request processing device provided in an embodiment of the present application;

[0031] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0032] The following embodiments of the technical solution of the present application will be described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.

[0033] It should be noted that all technical and scientific terms used in this document have the same meanings as those generally understood by technicians in the technical field to which this application belongs; the terms used in this document are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.

[0034] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.

[0035] Figure 1 A flow chart of a request processing method provided for an embodiment of the present application, the method is applied to a service node, it should be noted that the service node can run on a terminal device (also referred to as an electronic device) and a server; wherein the terminal device can specifically be a smart phone, a tablet computer, a computer, a personal digital assistant (PDA), etc.; the server can specifically be an application server or a Web server.

[0036] To facilitate understanding of the technical solution provided by the embodiment of the present application, the following takes the service node running in the server as an example to introduce the application scenario of the request processing method provided by the embodiment of the present application. Figure 1 As shown, the method includes:

[0037] Step S101: The server counts the number of first requests received per unit time.

[0038] Optionally, the unit time is a preset time, and 1 second, 10 seconds, or 1 minute can be set as a unit time, which can be set according to actual conditions.

[0039] Received requests refer to all requests that arrive at the service node within a unit time.

[0040] When each request arrives at the service node, the server automatically counts the requests arriving at the service node, thereby counting the number of requests received by the service node per unit time to obtain a first number of requests.

[0041] It should be noted that, since a service is distributed and deployed on multiple service nodes, the server counts the number of requests received by each service node separately.

[0042] Exemplarily, the service where the service node is located is service A, and service A includes 10 service nodes. The service node of the embodiment of the present application is any service node of service A. When counting, the server counts the number of requests received by the 10 service nodes of service A respectively.

[0043] Step S102, if the first request quantity is not less than the first preset threshold, the server sends a first token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of first tokens to the service node according to the preset first token issuance period based on the first token issuance request; the first token issuance request is used to represent that the service node passively obtains tokens from the service where the token bucket is located.

[0044] Step S103: The server processes the requests received after the first request quantity is not less than the first preset threshold based on the first token.

[0045] Optionally, the first preset threshold is pre-set based on historical traffic conditions of the service to which the service node belongs, and the traffic refers to the number of requests received per unit time.

[0046] For example, if one second is used as a unit time, the highest traffic of service A in the past 7 days is 10000 / S. Since service A includes 10 service nodes, The first preset threshold is set as the service node.

[0047] It should be noted that in the actual business processing process, in order to disperse the processing load, improve resource utilization and system reliability, a load balancing strategy is usually set for the cluster so that the requests entering the cluster are evenly distributed to each service node of the service. Therefore, the first preset threshold of each service node of service A is set to be the same.

[0048] Because each service node of service A accesses the same target service, as long as the number of first requests per unit time of one service node in service A is not less than the first preset threshold, it means that the access volume of the target service will gradually reach saturation. At the same time, since other service nodes of service A also access the target service, even if the number of first requests of other services does not reach the first preset threshold, it is considered to be greater than or equal to the first preset threshold.

[0049] For example, the target service accessed by service A is a database, and the number of connections set for the database is 10. At this time, the requests entering the cluster are evenly distributed to the 10 service nodes of service A based on the load balancing strategy. For example, request 1 is distributed to service node 1, request 2 is distributed to service node 2, request 3 is distributed to service node 3, and so on. After each service node is distributed a request, request 11 is distributed to service node 1, and the requests entering the cluster are distributed in turn.

[0050] If the previously arrived and distributed request is in the process of accessing the database, and request 31 is distributed to service node 1, but the database has not released the redundant connections at this time, request 31 will not be processed immediately. At this time, it is considered that the number of first requests of service node 1 is not less than the first preset threshold. Subsequent requests will be distributed to other service nodes in turn. Since request 31 has not been processed, subsequent requests that arrive and are distributed to other service nodes will still not be processed. At this time, the number of first requests of other service nodes is also considered to be not less than the first preset threshold.

[0051] Similarly, if the number of second requests per unit time of any service node in service A is not less than the second preset threshold, it is considered that the number of second requests of all service nodes of service A is not less than the second preset threshold.

[0052] Optionally, the first preset threshold may also be set based on the experience of the developer.

[0053] The preset first token issuance period is a preset value, for example, it is set that the service where the token bucket is located distributes a preset number of first tokens to the service node once every 1 second; for another example, it is set that the service where the token bucket is located distributes a preset number of first tokens to the service node once every 5 seconds. In actual applications, the first token issuance period can be set according to actual conditions.

[0054] It should be known that, because under the load balancing strategy, requests are evenly distributed to all nodes of service A, the service where the token bucket is located distributes the same number of first tokens to each service node of service A.

[0055] The preset number of first tokens may be a preset value based on the processing of historical requests, for example, 5 tokens or 6 tokens are distributed to each service node of service A every 5 seconds.

[0056] The preset number of first tokens can also be distributed according to the following formula, and the service where the token bucket is located dynamically calculates the number of remaining tokens in the token bucket and distributes them:

[0057]

[0058] in, represents the number of first tokens, represents the floor function, Indicates the total number of tokens remaining in the token bucket. Indicates percentage; Indicates the total number of service nodes in the service where the service node is located. Among them, the percentage It can be set according to actual situation.

[0059] For example, Set to 80%, the total capacity of the token bucket is 100, and the number of service nodes of service A is 10. In a token distribution cycle, if the number of tokens in the token bucket is 100, 80% of the tokens are distributed to each service node of service A. If the total number of tokens remaining in the token bucket is 81 during a token distribution cycle, 80% of them will be distributed to each service node of service A. tokens.

[0060] It should be noted that, since the number of tokens in the token bucket changes dynamically, when the number of first tokens is dynamically calculated by a formula, the number of first tokens distributed in each first token issuance cycle may be the same or different.

[0061] Optionally, the floor function may be replaced by a rounding method to obtain the number of distributed tokens.

[0062] It should also be noted that the purpose of setting the percentage when performing the calculation of the distribution token is to ensure that there is always a certain amount of stock tokens in the token bucket to handle burst traffic, thereby improving the stability of request processing.

[0063] Based on this, if the number of first requests of the service node counted by the server is not less than the first preset threshold, it indicates that the resources of the target service accessed by the service node are about to reach saturation. If the speed of the requests sent by the service node to the target service is not limited at this time, the processing speed of the target service will slow down or even crash in the future.

[0064] Therefore, the server sends a first token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of first tokens to the service node according to a preset first token issuance period based on the first token issuance request. The service node processes the requests received after the first request quantity is not less than the first preset threshold value through the first token distributed by the service where the token bucket is located.

[0065] The first token issuance request is used to indicate that the service node passively obtains tokens from the service where the token bucket is located. That is, when the resources of the target service are about to reach saturation, the service where the token bucket is located actively distributes a preset number of first tokens to the service node based on the first token issuance request sent by the service node.

[0066] In this process, after the server sends the first token issuance request to the service where the token bucket is located, the service where the token bucket is located actively distributes tokens to the service node according to the first token issuance cycle. Therefore, the service node does not apply for a token from the service where the token bucket is located to access the target service every time it receives a request, which reduces the frequency of interaction between the service node and the service where the token bucket is located, thereby reducing the access pressure on the service where the token bucket is located. In addition, the number of distributed first tokens may be different in different token issuance cycles, which not only realizes the control of requests to access the target service through tokens, but also improves the stability of request processing.

[0067] Optionally, taking the service where the service node is located as service A, the first preset threshold is 500, the first token issuance period is every 5 seconds, the target service accessed is a database, and the number of first tokens distributed is dynamically calculated by a formula as an example, the embodiment of the present application is described in detail:

[0068] If the number of first requests received by the service node per unit time counted by the server is not less than 500, the server sends a first token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of first tokens calculated by the formula to each service node of service A every 5 seconds based on the first token issuance request, so that the service node processes the requests received after the number of first requests is not less than the first preset threshold by using the preset number of first tokens.

[0069] In some embodiments, the method also includes: in the process of the server processing the requests received after the number of first requests is not less than the first preset threshold based on the first token, if the number of second requests received by any service node of the service where the service node is located is not less than the second preset threshold, the server sends a first token acquisition request to the service where the token bucket is located to obtain the second token sent by the service where the token bucket is located; the second preset threshold is greater than the first preset threshold; the first token acquisition request is used to characterize that the service node actively obtains tokens from the service where the token bucket is located; and the requests received after the number of second requests is not less than the second preset threshold are processed based on the second token.

[0070] Optionally, due to business characteristics, services may not only have low traffic peaks and moderate traffic, but also high traffic peaks. For example, during the Double Eleven event, the number of users shopping on Taobao increased dramatically, and the access to the database also increased dramatically. At this time, the service that initiates access to the database will reach a traffic peak. In order to improve the stability of the database, it is necessary to control the traffic accessing the database, thereby limiting the access to the database.

[0071] If the service enters a traffic peak, that is, the number of second requests received by any service node of the service where the service node is located is not less than the second preset threshold, the tokens are still distributed in the manner of actively distributing a preset number of first tokens to the service nodes according to the first token issuance cycle by the service where the token bucket is located. This will cause multiple requests to access the target service at the same time, but at this time the resources of the target service can no longer handle these multiple requests normally.

[0072] Therefore, in order to improve the stability of the target service, the server sends a first token acquisition request to the service where the token bucket is located, so that the service where the token bucket is located no longer actively distributes tokens to each service node, but sends a second token to the service node based on the first token acquisition request, so that the service node processes the requests received after the number of second requests is not less than the second preset threshold based on the second token.

[0073] It should be noted that a first token acquisition request can only obtain one second token. Therefore, for each service node of service A, upon receiving each request sent by the upstream service, a first token acquisition request will be sent to the service where the token bucket is located to obtain the corresponding second token to process the received request.

[0074] Optionally, is set as the second preset threshold of the service node. The second preset threshold value is set as the service node, as long as the second preset threshold value is greater than the first preset threshold value.

[0075] During this process, if the second number of requests received by any service node of the service where the service node is located is not less than the second preset threshold, it indicates that the service where the service node is located has entered a traffic peak. At this time, it is necessary to change the service node's passive token acquisition method to an active token acquisition method to improve the stability of request processing.

[0076] In some embodiments, after the server processes the request received after the number of second requests is not less than the second preset threshold based on the second token, the method also includes: if there exists in the service where the service node is located a target service node whose number of received requests is not less than the first preset threshold within a preset continuous time period, and the number of requests received by all service nodes of the service where the service node is located within the preset continuous time period is less than the second preset threshold, then the service node sends a second token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of third tokens to the service node according to the preset second token issuance cycle based on the second token issuance request.

[0077] Optional, since the traffic of the service is changing all the time, the traffic of the service may be at a peak in the last second, and at a low peak in the next second, or at a moderate level. According to the different traffic conditions of the service node, different token acquisition methods should be used to obtain tokens to reduce the interaction frequency between the service node and the service where the token bucket is located, so as to improve the stability of request processing.

[0078] However, instantaneous or short-term traffic changes are somewhat one-sided and are insufficient to characterize the overall traffic changes of the service node. Therefore, if there exists in the service where the service node is located a target service node whose number of received requests is not less than the first preset threshold within a preset continuous time period, and the number of requests received by all service nodes of the service where the service node is located within a preset continuous time period is less than the second preset threshold, it indicates that after a period of request processing, the traffic of the service where the service node is located has entered a moderate traffic state, and it also indicates that the available resources of the target service are gradually increasing. At this time, the token acquisition method should be changed, and the service node's active token acquisition method should be changed to a passive token acquisition method.

[0079] At this time, the service node sends a second token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of third tokens to the service node according to the preset second token issuance cycle based on the second token issuance request, thereby processing subsequent received requests through the third token.

[0080] The preset continuous time period is a preset value, which can be 30 consecutive seconds or 40 consecutive seconds. The second token issuance request is the same as the first token issuance request; the second token issuance cycle is the same as the first token issuance cycle; the third token is the same as the first token, and the calculation method of the preset number of third tokens is the same as the calculation method of the preset number of first tokens. That is, the preset number of third tokens can be a predefined value, or it can be calculated by the formula mentioned in the above embodiment.

[0081] In this process, considering that the traffic situation of the service nodes is constantly changing, but the instantaneous or short-term changes are not sufficient to characterize the overall situation of the service node traffic, therefore, if the number of requests of all service nodes is less than the second preset threshold within a continuous time period, and there is a service node whose number of requests is not less than the first preset threshold, the token acquisition method is changed to improve the stability of request processing.

[0082] In some embodiments, the method also includes: in the process of processing requests received after the number of first requests is not less than a first preset threshold based on the first token, if the number of requests received by the server is greater than the number of first tokens, a second token acquisition request is sent to the service where the token bucket is located to obtain a fourth token sent by the service where the token bucket is located; the second token acquisition request is used to characterize that the service node actively obtains tokens from the service where the token bucket is located; and unprocessed requests are processed according to the fourth token.

[0083] Optionally, since the service where the token bucket is located issues tokens according to a preset first token issuance cycle, in the actual process of processing requests, it is possible that the tokens pre-distributed in the service node have been used up before the next first token issuance cycle. That is, the number of requests received by the server is greater than the number of first tokens.

[0084] At this time, in order to allow the request to be processed normally and reduce the impact on the stability of the target service being accessed, the service node needs to send a second token acquisition request to the service where the token bucket is located to actively obtain the fourth token to process the unprocessed request. The second token acquisition request is the same as the first token acquisition request. The fourth token is the same as the second token.

[0085] It should be noted that one second token acquisition request can only obtain one fourth token. Therefore, before the next first token issuance cycle arrives, the service node needs to send as many second token acquisition requests to the service where the token bucket is located as there are requests left unprocessed to obtain the corresponding number of fourth tokens.

[0086] Exemplarily, the service where the token bucket is located issues a preset number of first tokens to each service node every 5 seconds, and one or several service nodes use up the pre-distributed tokens in the 4th second of the current cycle. Then these service nodes will obtain a token from the service where the token bucket is located for each request starting from the 4th second of the cycle.

[0087] In this process, when the pre-distributed tokens are not enough to process the received requests, the service node actively applies for tokens from the service where the token bucket is located, which improves the efficiency and stability of request processing.

[0088] In some embodiments, after the server sends a first token acquisition request to the service where the token bucket is located, the method also includes: the server receives a waiting identifier sent by the service where the token bucket is located, and the waiting identifier includes a waiting time; the waiting identifier is sent to a service node when there is no token in the token bucket; the server resends the first token acquisition request to the service where the token bucket is located according to the waiting time, and if the second token is not obtained, the server updates the waiting time based on the newly received waiting identifier; the server resends the first token acquisition request to the service where the token bucket is located based on the updated waiting time until the second token is obtained.

[0089] Optionally, since the tokens in the token bucket are generated according to a certain token generation strategy, for example, generating tokens at a constant speed, or generating all the tokens of the token bucket capacity at one time at a certain interval; and, in actual business, there may be burst traffic, after the service node sends the first token acquisition request to the service where the token bucket is located, there may not be any remaining tokens in the token bucket for the service node to use.

[0090] At this time, the service where the token bucket is located returns a waiting identifier to the service node, so that the service node resends the first token acquisition request to the service where the token bucket is located according to the waiting time in the waiting identifier until the second token is obtained.

[0091] It should be noted that after the server sends the second token acquisition request to the service where the token bucket is located, if it receives a waiting identifier sent by the service where the token bucket is located, the processing process is the same as the processing process after the server sends the first token acquisition request to the service where the token bucket is located, and will not be repeated here.

[0092] In this process, if the token cannot be obtained for the first time, it means that there are no tokens available in the token bucket. It also indirectly indicates that the resources of the target service that needs to be accessed have reached the upper limit. At this time, the request of the service node needs to wait for processing, thereby improving the stability of the target service and the stability of request processing.

[0093] In some embodiments, the service where the token bucket is located distributes a preset number of first tokens to the service node according to a preset first token issuance period based on the first token issuance request, including: determining the relationship between the number of tokens in the token bucket and the total number of service nodes of the service where the service node is located; if the number of tokens is greater than the total number of service nodes, executing the step of distributing a preset number of first tokens to the service node.

[0094] Optionally, since the tokens in the token bucket are also generated according to a certain token generation strategy, in a token distribution cycle, the number of tokens in the token bucket may be less than the total number of service nodes of the service where the service node is located. At this time, the service where the token bucket is located will not be able to evenly distribute tokens to each service node.

[0095] Therefore, before distributing a preset number of first tokens, it is necessary to determine the relationship between the number of tokens in the token bucket and the total number of service nodes served by the service node; only when the number of tokens is greater than the total number of service nodes, the step of distributing tokens is executed.

[0096] In this process, considering that the number of tokens may be insufficient for distribution, the step of distributing tokens is only executed when the number of tokens is sufficient for distribution. Therefore, the interaction frequency between the service where the token bucket is located and the service node is reduced to a certain extent, reducing the pressure on the token bucket, thereby improving the stability of the service where the token bucket is located, thereby improving the stability of request processing.

[0097] In some embodiments, the method further includes: if the number of requests received by all service nodes of the service where the service node is located is less than a first preset threshold, the server sends the request to the target service for processing.

[0098] Optionally, if the number of requests received by all service nodes of the service where the service node is located is less than the first preset threshold, it indicates that the available resources of the target service accessed by the service node are still sufficient. In this case, there is no need to limit the speed or use tokens, and the request can be directly sent to the target service for processing. While reducing the frequency of interaction between the service node and the service where the token bucket is located, the efficiency of request processing is improved.

[0099] Optionally, if the number of requests received by all service nodes of the service to which the service node belongs within the second preset continuous time period is lower than the first preset threshold, it also indicates that the available resources of the target service accessed by the service node are sufficient, and no speed limit is required, nor is a token required.

[0100] At this time, a stop token issuance request is sent to the service where the token bucket is located, so that the service where the token bucket is located no longer issues tokens to the service node, but the service node directly sends the request to the target service for processing. While reducing the frequency of interaction between the service node and the service where the token bucket is located, the efficiency of request processing is improved.

[0101] Figure 2 A schematic diagram of a request processing device provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the device includes: a statistics module 201, a token issuance module 202 and a processing module 203; wherein,

[0102] The statistical module 201 is used to count the first request quantity of the requests received per unit time; the token issuance module 202 is used to send a first token issuance request to the service where the token bucket is located if the first request quantity is not less than a first preset threshold value, so that the service where the token bucket is located distributes a preset number of first tokens to the service node according to a preset first token issuance period based on the first token issuance request; the first token issuance request is used to represent that the service node passively obtains tokens from the service where the token bucket is located; the processing module 203 is used to process the requests received after the first request quantity is not less than the first preset threshold value based on the first token.

[0103] Based on the above embodiment, the device also includes a second processing module, which is used to: in the process of processing the requests received after the number of first requests is not less than the first preset threshold based on the first token, if the number of second requests received by any service node of the service where the service node is located is not less than the second preset threshold, then send a first token acquisition request to the service where the token bucket is located to obtain the second token sent by the service where the token bucket is located; the second preset threshold is greater than the first preset threshold; the first token acquisition request is used to characterize that the service node actively obtains tokens from the service where the token bucket is located; based on the second token, process the requests received after the number of second requests is not less than the second preset threshold.

[0104] Based on the above embodiment, the device also includes a third processing module, which is used to: if there exists in the service where the service node is located a target service node whose number of received requests is not less than a first preset threshold within a preset continuous time period, and the number of requests received by all service nodes of the service where the service node is located within the preset continuous time period is less than a second preset threshold, then the service node sends a second token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of third tokens to the service node according to the preset second token issuance cycle based on the second token issuance request.

[0105] Based on the above embodiments, the device also includes a fourth processing module, which is used to: in the process of processing the requests received after the number of first requests is not less than the first preset threshold based on the first token, if the number of received requests is greater than the number of first tokens, send a second token acquisition request to the service where the token bucket is located to obtain a fourth token sent by the service where the token bucket is located; the second token acquisition request is used to characterize that the service node actively obtains tokens from the service where the token bucket is located; and process unprocessed requests according to the fourth token.

[0106] Based on the above embodiment, the second processing module is specifically used to: receive a waiting identifier sent by the service where the token bucket is located, the waiting identifier includes a waiting time; send the waiting identifier to the service node when there is no token in the token bucket; resend the first token acquisition request to the service where the token bucket is located according to the waiting time, and if the second token is not obtained, update the waiting time based on the newly received waiting identifier; resend the first token acquisition request to the service where the token bucket is located based on the updated waiting time until the second token is obtained.

[0107] Based on the above embodiment, the token issuing module 202 is specifically used to: dynamically calculate the number of first tokens according to the following formula: ,in, represents the number of first tokens, represents the floor function, Indicates the total number of tokens remaining in the token bucket. Indicates percentage; Indicates the total number of service nodes of the service to which the service node belongs.

[0108] Based on the above embodiment, the token issuance module 202 is specifically used to: determine the relationship between the number of tokens in the token bucket and the total number of service nodes of the service node; if the number of tokens is greater than the total number of service nodes, execute the step of distributing a preset number of first tokens to the service node.

[0109] Based on the above embodiment, the device further includes a fifth processing module, which is used to: if the number of requests received by all service nodes of the service where the service node is located is less than a first preset threshold, send the request to the target service for processing.

[0110] It should be understood that the device corresponds to the above-mentioned request processing method embodiment and can execute the various steps involved in the above-mentioned method embodiment. The specific functions of the device can be found in the above description. To avoid repetition, the detailed description is appropriately omitted here. The device includes at least one software function module that can be stored in a memory in the form of software or firmware or fixed in the operating system (OS) of the device.

[0111] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 3 As shown, the electronic device includes a processor 301 (processor), a memory 302 (memory) and a bus 303; wherein the processor 301 and the memory 302 communicate with each other through the bus 303. The processor 301 is used to call the program instructions in the memory 302 to execute the methods provided by the above-mentioned method embodiments.

[0112] The processor 301 may be an integrated circuit chip with signal processing capabilities. The processor 301 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. It may implement or execute various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0113] The memory 302 may include, but is not limited to, random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.

[0114] This embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments.

[0115] This embodiment provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable the computer to execute the methods provided by the above-mentioned method embodiments.

[0116] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0117] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0118] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0119] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A request processing method, It is characterized in that The method is applied to a service node; the method comprises: Count the number of first requests received per unit time; If the first request quantity is not less than a first preset threshold, a first token issuance request is sent to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of first tokens to the service node according to a preset first token issuance period based on the first token issuance request; the first token issuance request is used to indicate that the service node passively obtains tokens from the service where the token bucket is located; Processing, based on the first token, requests received after the number of the first requests is not less than the first preset threshold; In the process of processing the requests received after the number of the first requests is not less than the first preset threshold based on the first token, if the number of the received requests is greater than the number of the first tokens, a second token acquisition request is sent to the service where the token bucket is located to obtain a fourth token sent by the service where the token bucket is located; the second token acquisition request is used to represent that the service node actively obtains tokens from the service where the token bucket is located; The unprocessed request is processed according to the fourth token.

2. The method according to claim 1, It is characterized in that The method further comprises: In the process of processing the requests received after the first request quantity is not less than the first preset threshold based on the first token, if the second request quantity received by any service node of the service where the service node is located is not less than the second preset threshold, a first token acquisition request is sent to the service where the token bucket is located to obtain the second token sent by the service where the token bucket is located; the second preset threshold is greater than the first preset threshold; the first token acquisition request is used to represent that the service node actively obtains a token from the service where the token bucket is located; The requests received after the second request quantity is not less than the second preset threshold are processed based on the second token.

3. The method according to claim 2, It is characterized in that After processing the requests received after the second request quantity is not less than the second preset threshold based on the second token, the method further includes: If there exists in the service where the service node is located a target service node whose number of received requests is not less than the first preset threshold within a preset continuous time period, and the number of requests received by all service nodes of the service where the service node is located within the preset continuous time period is less than the second preset threshold, then the service node sends a second token issuance request to the service where the token bucket is located, so that the service where the token bucket is located distributes a preset number of third tokens to the service node according to the preset second token issuance cycle based on the second token issuance request.

4. The method according to any one of claims 2-3, It is characterized in that After sending the first token acquisition request to the service where the token bucket is located, the method further includes: receiving a waiting identifier sent by the service where the token bucket is located, wherein the waiting identifier includes a waiting time; and sending the waiting identifier to the service node when there is no token in the token bucket; Resending the first token acquisition request to the service where the token bucket is located according to the waiting time, and if the second token is not obtained, updating the waiting time based on the newly received waiting identifier; The first token acquisition request is resent to the service where the token bucket is located based on the updated waiting time until the second token is obtained.

5. The method according to any one of claims 1 to 3, It is characterized in that The number of the first tokens is dynamically calculated according to the following formula: in, represents the number of first tokens, represents the floor function, Indicates the total number of tokens remaining in the token bucket. Indicates percentage; Indicates the total number of service nodes of the service to which the service node belongs.

6. The method according to any one of claims 1 to 3, It is characterized in that The service where the token bucket is located distributes a preset number of first tokens to the service node according to a preset first token issuance period based on the first token issuance request, including: Determine the relationship between the number of tokens in the token bucket and the total number of service nodes of the service where the service node is located; If the number of the tokens is greater than the total number of service nodes, a step of distributing a preset number of first tokens to the service nodes is performed.

7. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: If the number of requests received by all service nodes of the service to which the service node belongs is less than the first preset threshold, the request is sent to the target service for processing.

8. A request processing device, It is characterized in that The device comprises: A statistics module, used for counting the number of first requests received per unit time; A token issuance module, configured to send a first token issuance request to the service where the token bucket is located if the first request quantity is not less than a first preset threshold value, so that the service where the token bucket is located distributes a preset number of first tokens to the service node according to a preset first token issuance period based on the first token issuance request; the first token issuance request is used to indicate that the service node passively obtains tokens from the service where the token bucket is located; a processing module, configured to process, based on the first token, requests received after the number of the first requests is not less than the first preset threshold; The device also includes a fourth processing module, which is used to send a second token acquisition request to the service where the token bucket is located to obtain a fourth token sent by the service where the token bucket is located, if the number of requests received is greater than the number of the first tokens during the process of processing the requests received after the number of the first requests is not less than the first preset threshold based on the first token; the second token acquisition request is used to represent that the service node actively obtains tokens from the service where the token bucket is located; and the unprocessed requests are processed according to the fourth token.

9. An electronic device, It is characterized in that include: A processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and when the machine-readable instructions are executed by the processor, the method according to any one of claims 1 to 7 is performed.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is executed.

11. A computer program product, It is characterized in that include: A computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is executed.