Distributed current limiting method, device, equipment, storage medium and system

文档序号:1941458 发布日期:2021-12-07 浏览:5次 中文

阅读说明:本技术 分布式限流方法、装置、设备、存储介质和系统 (Distributed current limiting method, device, equipment, storage medium and system ) 是由 丰泽 王晓成 于 2020-06-28 设计创作,主要内容包括:本发明实施例公开了一种分布式限流方法、装置、设备、存储介质和系统。该方法包括:获取待处理请求,并依据所述待处理请求,向限流服务端发送远程过程调用RPC请求,以使所述限流服务端依据所述RPC请求通过调用令牌获取服务来获取令牌桶算法模块产生的令牌;依据所述限流服务端对所述RPC请求的响应结果,确定是否执行所述待处理请求。通过上述技术方案,更加便捷且有效地实现分布式系统限流。(The embodiment of the invention discloses a distributed current limiting method, a distributed current limiting device, distributed current limiting equipment, a distributed current limiting storage medium and a distributed current limiting system. The method comprises the following steps: the method comprises the steps that a request to be processed is obtained, and a Remote Procedure Call (RPC) request is sent to a current limiting server according to the request to be processed, so that the current limiting server obtains a token generated by a token bucket algorithm module by calling a token obtaining service according to the RPC request; and determining whether to execute the request to be processed or not according to a response result of the current limiting server to the RPC request. Through the technical scheme, the distributed system current limiting is realized more conveniently and effectively.)

1. A distributed current limiting method is applied to distributed nodes and comprises the following steps:

the method comprises the steps that a request to be processed is obtained, and a Remote Procedure Call (RPC) request is sent to a current limiting server according to the request to be processed, so that the current limiting server obtains a token generated by a token bucket algorithm module by calling a token obtaining service according to the RPC request;

and determining whether to execute the request to be processed or not according to a response result of the current limiting server to the RPC request.

2. The method of claim 1, wherein sending a Remote Procedure Call (RPC) request to a current limit server according to the pending request comprises:

determining the number of request tokens according to the request information of the request to be processed;

and sending the RPC request to the current limiting server according to the number of the request tokens.

3. The method of claim 2, wherein determining the number of request tokens based on the request information of the pending request comprises:

and determining the number of the request tokens according to the target request type of the request to be processed and the corresponding relation between the request type and the number of the tokens.

4. The method of claim 1, wherein determining whether to execute the pending request according to a response result of the current limit server to the RPC request comprises:

if the response result is the token of the obtained request token number, executing the request to be processed;

and if the response result is that the tokens of the request token number are not acquired within the set time, determining the processing operation of the request to be processed according to the service level corresponding to the request to be processed.

5. The method of claim 4, wherein determining the processing operation for the pending request according to the service level corresponding to the pending request comprises:

determining whether the RPC request times exceed a preset number of times under the condition that the service level corresponding to the request to be processed is determined to be a high level;

and if not, returning to the step of executing the Remote Procedure Call (RPC) request sent to the current limiting server according to the request to be processed.

6. The method of claim 4, wherein determining the processing operation for the pending request according to the service level corresponding to the pending request comprises:

and caching or discarding the request to be processed under the condition that the service level corresponding to the request to be processed is a low level.

7. The method of claim 4, wherein the set time is a request timeout time for a Remote Procedure Call (RPC) request or a set latency in the RPC request.

8. A distributed current limiting method is applied to a current limiting server and comprises the following steps:

receiving a Remote Procedure Call (RPC) request sent by a distributed node, and acquiring a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request;

and sending a token acquisition result to the distributed nodes as a response result of the RPC request so that the distributed nodes can determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result.

9. A distributed current limiting apparatus, configured at a distributed node, comprising:

the Remote Procedure Call (RPC) request sending module is used for acquiring a request to be processed and sending a Remote Procedure Call (RPC) request to the current limiting server according to the request to be processed so that the current limiting server can acquire a token generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request;

and the request processing module is used for determining whether to execute the request to be processed according to a response result of the current limiting server to the RPC request.

10. A distributed current limiting device, configured at a current limiting server, includes:

the token acquisition module is used for receiving a Remote Procedure Call (RPC) request sent by the distributed node and acquiring a token generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request;

and the response result sending module is used for sending a token obtaining result to the distributed nodes as a response result of the RPC request so that the distributed nodes can determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result.

11. An electronic device, characterized in that the electronic device comprises:

one or more processors;

a storage device for storing one or more programs,

