Distributed current limiting method, device, equipment, storage medium and system
By introducing the current limiting server and RPC mechanism in the distributed system, the complex and difficult current limiting solutions in the existing technology are solved, and the efficiency and convenience of the distributed system's current limiting are achieved.
Patent Information
- Application Number
- CN202010600562.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-28
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2040-06-28
AI Technical Summary
In the prior art, the current limiting solution of Redis cache service + lua script is complex and difficult to implement, and it is necessary to deploy Redis cache service and master lua scripts.
By introducing a current limiting server in the distributed system, using the remote procedure call (RPC) mechanism, the distributed node sends a request to the current limiting server to obtain the token generated by the token bucket algorithm module and determine whether to execute the pending request .
It realizes the efficiency and convenience of distributed system current limiting, avoids the deployment of Redis cache services, and does not require self-programming to implement current limiting solutions.
Smart Images

Figure CN113765818B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to computer technology, and in particular to a distributed current limiting method, apparatus, device, storage medium and system. Background Art
[0002] Since the Application Programming Interface (API) cannot control the behavior of the caller, when there is a sudden surge in requests, the API will occupy too many server resources, causing other requests to respond slowly or time out, or even worse, causing the server to crash. Therefore, it is necessary to limit the requests for application services, i.e. rate limiting, to protect the server.
[0003] For various reasons, online businesses are mostly distributed systems. The current limiting method for distributed systems is to combine Lua scripts and Redis cache services to achieve current limiting. For example, Lua scripts are written and run, and the calculation and query process of the number of requests is placed on the Redis side, so that the current limiting judgment can be completed with one request to Redis.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: the current limiting solution of Redis cache service + lua script requires the deployment of Redis cache service and the mastery of lua script, and the implementation process of the solution is complicated and difficult to implement. Summary of the invention
[0005] Embodiments of the present invention provide a distributed current limiting method, apparatus, device, storage medium and system to more conveniently and effectively implement distributed system current limiting.
[0006] In a first aspect, an embodiment of the present invention provides a distributed current limiting method, which is applied to a distributed node, including:
[0007] Obtain a pending request, and send a remote procedure call (RPC) request to a current limiting server according to the pending request, so that the current limiting server obtains a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request;
[0008] Determine whether to execute the pending request based on the response result of the current limiting server to the RPC request.
[0009] In a second aspect, an embodiment of the present invention further provides a distributed current limiting method, which is applied to a current limiting server, including:
[0010] Receive a remote procedure call (RPC) request sent by a distributed node, and acquire a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request;
[0011] The token acquisition result is sent to the distributed node as a response result to the RPC request, so that the distributed node determines whether to execute the pending request corresponding to the RPC request according to the response result.
[0012] In a third aspect, an embodiment of the present invention further provides a distributed current limiting device, which is configured at a distributed node, and includes:
[0013] A remote procedure call (RPC) request sending module is used to obtain pending requests and send a remote procedure call (RPC) request to a current limiting server according to the pending requests, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request;
[0014] The request processing module is used to determine whether to execute the pending request based on the response result of the current limiting server to the RPC request.
[0015] In a fourth aspect, an embodiment of the present invention further provides a distributed current limiting device, which is configured at a current limiting service end, and the device includes:
[0016] A token acquisition module is used to receive a remote procedure call (RPC) request sent by a distributed node, and acquire a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request;
[0017] The response result sending module is used to send the token acquisition result as the response result to the RPC request to the distributed node, so that the distributed node determines whether to execute the pending request corresponding to the RPC request according to the response result.
[0018] In a fifth aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:
[0019] one or more processors;
[0020] a storage device for storing one or more programs,
[0021] When the one or more programs are executed by the one or more processors, the one or more processors implement the distributed current limiting method applied to distributed nodes, or the distributed current limiting method applied to the current limiting server, provided in any embodiment of the present invention.
[0022] In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the distributed current limiting method applied to distributed nodes, or the distributed current limiting method applied to a current limiting server, provided in any embodiment of the present invention is implemented.
[0023] In a seventh aspect, an embodiment of the present invention further provides a distributed current limiting system, the system comprising: at least two distributed nodes and a current limiting server, wherein:
[0024] The distributed node is used to obtain a pending request, and send a remote procedure call (RPC) request to the current limiting server according to the pending request, and determine whether to execute the pending request according to a response result of the current limiting server to the RPC request;
[0025] The current limiting server is independent of the distributed node and is remotely connected to the distributed node for acquiring the token generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request, and sending the token acquisition result as a response to the RPC request to the distributed node.
[0026] The embodiment of the present invention obtains pending requests and sends a remote procedure call RPC request to the current limiting server according to the pending requests, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request; and determines whether to execute the pending request according to the response result of the current limiting server to the RPC request. The token bucket algorithm module that can only be applied to single-machine current limiting is deployed to an independent current limiting server, and then applied to the current limiting of the distributed system, so that each node in the distributed system remotely calls the token bucket current limiting service in the current limiting server through the RPC service to obtain the token for current limiting, which not only avoids the deployment of the Redis cache service, but also does not need to be programmed by itself to implement the current limiting solution, thereby improving the efficiency and convenience of the current limiting of the distributed system. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 is a flow chart of a distributed current limiting method applied to a distributed node in Embodiment 1 of the present invention;
[0028] Figure 2 is a flow chart of a distributed current limiting method applied to a distributed node in Embodiment 2 of the present invention;
[0029] Figure 3 is a flow chart of a distributed current limiting method applied to a current limiting server in Embodiment 3 of the present invention;
[0030] Figure 4is a structural schematic diagram of a distributed current limiting system in Embodiment 4 of the present invention;
[0031] Figure 5 It is a schematic diagram of the interaction process between a distributed node and a current limiting server in a distributed current limiting system in Embodiment 4 of the present invention;
[0032] Figure 6 It is a structural schematic diagram of a distributed current limiting device configured at a distributed node in Embodiment 5 of the present invention;
[0033] Figure 7 It is a structural schematic diagram of a distributed current limiting device configured at a current limiting service end in Embodiment 6 of the present invention;
[0034] Figure 8 It is a structural schematic diagram of an electronic device in Embodiment 7 of the present invention. DETAILED DESCRIPTION
[0035] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0036] Embodiment 1
[0037] The distributed current limiting method applied to distributed nodes provided in this embodiment can be applied to access current limiting of distributed systems. The method can be executed by a distributed current limiting device configured in a distributed node. The device can be implemented in software and / or hardware. The device can be integrated into an electronic device corresponding to a node in a distributed system, such as a desktop computer or a server. Figure 1 The distributed current limiting method applied to distributed nodes in this embodiment specifically includes:
[0038] S110, obtaining pending requests, and sending a remote procedure call RPC request to the current limiting server according to the pending requests, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request.
[0039] Among them, pending requests refer to external requests that need to be processed by distributed nodes. The current limiting server refers to the server that provides the current limiting service, which is deployed in a single machine. The remote procedure call (RPC) request refers to a request for remotely calling the current limiting service. The current limiting service here refers to a service based on the token bucket algorithm, that is, a token acquisition service, for example, it can be a current limiting service implemented by the rate limiting tool class ratelimiter based on the token bucket algorithm provided by the Google open source toolkit Guava.
[0040] In the related art, the token bucket algorithm is used for access current limiting, especially the mature current limiting tool class RateLimiter provided by the Google open source toolkit Guava. However, the current limiting tool class RateLimiter is only suitable for single-machine current limiting, and it cannot adapt to distributed environments. If the token bucket algorithm is to be applied to a distributed system, it is necessary to use a lua script to implement it by itself, and a Redis cache service needs to be deployed. Based on this, the current limiting tool class RateLimiter will not be used for distributed current limiting in the related art. However, the distributed current limiting of the Redis cache service combined with the lua script is relatively complex and difficult to implement. In order to improve the convenience of implementing distributed current limiting, the current limiting tool class RateLimiter is used for distributed current limiting in an embodiment of the present invention. Specifically: an independent server (i.e., a current limiting server) is set up, and the current limiting tool class RateLimiter is used in the current limiting server to implement the token bucket algorithm, which is used to produce tokens and provide tokens, and provide token acquisition services to the outside. At the same time, all distributed nodes register the remote procedure call RPC service to realize the remote call function between the current limiting server.
[0041] Based on the current limiting deployment of the above distributed system, when a distributed node receives a pending request, it first generates a remote procedure call RPC request based on the pending request and the calling rules of the token acquisition service in the current limiting server (such as calling method, required parameters, etc.). Then, the RPC request is sent to the current limiting server. After receiving the RPC request, the current limiting server calls the token acquisition service to obtain the requested token from the token bucket. Regardless of whether the requested token can be obtained, the current limiting server will feedback the response result of the RPC request to the distributed node.
[0042] Exemplarily, sending a remote procedure call (RPC) request to a current limiting server based on a pending request includes: determining a request token number based on request information of the pending request; and sending the RPC request to the current limiting server based on the request token number.
[0043] The request information refers to the relevant information of the pending request, such as the request content, request type, requested data packet size, etc. The request token number refers to the number of tokens required to execute the pending request.
[0044] Token bucket current limiting uses tokens generated at a uniform speed to control the processing of requests. If a token is obtained, the request can be executed. If a token is not obtained, the request will not be executed. The business corresponding to the pending request is different, the request content will also be different, and the number of tokens required to execute the request may also be different. Based on this, after obtaining the pending request, it is necessary to determine the number of request tokens based on the request information of the pending request, and then generate an RPC request based on the number of request tokens and send it to the current limiting server. For example, the number of request tokens can be determined based on the data packet size of the pending request and the amount of data corresponding to each token. The advantage of this setting is that it avoids sending the request information of the pending request to the current limiting server, which can not only improve the security of the pending request, but also reduce the amount of data of the RPC request, improve the efficiency of remote calls, and thus improve the current limiting efficiency of distributed nodes.
[0045] Exemplarily, determining the number of request tokens according to the request information of the request to be processed includes: determining the number of request tokens according to the target request type of the request to be processed and the corresponding relationship between the request type and the number of tokens.
[0046] If the pending request is a call request between a third-party service, and the third-party service has agreed on the number of tokens required for requests of different request types, then a correspondence between the request type and the number of tokens can be established. After obtaining the pending request, the distributed node can query the number of tokens corresponding to the pending request from the above correspondence according to the request type (i.e., the target request type) of the pending request, as the number of request tokens. For example, the task generation request (such as the request to generate an order) corresponding to the item acquisition task (such as a shopping order) in the e-commerce platform, the calling service is the order service in the third-party service, the request type is the order generation type, and the number of tokens corresponding to the order generation type request is agreed to be 2, then the number of request tokens is 2; for another example, the order query service in the third-party service is called, the request type is the order query type, and the agreed number of tokens is 1, then the number of request tokens is 1. The advantage of this setting is that when the pending request is an external service call request type, the number of request tokens is determined according to the agreement of the third-party service first, and if there is no agreement, it is determined according to the size of the data packet, which can improve the execution rate of important requests to a certain extent, further improve the intelligence and rationality of current limiting, and thus further improve the efficiency of distributed current limiting.
[0047] S120: Determine whether to execute the pending request based on the response result of the current limiting server to the RPC request.
[0048] After receiving the response result fed back by the current limiting server, the distributed node will determine whether to execute the pending request based on whether the response result is the requested token.
[0049] Exemplarily, S120 includes: if the response result is that the requested number of tokens are obtained, executing the pending request; if the response result is that the requested number of tokens are not obtained within the set time, determining the processing operation of the pending request based on the business level corresponding to the pending request.
[0050] Among them, the set time refers to a pre-set time period. Exemplarily, the set time is the request timeout of the remote procedure call RPC request, or the set waiting time in the RPC request. The request timeout refers to the timeout of any request for a remote call, which is set when the node registers the remote procedure call service. The set waiting time is a request parameter of the RPC request, which is given when the node calls the remote procedure call service. The advantage of this setting is that it can not only avoid long-term blocking of remote procedure calls, but also flexibly determine the call blocking time of the remote procedure call service, further improving the flexibility of distributed current limiting. Business level refers to the level set in advance according to the importance of the business. The more important the business, the higher the business level.
[0051] If the response result received by the distributed node is the token of the requested number of tokens, then the pending request is executed. If the response result is a feedback that the token has not been obtained due to the arrival of the set time, then the pending request cannot be executed. At this time, it is necessary to determine whether to continue to send RPC requests to the current limiting server to continue to obtain the token of the requested number of tokens based on the business level corresponding to the pending request. The advantage of this setting is that it can determine whether to continue to obtain tokens based on the business level of the pending request, distinguish the current limiting processes of important and non-important businesses, further improve the execution rate of important businesses, and thus further improve the flexibility of distributed current limiting.
[0052] The technical solution of this embodiment obtains pending requests and sends a remote procedure call RPC request to the current limiting server based on the pending requests, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling the token acquisition service based on the RPC request; and determines whether to execute the pending request based on the response result of the current limiting server to the RPC request. It realizes the deployment of the token bucket algorithm module that can only be applied to single-machine current limiting to an independent current limiting server, and then applies it to the current limiting of the distributed system, so that each node in the distributed system remotely calls the token bucket current limiting service in the current limiting server through the RPC service to obtain the token for current limiting, which not only avoids the deployment of the Redis cache service, but also does not need to program the current limiting solution by itself, thereby improving the efficiency and convenience of the current limiting of the distributed system.
[0053] Embodiment 2
[0054] Based on the above embodiment 1, this embodiment further optimizes "determining the processing operation of the request to be processed according to the service level corresponding to the request to be processed". The explanations of the terms that are the same or corresponding to the above embodiments are not repeated here.
[0055] See also Figure 2 The distributed current limiting method applied to distributed nodes provided in this embodiment includes:
[0056] S210: Obtain pending requests, and determine the number of request tokens based on request information of the pending requests.
[0057] S220. Send an RPC request to the current limiting server according to the requested token number, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request.
[0058] The token bucket algorithm module in the current limiting server is implemented using the current limiting tool class RateLimiter based on the token bucket algorithm provided by the Google open source toolkit Guava, and provides two calling interfaces, namely double acquire(int permits) and tryAcquire(int permits, long timeout), where permits represents the number of requested tokens and timeout represents the set waiting time. Distributed nodes can use the number of requested tokens (and the set waiting time) as function input parameters according to business needs (such as the flexibility of setting the time for remote call blocking), call the interface function acquire(int permits) (or tryAcquire(int permits, long timeout)), generate and send RPC requests to the current limiting server.
[0059] S203. If the response result is that the requested number of tokens is obtained, the pending request is executed.
[0060] S204: If the response result is that the requested number of tokens is not obtained within the set time, then when it is determined that the service level corresponding to the pending request is a high level, determine whether the number of RPC requests exceeds the preset number.
[0061] The number of RPC requests refers to the number of times RPC requests are sent to the current limiting server. The preset number of times refers to the preset number of allowed remote procedure calls.
[0062] If the response result of an RPC request is that the token is not obtained, then it is necessary to determine the service level of the corresponding pending service based on the pending request. If the service level is high, the pending request is an important request and needs to be executed as much as possible. At this time, the distributed node needs to determine whether the number of RPC requests corresponding to the pending request exceeds the preset number. Then execute S250 or S260.
[0063] S250: If the number of RPC requests does not exceed the preset number, return to execute S220.
[0064] If the number of RPC requests does not exceed the preset number, it means that the token can continue to be obtained and the process returns to step S220.
[0065] S260: If the number of RPC requests exceeds a preset number, cache or discard pending requests.
[0066] If the number of RPC requests exceeds the preset number, it means that the number of requests for the remote procedure call current limiting service has reached the upper limit, and no more RPC requests can be sent. At this time, the pending requests will be cached or discarded. If it is cached, wait for a period of time, or continue to request to obtain the token according to the business volume.
[0067] S270: If the response result is that the requested number of tokens are not obtained within the set time, then if the service level corresponding to the pending request is a low level, the pending request is cached or discarded.
[0068] If the token is not obtained and the business level corresponding to the pending request is low, it means that the pending request is not an important request. In order to improve business processing efficiency and current limiting efficiency, the pending request can be directly cached or discarded without repeated request process to obtain the token.
[0069] The technical solution of this embodiment is that if the response result is that the token of the requested number of tokens has not been obtained within the set time, then when the service level corresponding to the pending request is a low level, the pending request is cached or discarded. The processing operation of low-level pending requests is realized, which avoids excessive occupation of resources by unimportant pending requests, improves the request processing efficiency of distributed nodes, and further improves the distributed current limiting efficiency. If the response result is that the token of the requested number of tokens has not been obtained within the set time, then when it is determined that the service level corresponding to the pending request is a high level, it is determined whether the number of RPC requests exceeds the preset number; if not, it returns to the step of sending a remote procedure call RPC request to the current limiting server based on the pending request. The processing operation of high-level pending requests is realized, and the execution of important pending requests is ensured as much as possible. On the basis of improving the rationality of distributed current limiting, the efficiency of request processing is further taken into account.
[0070] Embodiment 3
[0071] The distributed current-limiting method applied to the current-limiting server provided in this embodiment is applicable to access current-limiting in a distributed system. This method can be executed by a distributed current-limiting device configured in the current-limiting server. This device can be implemented in software and / or hardware, and can be integrated in an electronic device corresponding to the current-limiting server, such as a desktop computer or a server, etc. Among them, the explanations of the same or corresponding terms as those in the above embodiments will not be elaborated here.
[0072] See Figure 3 , the distributed current-limiting method applied to the current-limiting server in this embodiment specifically includes:
[0073] S310. Receive a Remote Procedure Call (RPC) request sent by a distributed node, and obtain tokens generated by the token bucket algorithm module by invoking a token acquisition service according to the RPC request.
[0074] The token bucket algorithm module in the current-limiting server is implemented using the rate-limiting tool class RateLimiter based on the token bucket algorithm provided by the Google open-source toolkit Guava. For example, by RateLimiter rateLimiter = RateLimiter.create(limiting value), the com.google.common.util.concurrent.RateLimiter is implemented to construct a method for adding tokens. Here, the limiting value is the upper limit of the tokens that can be stored in the token bucket.
[0075] When the current-limiting server receives an RPC request sent by a distributed node, such as an RPC request generated by invoking the interface function acquire(int permits), it parses the RPC request to obtain the requested number of tokens. Then, the current-limiting server keeps blocking and invokes the token acquisition service to obtain the tokens generated by the token bucket algorithm module until it obtains the tokens of the requested number of tokens. If enough tokens are obtained before the request timeout time is reached, the tokens of the requested number of tokens are returned to the distributed node as the response result. If the blocking duration reaches the request timeout time of the remote procedure call but the tokens of the requested number of tokens are still not obtained, then the current-limiting server will feedback a remote procedure call error message to the distributed node, and this error message will be used as the response result of the RPC request, indicating that the tokens of the requested number of tokens have not been obtained within the set time. It should be noted that taking the open-source distributed service framework dubbo as an example, the global configuration of the request timeout time can be exemplified as: <dubbo:consumer timeout = "request timeout time set according to business requirements">.
[0076] When the current limiting server receives an RPC request sent by a distributed node, such as an RPC request generated by calling the interface function tryAcquire(int permits, long timeout), it parses the RPC request to obtain the requested number of tokens and the set waiting time. Then, the current limiting server calls the token acquisition service to obtain the token generated by the token bucket algorithm module. If the tokens of the requested number of tokens are obtained within the set waiting time, the tokens are returned to the distributed node as the response result. If the set waiting time is reached and the tokens of the requested number of tokens are still not obtained, the current limiting server will feedback the remote procedure call error information to the distributed node, and the error information will be used as the response result of the RPC request, indicating that the tokens of the requested number of tokens were not obtained within the set time.
[0077] S320. Send the token acquisition result as a response result to the RPC request to the distributed node, so that the distributed node determines whether to execute the pending request corresponding to the RPC request according to the response result.
[0078] The technical solution of this embodiment is to receive the remote procedure call RPC request sent by the distributed node, and obtain the token generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request; the token acquisition result is sent to the distributed node as the response result to the RPC request, so that the distributed node determines whether to execute the pending request corresponding to the RPC request according to the response result. It realizes the deployment of the token bucket algorithm module that can only be applied to single-machine current limiting to an independent current limiting server, and then applies it to the current limiting of the distributed system, so that each node in the distributed system remotely calls the token bucket current limiting service in the current limiting server through the RPC service to obtain the token for current limiting, which not only avoids the deployment of the Redis cache service, but also does not need to program the current limiting solution by itself, thereby improving the efficiency and convenience of the current limiting of the distributed system.
[0079] Embodiment 4
[0080] This embodiment provides a distributed current limiting system. Figure 4 The system specifically includes: at least two distributed nodes 420 and a current limiting server 410, wherein:
[0081] The distributed node 420 is used to obtain the pending request, and send a remote procedure call RPC request to the current limiting server according to the pending request, and determine whether to execute the pending request according to the response result of the current limiting server to the RPC request;
[0082] The current limiting server 410 is independent of the distributed nodes and is remotely connected to the distributed nodes for acquiring the token generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request, and sending the token acquisition result as a response to the RPC request to the distributed nodes.
[0083] See also Figure 5 , taking the interaction between a distributed node 420 and a current limiting server 410 as an example, the current limiting process is as follows: after the distributed node 420 obtains the pending request, it generates an RPC request according to the pending request and sends it to the current limiting server 410. The current limiting server 410 calls the token acquisition service therein to obtain the token generated by the token bucket algorithm module, executes the token acquisition logic, and returns the token acquisition result as a response result to the distributed node 420. The distributed node 420 determines whether to execute the pending request based on whether the response result contains the token of the requested number of tokens.
[0084] Optionally, the distributed node 420 includes:
[0085] A request token number determination module, used to determine the request token number according to the request information of the request to be processed;
[0086] The RPC request sending module is used to send RPC requests to the current limiting server based on the number of request tokens.
[0087] Furthermore, the request token number determination module is specifically used for:
[0088] The number of request tokens is determined according to the target request type of the request to be processed and the corresponding relationship between the request type and the number of tokens.
[0089] Optionally, the distributed node 420 includes:
[0090] A request execution module, used for executing the pending request if the response result is that the requested number of tokens are obtained;
[0091] The request processing operation determination module is used to determine the processing operation of the request to be processed according to the service level corresponding to the request to be processed if the response result is that the requested number of tokens are not obtained within the set time.
[0092] The set time is a request timeout time of a remote procedure call (RPC) request, or a set waiting time in an RPC request.
[0093] Furthermore, the request processing operation determination module is specifically used for:
[0094] In the case where it is determined that the service level corresponding to the pending request is a high level, determining whether the number of RPC requests exceeds a preset number;
[0095] If not, return to the step of sending a remote procedure call RPC request to the current limiting server based on the pending request.
[0096] Optionally, the request processing operation determination module is specifically used to:
[0097] When the service level corresponding to the pending request is low, the pending request is cached or discarded.
[0098] Through a distributed current limiting system of the fourth embodiment of the present invention, it is possible to deploy a token bucket algorithm module that is only applicable to single-machine current limiting to an independent current limiting server, and then apply it to the current limiting of the distributed system, so that each node in the distributed system remotely calls the token bucket current limiting service in the current limiting server through the RPC service to obtain tokens for current limiting, which not only avoids the deployment of the Redis cache service, but also eliminates the need for self-programming to implement the current limiting solution, thereby improving the efficiency and convenience of the current limiting of the distributed system.
[0099] Embodiment 5
[0100] This embodiment provides a distributed current limiting device, which is configured in a distributed node. Figure 6 , the device specifically comprises:
[0101] A remote procedure call (RPC) request sending module 610 is used to obtain pending requests and send a remote procedure call (RPC) request to a current limiting server according to the pending requests, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request.
[0102] The request processing module 620 is used to determine whether to execute the pending request based on the response result of the current limiting server to the RPC request.
[0103] Optionally, the remote procedure call (RPC) request sending module 610 includes:
[0104] A request token number determination submodule, used to determine the request token number based on the request information of the request to be processed;
[0105] The RPC request sending submodule is used to send RPC requests to the current limiting server based on the number of request tokens.
[0106] Furthermore, the request token number determination submodule is specifically used for:
[0107] The number of request tokens is determined according to the target request type of the request to be processed and the corresponding relationship between the request type and the number of tokens.
[0108] Optionally, the request processing module 620 includes:
[0109] The request execution submodule is used to execute the pending request if the response result is to obtain the requested number of tokens;
[0110] The request processing operation determination submodule is used to determine the processing operation of the request to be processed according to the service level corresponding to the request to be processed if the response result is that the requested number of tokens are not obtained within the set time.
[0111] The set time is a request timeout time of a remote procedure call (RPC) request, or a set waiting time in an RPC request.
[0112] Furthermore, the request processing operation determines that the submodule is specifically used for:
[0113] In the case where it is determined that the service level corresponding to the pending request is a high level, determining whether the number of RPC requests exceeds a preset number;
[0114] If not, return to the step of sending a remote procedure call RPC request to the current limiting server based on the pending request.
[0115] Optionally, the request processing operation determines that the submodule is specifically used for:
[0116] When the service level corresponding to the pending request is low, the pending request is cached or discarded.
[0117] Through the distributed current limiting device configured in the distributed node of the fifth embodiment of the present invention, it is possible to deploy the token bucket algorithm module that can only be applied to single-machine current limiting to an independent current limiting server, and then apply it to the current limiting of the distributed system, so that each node in the distributed system remotely calls the token bucket current limiting service in the current limiting server through the RPC service to obtain tokens for current limiting, which not only avoids the deployment of the Redis cache service, but also eliminates the need for self-programming to implement the current limiting solution, thereby improving the efficiency and convenience of the current limiting of the distributed system.
[0118] The distributed current limiting device configured at a distributed node provided in an embodiment of the present invention can execute the distributed current limiting method applied to a distributed node provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0119] Embodiment 6
[0120] This embodiment provides a distributed current limiting device configured at a current limiting service end, see Figure 7 , the device specifically comprises:
[0121] The token acquisition module 710 is used to receive a remote procedure call (RPC) request sent by a distributed node, and acquire the token generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request;
[0122] The response result sending module 720 is used to send the token acquisition result as the response result to the RPC request to the distributed node, so that the distributed node determines whether to execute the pending request corresponding to the RPC request according to the response result.
[0123] Optionally, the token acquisition module 710 is specifically used for:
[0124] According to the number of requested tokens in the RPC request, the token generated by the token bucket algorithm module is obtained by calling the token acquisition service within the set time.
[0125] The set time is a request timeout time of a remote procedure call (RPC) request, or a set waiting time in an RPC request.
[0126] Optionally, the token acquisition module 710 is further specifically configured to:
[0127] If the requested number of tokens is obtained within the set time, the tokens are used as token acquisition results;
[0128] If the requested number of tokens is not obtained within the set time, the remote procedure call error information is used as the token acquisition result.
[0129] Through a distributed current limiting device configured at a current limiting service end according to the sixth embodiment of the present invention, it is possible to deploy a token bucket algorithm module that is only applicable to single-machine current limiting to an independent current limiting server, and then apply it to the current limiting of a distributed system, so that each node in the distributed system remotely calls the token bucket current limiting service in the current limiting server through an RPC service to obtain tokens for current limiting, which not only avoids the deployment of a Redis cache service, but also eliminates the need for self-programming to implement the current limiting solution, thereby improving the efficiency and convenience of current limiting in the distributed system.
[0130] The distributed current limiting device configured at the current limiting server provided in the embodiment of the present invention can execute the distributed current limiting method applied to the current limiting server provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0131] It is worth noting that in the embodiments of the above-mentioned distributed current limiting device / system, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0132] Embodiment 7
[0133] See also Figure 8This embodiment provides an electronic device 800, which includes: one or more processors 820; a storage device 810, which is used to store one or more programs. When the one or more programs are executed by the one or more processors 820, the one or more processors 820 implement the distributed current limiting method applied to distributed nodes provided by the embodiment of the present invention, including:
[0134] Obtain pending requests, and send a remote procedure call (RPC) request to the current limiting server based on the pending requests, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling the token acquisition service based on the RPC request;
[0135] Determine whether to execute the pending request based on the response of the current limiting server to the RPC request.
[0136] Of course, those skilled in the art can understand that the processor 820 can also implement the technical solution of the distributed current limiting method applied to distributed nodes provided by any embodiment of the present invention.
[0137] Figure 8 The electronic device 800 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0138] like Figure 8 As shown, the electronic device 800 is in the form of a general-purpose computing device. The components of the electronic device 800 may include, but are not limited to: one or more processors 820, a storage device 810, and a bus 850 connecting different system components (including the storage device 810 and the processor 820).
[0139] Bus 850 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.
[0140] The electronic device 800 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 800, including volatile and non-volatile media, removable and non-removable media.
[0141] The storage device 810 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 811 and / or cache memory 812. The electronic device 800 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 813 may be used to read and write non-removable, non-volatile magnetic media ( Figure 8 not shown, usually called a "hard drive"). Although Figure 8 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 850 via one or more data medium interfaces. The storage device 810 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the embodiments of the present invention.
[0142] A program / utility 814 having a set (at least one) of program modules 815 may be stored, for example, in a storage device 810, such program modules 815 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination thereof may include an implementation of a network environment. The program modules 815 generally perform the functions and / or methods of any embodiment described herein.
[0143] The electronic device 800 may also communicate with one or more external devices 860 (e.g., keyboards, pointing devices, displays 870, etc.), one or more devices that enable a user to interact with the electronic device 800, and / or any device that enables the electronic device 800 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output interface (I / O interface) 830. Furthermore, the electronic device 800 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 840. Figure 8 As shown, the network adapter 840 communicates with other modules of the electronic device 800 via the bus 850. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0144] The processor 820 executes various functional applications and data processing by running the programs stored in the storage device 810, such as implementing the distributed current limiting method applied to distributed nodes provided in the embodiment of the present invention.
[0145] The embodiment of the present invention further provides another electronic device, which includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the distributed current limiting method applied to the current limiting server provided in the embodiment of the present invention, including:
[0146] Receive the remote procedure call (RPC) request sent by the distributed node, and obtain the token generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request;
[0147] The token acquisition result is sent to the distributed node as a response result to the RPC request, so that the distributed node determines whether to execute the pending request corresponding to the RPC request based on the response result.
[0148] Of course, those skilled in the art can understand that the processor can also implement the technical solution of the distributed current limiting method applied to the current limiting server provided in any embodiment of the present invention. The hardware structure and function of the electronic device can refer to the explanation of the content of embodiment 7.
[0149] Embodiment 8
[0150] This embodiment provides a storage medium including computer executable instructions. When the computer executable instructions are executed by a computer processor, they are used to execute a distributed current limiting method applied to distributed nodes. The method includes:
[0151] Obtain pending requests, and send a remote procedure call (RPC) request to the current limiting server based on the pending requests, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling the token acquisition service based on the RPC request;
[0152] Determine whether to execute the pending request based on the response of the current limiting server to the RPC request.
[0153] Of course, the storage medium containing computer executable instructions provided in an embodiment of the present invention is not limited to the above method operations, and the computer executable instructions can also execute related operations in the distributed current limiting method applied to distributed nodes provided in any embodiment of the present invention.
[0154] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0155] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0156] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0157] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0158] The embodiment of the present invention further provides another computer-readable storage medium, wherein the computer executable instructions are used to execute a distributed current limiting method applied to a current limiting server when executed by a computer processor, the method comprising:
[0159] Receive the remote procedure call (RPC) request sent by the distributed node, and obtain the token generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request;
[0160] The token acquisition result is sent to the distributed node as a response result to the RPC request, so that the distributed node determines whether to execute the pending request corresponding to the RPC request based on the response result.
[0161] Of course, the computer executable instructions of the storage medium provided in the embodiment of the present invention are not limited to the above method operations, but can also execute the related operations in the distributed current limiting method applied to the current limiting server provided in any embodiment of the present invention. For the introduction of the storage medium, please refer to the content explanation in the eighth embodiment.
[0162] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A distributed current limiting method, characterized in that: Applicable to distributed nodes, including: Obtain a pending request, and send a remote procedure call (RPC) request to a current limiting server according to the pending request, so that the current limiting server obtains a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request; Determine whether to execute the pending request according to the response result of the current limiting server to the RPC request; Wherein, determining whether to execute the pending request according to the response result of the current limiting server to the RPC request includes: If the response result is that the requested number of tokens is obtained, the pending request is executed; If the response result is that the requested number of tokens is not obtained within the set time, determining the processing operation of the pending request according to the service level corresponding to the pending request; The determining, according to the service level corresponding to the request to be processed, a processing operation for the request to be processed includes: In the case where it is determined that the service level corresponding to the pending request is a high level, determining whether the number of RPC requests exceeds a preset number; If not, return to the step of sending a remote procedure call (RPC) request to the current limiting server based on the pending request.
2. The method according to claim 1, characterized in that According to the pending request, sending a remote procedure call (RPC) request to the current limiting server includes: Determining the number of request tokens according to the request information of the request to be processed; Send the RPC request to the current limiting server according to the number of request tokens.
3. The method according to claim 2, characterized in that Determining the number of request tokens according to the request information of the request to be processed includes: The request token number is determined according to the target request type of the request to be processed and the corresponding relationship between the request type and the token number.
4. The method according to claim 1, characterized in that Determining a processing operation for the request to be processed according to the service level corresponding to the request to be processed includes: When the service level corresponding to the pending request is low, the pending request is cached or discarded.
5. The method according to claim 1, characterized in that The set time is a request timeout time of a remote procedure call (RPC) request, or a set waiting time in the RPC request.
6. A distributed current limiting method, characterized in that: Applied to the current limiting server, including: Receive a remote procedure call (RPC) request sent by a distributed node, and acquire a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request; Sending the token acquisition result as a response result to the RPC request to the distributed node, so that the distributed node determines whether to execute the pending request corresponding to the RPC request according to the response result; Wherein, determining whether to execute the pending request corresponding to the RPC request according to the response result includes: If the response result is that the requested number of tokens is obtained, the pending request is executed; If the response result is that the requested number of tokens is not obtained within the set time, determining the processing operation of the pending request according to the service level corresponding to the pending request; The determining, according to the service level corresponding to the request to be processed, a processing operation for the request to be processed includes: In the case where it is determined that the service level corresponding to the pending request is a high level, determining whether the number of RPC requests exceeds a preset number; If not, return to the step of sending a remote procedure call (RPC) request to the current limiting server based on the pending request.
7. A distributed current limiting device, characterized in that: Configured on distributed nodes, including: A remote procedure call (RPC) request sending module is used to obtain pending requests and send a remote procedure call (RPC) request to a current limiting server according to the pending requests, so that the current limiting server obtains the token generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request; A request processing module, used to determine whether to execute the pending request according to the response result of the current limiting server to the RPC request; Wherein, the request processing module includes: A request execution submodule, configured to execute the pending request if the response result is that the requested number of tokens is obtained; A request processing operation determination submodule, used to determine a processing operation for the pending request according to the service level corresponding to the pending request if the response result is that the requested number of tokens is not obtained within a set time; The request processing operation determination submodule is specifically used for: In the case where it is determined that the service level corresponding to the pending request is a high level, determining whether the number of RPC requests exceeds a preset number; If not, return to the step of sending a remote procedure call (RPC) request to the current limiting server based on the pending request.
8. A distributed current limiting device, characterized in that: Configured on the current limiting server, including: A token acquisition module is used to receive a remote procedure call (RPC) request sent by a distributed node, and acquire a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request; A response result sending module, used for sending the token acquisition result as a response result to the RPC request to the distributed node, so that the distributed node determines whether to execute the pending request corresponding to the RPC request according to the response result; Wherein, determining whether to execute the pending request corresponding to the RPC request according to the response result includes: If the response result is that the requested number of tokens is obtained, the pending request is executed; If the response result is that the requested number of tokens is not obtained within the set time, determining the processing operation of the pending request according to the service level corresponding to the pending request; The determining, according to the service level corresponding to the request to be processed, a processing operation for the request to be processed includes: In the case where it is determined that the service level corresponding to the pending request is a high level, determining whether the number of RPC requests exceeds a preset number; If not, return to the step of sending a remote procedure call (RPC) request to the current limiting server based on the pending request.
9. An electronic device, characterized in that: The electronic device comprises: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the distributed current limiting method applied to distributed nodes as described in any one of claims 1-5, or the distributed current limiting method applied to the current limiting server as described in claim 6.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it implements the distributed current limiting method applied to a distributed node as described in any one of claims 1 to 5, or the distributed current limiting method applied to a current limiting server as described in claim 6.
11. A distributed current limiting system, characterized in that: The system includes: at least two distributed nodes and a current limiting server, wherein: The distributed node is used to obtain a pending request, and send a remote procedure call RPC request to the current limiting server according to the pending request, and determine whether to execute the pending request according to the response result of the current limiting server to the RPC request; the current limiting server is independent of the distributed node and is remotely communicated with the distributed node, and is used to obtain a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request, and send the token acquisition result as a response result to the RPC request to the distributed node; Wherein, the distributed nodes include: A request execution module, configured to execute the pending request if the response result is that the requested number of tokens is obtained; A request processing operation determination module, configured to determine a processing operation for the pending request according to a service level corresponding to the pending request if the response result is that the requested number of tokens is not obtained within a set time; The request processing operation determination module is specifically used to: In the case where it is determined that the service level corresponding to the pending request is a high level, determining whether the number of RPC requests exceeds a preset number; If not, return to the step of sending a remote procedure call (RPC) request to the current limiting server based on the pending request.
Citation Information
Patent Citations
Traffic management method and device for distributed system, and computing device
CN109617831A
Service processing method based on cluster server, platform, device and storage medium
CN109672627A
Service request processing method and device, computer equipment and storage medium
CN110149352A