when executed by the one or more processors, cause the one or more processors to implement the distributed current limiting method applied to the distributed node according to any one of claims 1 to 7, or the distributed current limiting method applied to the current limiting service end according to claim 8.

12. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements a distributed current limiting method applied to distributed nodes according to any one of claims 1 to 7, or a distributed current limiting method applied to a current limiting service terminal according to claim 8.

13. A distributed current limiting system, the system comprising: at least two distributed nodes and a current limiting server, wherein,

the distributed node is used for acquiring a request to be processed, sending a Remote Procedure Call (RPC) request to the current limiting server according to the request to be processed, and determining whether to execute the request to be processed according to a response result of the current limiting server to the RPC request;

the current limiting server is independent of the distributed nodes, is in remote communication connection with the distributed nodes, and is used for obtaining tokens generated by the token bucket algorithm module by calling a token obtaining service according to the RPC request and sending a token obtaining result to the distributed nodes as a response result to the RPC request.

Technical Field

Embodiments of the present invention relate to computer technologies, and in particular, to a distributed current limiting method, apparatus, device, storage medium, and system.

Background

Since the Application Programming Interface (API) cannot control the behavior of the calling party, when the instantaneous request amount is increased, the API occupies too many server resources, so that the response speed of other requests is reduced or the requests are overtime, and even more, the server may be down. Therefore, it is necessary to protect the server by limiting the request of the application service, i.e., limiting the flow (Rate limiting).

Online services are mostly distributed systems for various reasons. The current limiting method for the distributed system is as follows: the method combines the Lua script and the Redis cache service to realize the current limiting, for example, the method of writing the Lua script to run is adopted, and the operation and query process of the request times is put at the Redis end, so that the current limiting judgment can be completed by carrying out one request on the Redis.

In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art: the current limiting scheme of Redis cache service and lua script needs to deploy Redis cache service and grasp the lua script, and the scheme is complex in implementation process and difficult to implement.

Disclosure of Invention

Embodiments of the present invention provide a distributed current limiting method, apparatus, device, storage medium, and system, so as to implement distributed system current limiting more conveniently and effectively.

In a first aspect, an embodiment of the present invention provides a distributed current limiting method, applied to a distributed node, including:

the method comprises the steps that a request to be processed is obtained, and a Remote Procedure Call (RPC) request is sent to a current limiting server according to the request to be processed, so that the current limiting server obtains a token generated by a token bucket algorithm module by calling a token obtaining service according to the RPC request;

and determining whether to execute the request to be processed or not according to a response result of the current limiting server to the RPC request.

In a second aspect, an embodiment of the present invention further provides a distributed current limiting method, applied to a current limiting server, including:

receiving a Remote Procedure Call (RPC) request sent by a distributed node, and acquiring a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request;

and sending a token acquisition result to the distributed nodes as a response result of the RPC request so that the distributed nodes can determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result.

In a third aspect, an embodiment of the present invention further provides a distributed current limiting device, configured at a distributed node, where the device includes:

the Remote Procedure Call (RPC) request sending module is used for acquiring a request to be processed and sending a Remote Procedure Call (RPC) request to the current limiting server according to the request to be processed so that the current limiting server can acquire a token generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request;

and the request processing module is used for determining whether to execute the request to be processed according to a response result of the current limiting server to the RPC request.

In a fourth aspect, an embodiment of the present invention further provides a distributed current limiting device, configured at a current limiting service end, where the device includes:

the token acquisition module is used for receiving a Remote Procedure Call (RPC) request sent by the distributed node and acquiring a token generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request;

and the response result sending module is used for sending a token obtaining result to the distributed nodes as a response result of the RPC request so that the distributed nodes can determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result.

In a fifth aspect, an embodiment of the present invention further provides an electronic device, where the electronic device 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 distributed nodes or the distributed current limiting method applied to the current limiting service end provided by any embodiment of the present invention.

In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the distributed current limiting method applied to a distributed node or the distributed current limiting method applied to a current limiting service end, provided in any embodiment of the present invention.

In a seventh aspect, an embodiment of the present invention further provides a distributed current limiting system, where the system includes: at least two distributed nodes and a current limiting server, wherein,

the distributed node is used for acquiring a request to be processed, sending a Remote Procedure Call (RPC) request to the current limiting server according to the request to be processed, and determining whether to execute the request to be processed according to a response result of the current limiting server to the RPC request;

the current limiting server is independent of the distributed nodes, is in remote communication connection with the distributed nodes, and is used for obtaining tokens generated by the token bucket algorithm module by calling a token obtaining service according to the RPC request and sending a token obtaining result to the distributed nodes as a response result to the RPC request.

The method comprises the steps that a request to be processed is obtained, and a Remote Procedure Call (RPC) request is sent to a current limiting server according to the request to be processed, so that the current limiting server obtains a token generated by a token bucket algorithm module by calling a token obtaining service according to the RPC request; and determining whether to execute the request to be processed or not according to the response result of the current-limiting server to the RPC request. The token bucket algorithm module only suitable for single machine current limiting is deployed to the independent current limiting server and then applied to the current limiting of the distributed system, 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, the deployment of Redis cache service is avoided, the current limiting scheme is not required to be implemented through self programming, and the high efficiency and convenience of the current limiting of the distributed system are improved.

Drawings

Fig. 1 is a flowchart of a distributed current limiting method applied to distributed nodes according to a first embodiment of the present invention;

fig. 2 is a flowchart of a distributed current limiting method applied to distributed nodes according to a second embodiment of the present invention;

fig. 3 is a flowchart of a distributed current limiting method applied to a current limiting server according to a third embodiment of the present invention;

fig. 4 is a schematic structural diagram of a distributed current limiting system according to a fourth embodiment of the present invention;

fig. 5 is a schematic diagram of an interaction process between a distributed node and a current-limiting server in a distributed current-limiting system according to a fourth embodiment of the present invention;

fig. 6 is a schematic structural diagram of a distributed current limiting apparatus configured at a distributed node according to a fifth embodiment of the present invention;

fig. 7 is a schematic structural diagram of a distributed current limiting apparatus configured at a current limiting server according to a sixth embodiment of the present invention;

fig. 8 is a schematic structural diagram of an electronic device in a seventh embodiment of the present invention.

Detailed Description

The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.

Example one

The distributed current limiting method applied to the distributed nodes provided by the embodiment is applicable to access current limiting of a distributed system. The method may be performed by a distributed current limiting device configured in a distributed node, where the device may be implemented by software and/or hardware, and the device may be integrated in an electronic device corresponding to a node in a distributed system, such as a desktop computer or a server. Referring to fig. 1, the distributed current limiting method applied to the distributed nodes in this embodiment specifically includes:

s110, a request to be processed is obtained, and a Remote Procedure Call (RPC) request is sent to the current limiting server according to the request to be processed, so that the current limiting server obtains a token generated by the token bucket algorithm module by calling a token obtaining service according to the RPC request.

The pending request refers to an external request which needs to be processed by the distributed node. The current limiting server is a server providing current limiting service and is arranged in a single machine. A Remote Procedure Call (RPC) request refers to a request to remotely Call a current limiting service. The current limiting service here refers to a service based on a token bucket algorithm, that is, a token obtaining service, and may be, for example, a current limiting service implemented by a class RateLimiter of a current limiting tool based on a token bucket algorithm provided by the Google open source toolkit Guava.

In the related art, access throttling is performed by using a token bucket algorithm, and particularly, a mature throttling tool class RateLimiter provided by the Google open source toolkit Guava is used. However, the ratelimit tool class is only suitable for single-machine current limiting, and cannot be adapted to a distributed environment. If the token bucket algorithm is applied to a distributed system, the token bucket algorithm needs to be implemented by the lua script, and a Redis cache service needs to be deployed. Based on this, the related art does not use the ratelimit tool class for distributed current limiting. However, the Redis cache service is complex and difficult to implement in combination with the distributed current limiting of the lua script, and in order to improve the implementation convenience of the distributed current limiting, in the embodiment of the invention, a current limiting tool class rateLimiter is used for the distributed current limiting. The method specifically comprises the following steps: and setting an independent server (namely a current limiting server), wherein the current limiting server realizes a token bucket algorithm by using a current limiting tool class RateLimiter, is used for producing and providing tokens, and provides token acquisition service outwards. Meanwhile, the distributed nodes register Remote Procedure Call (RPC) service so as to realize a remote call function with the current limiting server.

Based on the current limiting deployment of the distributed system, when a distributed node receives a request to be processed, a Remote Procedure Call (RPC) request is generated according to the request to be processed and a call rule (such as a call mode, required parameters and the like) of a token acquisition service in a current limiting service end. Then, the RPC request is sent to the current limit server. After receiving the RPC request, the current limiting server invokes the token obtaining service to obtain the requested token from the token bucket. And whether the token of the request can be acquired or not, the current limiting server side feeds back a response result to the RPC request to the distributed nodes.

Illustratively, sending a Remote Procedure Call (RPC) request to the current limit server according to the pending request comprises: determining the number of request tokens according to the request information of the request to be processed; and sending an RPC request to the current limiting server according to the number of the request tokens.

The request information refers to information related to the pending request, and may be, for example, request content, request type, requested packet size, and the like. The request token number is the number of tokens required to execute the pending request.

The token bucket flow limitation is to control the processing of a request by using tokens generated at a constant speed, and if the tokens are acquired, the request can be executed, and if the tokens are not acquired, the request is not executed. The pending requests may correspond to different services, the request contents may also be different, and the number of tokens required to execute the request may also be different. Based on this, after the to-be-processed request is acquired, the number of the request tokens needs to be determined according to the request information of the to-be-processed request, and then the RPC request is generated according to the number of the request tokens and is sent to the current limiting server. For example, the number of request tokens may be determined according to the packet size of the pending request and the amount of data corresponding to each token. The advantage that sets up like this lies in, avoids sending the request message of pending request to the current-limiting server side, can improve pending request's security, can reduce the data bulk of RPC request again, improves remote calling efficiency, and then improves distributed node's current-limiting efficiency.

Illustratively, determining the number of request tokens according to the request information of the pending request comprises: and determining the number of the request tokens according to the target request type of the request to be processed and the corresponding relation between the request type and the number of the tokens.

If the pending request is a call request with a third-party service, and the third-party service agrees the number of tokens required by requests of different request types, a corresponding relation between the request type and the number of tokens can be constructed. After the distributed node acquires the request to be processed, the token number corresponding to the request to be processed can be inquired from the corresponding relation according to the request type (namely the target request type) of the request to be processed and is used as the request token number. For example, a task generation request (e.g., a request for generating an order) corresponding to an item acquisition task (e.g., a shopping order) in an e-commerce platform, the calling service is an order placing service in a third-party service, the request type is an order generating type, and the number of tokens corresponding to the request of the order generating type is agreed to be 2, so that the number of the request tokens is 2; for another example, if an order query service in the third-party service is called, the request type is the order query type, and the agreed token number is 1, then the request token number is 1. The method has the advantages that when the request to be processed is an external service calling request type, the number of the request tokens is determined preferentially according to the service agreement of the third party, if the request tokens are determined without agreement according to the size of the data packet, the execution rate of important requests can be improved to a certain extent, the intelligence and rationalization of current limiting are further improved, and the distributed current limiting efficiency is further improved.

And S120, determining whether to execute the request to be processed or not according to the response result of the current limiting server to the RPC request.

After receiving the response result fed back by the current limiting server, the distributed node determines whether to execute the pending request according to whether the response result is the requested token.

Exemplarily, S120 includes: if the response result is the token of the obtained request token number, executing the request to be processed; and if the response result is that the tokens of the request token number are not acquired within the set time, determining the processing operation of the request to be processed according to the service level corresponding to the request to be processed.

The set time refers to a preset time period. Illustratively, the set time is a request timeout time for a Remote Procedure Call (RPC) request, or a set latency in an RPC request. The request timeout time refers to the timeout time for any request for a remote call, which is set when a node registers for a remote procedure call service. The set latency is a request parameter of the RPC request that is given when the node invokes the remote procedure call service. The method has the advantages that long-time blocking of remote procedure call can be avoided, call blocking duration of remote procedure call service can be flexibly determined, and flexibility of distributed current limiting is further improved. The service level refers to a level set in advance according to the service importance degree, and the more important the service is, the higher the service level is.

And if the response result received by the distributed node is the token of the request token number, executing the pending request. If the response result is that the token is not acquired and fed back due to the set time, the pending request cannot be executed. At this time, it is necessary to determine whether to continue sending RPC requests to the current limiting server to continue obtaining tokens requesting the number of tokens according to the service class corresponding to the request to be processed. The method has the advantages that whether the token is continuously acquired or not can be determined according to the service grade of the request to be processed, the flow limiting process of important services and non-important services is distinguished, the execution rate of the important services is further improved, and the flexibility of distributed flow limiting is further improved.

According to the technical scheme of the embodiment, the Remote Procedure Call (RPC) request is sent to the current-limiting server side by obtaining the request to be processed and according to the request to be processed, so that the current-limiting server side obtains the token generated by the token bucket algorithm module by calling the token obtaining service according to the RPC request; and determining whether to execute the request to be processed or not according to the response result of the current-limiting server to the RPC request. The token bucket algorithm module only suitable for single machine current limiting is deployed to the independent current limiting server and then applied to the current limiting of the distributed system, 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, the deployment of Redis cache service is avoided, the current limiting scheme is not required to be implemented through self programming, and the high efficiency and convenience of the current limiting of the distributed system are improved.

Example two

In this embodiment, based on the first embodiment, further optimization is performed on "determining the processing operation of the request to be processed according to the service level corresponding to the request to be processed". The same or corresponding terms as those in the above embodiments are not explained in detail herein.

Referring to fig. 2, the distributed current limiting method applied to the distributed nodes provided in this embodiment includes:

s210, obtaining the request to be processed, and determining the number of the request tokens according to the request information of the request to be processed.

S220, sending an RPC request to the current limiting server according to the number of the request tokens, so that the current limiting server acquires the tokens generated by the token bucket algorithm module by calling a token acquisition service according to the RPC request.

The token bucket algorithm module in the current-limiting service end is realized by adopting a current-limiting tool class RateLimiter based on a token bucket algorithm provided by a Google open source toolkit Guava, and two calling interfaces, namely double acquires (int permits) and tryAcquires (int permits, long timeout) are provided, wherein the permits represents the number of request tokens, and the timeout represents the set waiting time. The distributed node may call an interface function acquirel (int permissions) or tryAcquire (long timeout) as a function input parameter according to a service requirement (such as flexibility of time setting of remote call blocking), generate and send an RPC request to the current limiting service end.

And S203, if the response result is the token of the acquired request token number, executing the request to be processed.

And S204, if the response result is that the tokens of the request token number are not acquired within the set time, determining whether the RPC request number exceeds the preset number under the condition that the service level corresponding to the request to be processed is determined to be a high level.

And the RPC request times are the times of sending RPC requests to the current limiting server. The preset number refers to the preset allowable number of remote procedure calls.

If the response result of one RPC request is that the token is not acquired, the service level of the service to be processed corresponding to the RPC request needs to be determined according to the request to be processed. If the traffic class 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 RPC request frequency of the RPC request corresponding to the request to be processed exceeds a preset frequency. And then performs S250 or S260.

And S250, if the RPC request times do not exceed the preset times, returning to execute S220.

If the number of RPC requests does not exceed the preset number, it indicates that the token can be continuously obtained, and the step returns to S220.

And S260, if the RPC request times exceed the preset times, caching or discarding the request to be processed.

If the RPC request times exceed the preset times, the remote procedure calls that the current limiting service request times reach the upper limit, the RPC request cannot be sent, and the request to be processed is cached or discarded. If so, waiting for a period of time or continuing to request to acquire the token according to the traffic.

And S270, if the response result is that the tokens of the request token number are not acquired within the set time, caching or discarding the request to be processed under the condition that the service level corresponding to the request to be processed is a low level.

If the token is not acquired and the service level corresponding to the request to be processed is a low level, it is indicated that the request to be processed is not an important request, and in order to improve the service processing efficiency and the current limiting efficiency, the request to be processed can be directly cached or discarded without performing a repeated request process for acquiring the token.

According to the technical scheme of the embodiment, if the response result is that the tokens of the number of the request tokens are not acquired within the set time, the to-be-processed request is cached or discarded under the condition that the service level corresponding to the to-be-processed request is a low level. The processing operation of low-level requests to be processed is realized, the condition that resources are excessively occupied by unimportant requests to be processed is avoided, the request processing efficiency of distributed nodes is improved, and the distributed current limiting efficiency is further improved. If the response result is that the tokens requesting the number of tokens are not obtained within the set time, determining whether the RPC request number exceeds the preset number under the condition that the service level corresponding to the request to be processed is determined to be a high level; if not, returning to the step of executing the Remote Procedure Call (RPC) request sent to the current limiting server according to the request to be processed. The processing operation of high-level to-be-processed requests is realized, the execution of important to-be-processed requests is ensured as much as possible, and the high efficiency of request processing is further considered on the basis of improving the rationality of distributed current limiting.

EXAMPLE III

The distributed current limiting method applied to the current limiting server side provided by the embodiment can be applied to access current limiting of a distributed system. The method can be executed by a distributed current limiting device configured in a current limiting server, the device can be implemented by software and/or hardware, and the device can be integrated in electronic equipment corresponding to the current limiting server, such as a desktop computer or a server. The same or corresponding terms as those in the above embodiments are not explained in detail herein.

Referring to fig. 3, the distributed current limiting method applied to the current limiting server of the embodiment specifically includes:

s310, receiving a Remote Procedure Call (RPC) request sent by the distributed node, and obtaining the token generated by the token bucket algorithm module by calling a token obtaining service according to the RPC request.

The token bucket algorithm module in the current-limiting service end is implemented by using a current-limiting tool class ratelimit provided by the Google open source toolkit Guava and based on the token bucket algorithm, for example, by using ratelimit, which is ratelimit, create, com. The current limit value is an upper limit value in the token bucket, where tokens can be stored.

When receiving an RPC request sent by a distributed node, such as an RPC request generated by calling an interface function acquire (int permit), a current-limiting server analyzes the RPC request to obtain the number of request tokens. And then, the current-limiting service end is always blocked, and the token acquisition service is called to acquire the tokens generated by the token bucket algorithm module until the tokens requesting the token number are acquired. And if a sufficient number of tokens are acquired before the request timeout time is reached, returning the tokens of the request token number to the distributed node as a response result. If the blocking duration reaches the request timeout time of the remote procedure call but the token of the request token number is not obtained, the current limiting server side feeds back remote procedure call error information to the distributed node, and the error information is used as a response result of the RPC request and represents that the token of the request token number is not 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 may be as follows: < dubbo: consumer timeout ═ request timeout set according to service demand "> < dubbo: consumer >.

When receiving an RPC request sent by a distributed node, such as an RPC request generated by calling an interface function tryacknowledge (int permissions, long timeout), a current-limiting service end analyzes the RPC request to obtain the number of request tokens and set a waiting time. Then, the current limiting service terminal calls a token obtaining service to obtain the token generated by the token bucket algorithm module. And if the token of the request token number is acquired within the set waiting time, returning the token to the distributed node as a response result. If the set waiting time is up and the token of the request token number is not obtained yet, the current limiting server side feeds back remote procedure call error information to the distributed node, and the error information is used as a response result of the RPC request and represents that the token of the request token number is not obtained within the set time.

S320, sending the token acquisition result to the distributed nodes as a response result of the RPC request so that the distributed nodes can determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result.

According to the technical scheme of the embodiment, the Remote Procedure Call (RPC) request sent by the distributed node is received, and the token generated by the token bucket algorithm module is obtained by calling the token obtaining service according to the RPC request; and sending the token acquisition result to the distributed nodes as a response result of the RPC request so that the distributed nodes can determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result. The token bucket algorithm module only suitable for single machine current limiting is deployed to the independent current limiting server and then applied to the current limiting of the distributed system, 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, the deployment of Redis cache service is avoided, the current limiting scheme is not required to be implemented through self programming, and the high efficiency and convenience of the current limiting of the distributed system are improved.

Example four

This embodiment provides a distributed current limiting system, refer to fig. 4, and this system specifically includes: at least two distributed nodes 420 and a current limit server 410, wherein,

the distributed node 420 is used for acquiring the request to be processed, sending a Remote Procedure Call (RPC) request to the current limiting server according to the request to be processed, and determining whether to execute the request to be processed according to a response result of the current limiting server to the RPC request;

and the current limiting server 410 is independent of the distributed nodes, is in remote communication connection with the distributed nodes, and is used for acquiring the tokens generated by the token bucket algorithm module by calling the token acquisition service according to the RPC request and sending the token acquisition result to the distributed nodes as a response result to the RPC request.

Referring to fig. 5, taking the interaction between one distributed node 420 and the current limiting server 410 as an example, the current limiting process is: after obtaining the pending request, the distributed node 420 generates an RPC request according to the pending request and sends the RPC request to the current limiting server 410. The current limiting server 410 invokes a token acquisition service therein to acquire tokens generated by the token bucket algorithm module, execute the acquire token logic, and return token acquisition results to the distributed nodes 420 as response results. The distributed node 420 determines whether to execute the pending request according to whether the response result includes the token of the request token number.

Optionally, distributed node 420 includes:

the request token number determining module is used for determining the number of the request tokens according to the request information of the request to be processed;

and the RPC request sending module is used for sending the RPC request to the current limiting server according to the number of the request tokens.

Further, the request token number determination module is specifically configured to:

and determining the number of the request tokens according to the target request type of the request to be processed and the corresponding relation between the request type and the number of the tokens.

Optionally, distributed node 420 includes:

the request execution module is used for executing the request to be processed if the response result is the token of the obtained request token number;

and the request processing operation determining module is used for determining 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 tokens of the request token number are not acquired within the set time.

The set time is the request timeout time of the Remote Procedure Call (RPC) request or the set waiting time in the RPC request.

Further, the request processing operation determining module is specifically configured to:

under the condition that the service level corresponding to the request to be processed is determined to be a high level, determining whether the RPC request frequency exceeds a preset frequency;

if not, returning to the step of executing the Remote Procedure Call (RPC) request sent to the current limiting server according to the request to be processed.

Optionally, the request processing operation determining module is specifically configured to:

and caching or discarding the request to be processed under the condition that the service level corresponding to the request to be processed is a low level.

By the distributed current limiting system, the token bucket algorithm module only suitable for single machine current limiting is deployed to the independent current limiting server and further applied to current limiting of the distributed system, 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, deployment of Redis cache service is avoided, a current limiting scheme is not required to be programmed automatically, and efficiency and convenience of current limiting of the distributed system are improved.

EXAMPLE five

The present embodiment provides a distributed current limiting apparatus configured at a distributed node, and referring to fig. 6, the apparatus specifically includes:

a Remote Procedure Call (RPC) request sending module 610, configured to obtain a request to be processed, and send a Remote Procedure Call (RPC) request to the current limiting server according to the request to be processed, so that the current limiting server obtains a token generated by the token bucket algorithm module by calling a token obtaining service according to the RPC request;

and the request processing module 620 is configured to determine whether to execute the to-be-processed request according to a response result of the current-limited server to the RPC request.

Optionally, the remote procedure call RPC request sending module 610 includes:

the request token number determining submodule is used for determining the number of the request tokens according to the request information of the request to be processed;

and the RPC request sending submodule is used for sending the RPC request to the current limiting server according to the number of the request tokens.

Further, the request token number determination submodule is specifically configured to:

and determining the number of the request tokens according to the target request type of the request to be processed and the corresponding relation between the request type and the number of the tokens.

Optionally, the request processing module 620 includes:

the request execution submodule is used for executing the request to be processed if the response result is the token of the acquired request token number;

and the request processing operation determining submodule is used for determining 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 tokens of the request token number are not acquired within the set time.

The set time is the request timeout time of the Remote Procedure Call (RPC) request or the set waiting time in the RPC request.

Further, the request processing operation determining submodule is specifically configured to:

under the condition that the service level corresponding to the request to be processed is determined to be a high level, determining whether the RPC request frequency exceeds a preset frequency;

if not, returning to the step of executing the Remote Procedure Call (RPC) request sent to the current limiting server according to the request to be processed.

Optionally, the request processing operation determining submodule is specifically configured to:

and caching or discarding the request to be processed under the condition that the service level corresponding to the request to be processed is a low level.

Through the distributed current limiting device configured at the distributed nodes, the token bucket algorithm module which can only be suitable for single-machine current limiting is deployed to the independent current limiting server and is further applied to current limiting of the distributed system, 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, deployment of Redis cache service is avoided, a current limiting scheme is not required to be programmed automatically, and efficiency and convenience of current limiting of the distributed system are improved.

The distributed current limiting device configured at the distributed nodes provided by the embodiment of the invention can execute the distributed current limiting method applied to the distributed nodes provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.

EXAMPLE six

Referring to fig. 7, the present embodiment provides a distributed current limiting apparatus configured at a current limiting service end, and the apparatus specifically includes:

the token obtaining module 710 is configured to receive a Remote Procedure Call (RPC) request sent by a distributed node, and obtain a token generated by the token bucket algorithm module by calling a token obtaining service according to the RPC request;

and a response result sending module 720, configured to send the token obtaining result to the distributed nodes as a response result to the RPC request, so that the distributed nodes determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result.

Optionally, the token obtaining module 710 is specifically configured to:

and obtaining the tokens generated by the token bucket algorithm module by calling the token obtaining service within a set time according to the number of the request tokens in the RPC request.

The set time is the request timeout time of the Remote Procedure Call (RPC) request or the set waiting time in the RPC request.

Optionally, the token obtaining module 710 is further specifically configured to:

if the token requesting the token number is acquired within the set time, taking the token as a token acquisition result;

and if the token of the request token number is not acquired within the set time, taking the remote procedure call error information as a token acquisition result.

Through the distributed current limiting device configured at the current limiting server side in the sixth embodiment of the invention, the token bucket algorithm module only suitable for single machine current limiting is deployed to the independent current limiting server, and is further applied to 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 RPC service to obtain the token for current limiting, deployment of Redis cache service is avoided, a current limiting scheme is not required to be programmed by itself, and the efficiency and convenience of current limiting of the distributed system are improved.

The distributed current limiting device configured at the current limiting server provided by the embodiment of the invention can execute the distributed current limiting method applied to the current limiting server provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.

It should be noted that, in the embodiment of the distributed current limiting apparatus/system, the units and modules included in the embodiment are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.

EXAMPLE seven

Referring to fig. 8, the present embodiment provides an electronic device 800, which includes: one or more processors 820; the storage 810 is configured to store one or more programs, and 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 the distributed nodes according to the embodiment of the present invention, including:

the method comprises the steps that a request to be processed is obtained, and a Remote Procedure Call (RPC) request is sent to a current limiting server according to the request to be processed, so that the current limiting server obtains a token generated by a token bucket algorithm module by calling a token obtaining service according to the RPC request;

and determining whether to execute the request to be processed or not according to the response result of the current-limiting server to the RPC request.

Of course, those skilled in the art will understand that the processor 820 may also implement the solution of the distributed current limiting method applied to the distributed nodes according to any embodiment of the present invention.

The electronic device 800 shown in fig. 8 is only an example and should not bring any limitations to the function and scope of use of the embodiments of the present invention.

As shown in fig. 8, 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 that connects the various system components (including the storage device 810 and the processors 820).

Bus 850 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such 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.

Electronic device 800 typically includes a variety of computer system readable media. Such media may be any available media that is accessible by electronic device 800 and includes both volatile and nonvolatile media, removable and non-removable media.

Storage 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/nonvolatile computer system storage media. By way of example only, storage system 813 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 8, often referred to as a "hard drive"). Although not shown in FIG. 8, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 850 by one or more data media interfaces. Storage 810 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.

A program/utility 814 having a set (at least one) of program modules 815 may be stored, for example, in storage 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 examples or some combination thereof may include an implementation of a network environment. The program modules 815 generally perform the functions and/or methodologies of any of the embodiments described herein.

The electronic device 800 may also communicate with one or more external devices 860 (e.g., keyboard, pointing device, display 870, etc.), with one or more devices that enable a user to interact with the electronic device 800, and/or with any devices (e.g., network card, modem, etc.) that enable the electronic device 800 to communicate with one or more other computing devices. Such communication may be through an input/output interface (I/O interface) 830. Also, the electronic device 800 may 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) via the network adapter 840. As shown in fig. 8, the network adapter 840 communicates with the other modules of the electronic device 800 via the bus 850. It should be appreciated that although not shown, other hardware and/or software modules may 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, among others.

The processor 820 executes a program stored in the storage device 810 to perform various functional applications and data processing, for example, implement the distributed current limiting method applied to the distributed nodes according to the embodiment of the present invention.

An embodiment of the present invention further provides another electronic device, which includes: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by one or more processors, the one or more processors implement the distributed current limiting method applied to the current limiting service end, which is provided by the embodiment of the invention, and the method comprises the following steps:

receiving a Remote Procedure Call (RPC) request sent by a distributed node, and acquiring a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request;

and sending the token acquisition result to the distributed nodes as a response result of the RPC request so that the distributed nodes can determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result.

Of course, those skilled in the art can understand that the processor may also implement the technical solution of the distributed current limiting method applied to the current limiting server according to any embodiment of the present invention. The hardware structure and the functions of the electronic device can be explained with reference to the seventh embodiment.

Example eight

The present embodiments provide a storage medium containing computer-executable instructions which, when executed by a computer processor, are operable to perform a method of distributed throttling for application to distributed nodes, the method comprising:

the method comprises the steps that a request to be processed is obtained, and a Remote Procedure Call (RPC) request is sent to a current limiting server according to the request to be processed, so that the current limiting server obtains a token generated by a token bucket algorithm module by calling a token obtaining service according to the RPC request;

and determining whether to execute the request to be processed or not according to the response result of the current-limiting server to the RPC request.

Of course, the storage medium containing the computer-executable instructions provided by the embodiments of the present invention is not limited to the above method operations, and may also perform related operations in the distributed current limiting method applied to the distributed nodes provided by any embodiment of the present invention.

Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.

A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.

Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, or the like, as well as conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).

An embodiment of the present invention further provides another computer-readable storage medium, where computer-executable instructions, when executed by a computer processor, are configured to perform a distributed current limiting method applied to a current limiting server, where the method includes:

receiving a Remote Procedure Call (RPC) request sent by a distributed node, and acquiring a token generated by a token bucket algorithm module by calling a token acquisition service according to the RPC request;

and sending the token acquisition result to the distributed nodes as a response result of the RPC request so that the distributed nodes can determine whether to execute the to-be-processed request corresponding to the RPC request according to the response result.

Of course, the storage medium containing the computer-executable instructions provided by the embodiments of the present invention is not limited to the above method operations, and may also perform related operations in the distributed current limiting method applied to the current limiting service end provided by any embodiment of the present invention. The description of the storage medium can be found in the explanation of embodiment eight.

It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

19页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:资源访问方法、装置、电子设备及存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!