Upstream system current limiting method and device

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

阅读说明:本技术 上游系统限流方法和装置 (Upstream system current limiting method and device ) 是由 贺双喜 于 2020-11-20 设计创作,主要内容包括:本申请公开了一种上游系统限流方法和装置,包括:限流器实时监测当前是否发生预设的限额配置触发事件;所述限额配置触发事件包括:所述下游系统中已启动的下游服务器数量发生变化和任一预设上游系统中已启动的上游服务器数量发生变化;当发生所述限额配置触发事件,且当前至少一台上游服务器已启动时,所述限流器根据当前下游系统支持的最大请求处理能力,为当前已启动的相应上游服务器,确定最大请求发送限额并通知上游服务器;所述上游服务器根据所述通知,在本地创建线程池;所述线程池支持的最大线程数为所述最大请求发送限额;当前已启动的每台上游服务器,利用本地最新创建的线程池,请求所述下游系统。采用本发明,可以提高请求成功率。(The application discloses a method and a device for limiting the current of an upstream system, which comprise the following steps: the current limiter monitors whether a preset quota configuration trigger event occurs at present in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes; when the quota configuration trigger event occurs and at least one upstream server is started currently, the current limiter determines a maximum request sending quota for the corresponding upstream server which is started currently according to the maximum request processing capacity supported by the current downstream system and informs the upstream server; the upstream server establishes a thread pool locally according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota; and each upstream server which is started currently requests the downstream system by using the thread pool which is created locally and newly. By adopting the invention, the request success rate can be improved.)

1. An upstream system throttling method, comprising:

the current limiter monitors whether a preset quota configuration trigger event occurs at present in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

when the quota configuration trigger event occurs and at least one upstream server is started currently, the current limiter determines a maximum request sending quota for the corresponding upstream server which is started currently according to the maximum request processing capacity supported by the current downstream system and informs the upstream server; the upstream server establishes a thread pool locally according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification;

and each upstream server which is started currently requests the downstream system by using the thread pool which is created locally and newly.

2. The method of claim 1, wherein the quota configuration triggering event further comprises: the ratio of the transmission quota of the upstream system changes.

3. The method of claim 2, wherein determining the maximum request sending quota for the currently activated corresponding upstream server when the number of activated downstream servers in the downstream system changes and at least one upstream server is activated comprises:

accumulating the maximum request processing quota supported by all the currently started downstream servers to obtain the maximum request processing quota S of the current downstream systemmax

For each of the upstream systems, the SmaxMultiplying the ratio of the maximum request sending quota of the upstream system by the ratio of the maximum request sending quota of the upstream system; if the started upstream servers exist in the upstream system, determining each started upstream server in the upstream system according to the maximum request sending quota of the upstream system and the number of the started upstream servers in the upstream systemThe maximum request send quota for the game server.

4. The method of claim 2, wherein determining the maximum request sending quota for the currently activated corresponding upstream server when the number of activated upstream servers in any of the upstream systems changes and at least one upstream server is activated comprises:

for each upstream system, if the number of the upstream servers started in the upstream system currently changes, determining the maximum request sending quota of each upstream server started in the upstream system currently according to the maximum request sending quota of the upstream system currently and the number of the upstream servers started in the upstream system currently; the maximum request sending quota of the current upstream system is the product of the ratio of the sending quota of the current upstream system and the accumulated value of the maximum request processing quotas of all the currently started downstream servers.

5. The method of claim 2, wherein determining the maximum requested transmission quota for the currently activated corresponding upstream server when the transmission quota ratio of the upstream system changes and the at least one upstream server is currently activated comprises:

for each upstream system with the changed sending quota ratio, multiplying the current sending quota ratio of the upstream system by the maximum request processing quota of the current downstream system to obtain the maximum request sending quota of the upstream system; and if the started upstream server exists in the upstream system, determining the maximum request sending quota of each upstream server started in the upstream system according to the maximum request sending quota of the upstream system and the number of the upstream servers started in the upstream system.

6. The method of any of claims 3 to 5, wherein determining the maximum request sending quota for each upstream server currently started in the upstream system comprises:

will be the current upstream system GiMaximum request sending quota and upstream system GiDividing the number of the currently started upstream servers;

generating an upstream system G according to the division resultiThe maximum request sending quota of each upstream server that has been started.

7. The method of claim 6, wherein an upstream system G is determined based on the result of the divisioniThe maximum request sending quota for each upstream server that has been started comprises:

if d is 0, the upstream system G is startediDetermining the maximum request sending quota of each upstream server which is started currently as the result of the division; d is the remainder of the division;

if d ≠ 0, then for the upstream system GiThe currently started upstream server determines the maximum request sending quota of the first d started upstream servers as a result of rounding up the division result, and determines the maximum request sending quota of other upstream servers except the first d started upstream servers as a result of rounding down the division result.

8. The method of claim 2, further comprising:

when the sending quota ratio of more than one upstream system needs to be increased, the current limiter correspondingly reduces the sending quota ratios of other upstream systems while performing the increase; wherein the reduced transmission limit ratio total is the same as the increased transmission limit ratio total.

9. The method of claim 1, further comprising:

establishing a long connection with the flow restrictor when a downstream server of the downstream system is started;

establishing a long connection with the flow restrictor when an upstream server of the upstream system is started;

and the current limiter acquires the real-time running state of the corresponding downstream server or the upstream server according to the communication state of the long connection.

10. The method of claim 1, further comprising:

when the number of started downstream servers in the downstream system decreases to zero, the current limiter notifies all the upstream servers that have been currently started to prohibit requesting the downstream system.

11. The method of claim 2, further comprising:

when the downstream server in the downstream system is started, if the started upstream server does not exist currently, the current limiter accumulates the maximum request processing limits respectively supported by all the currently started downstream servers to obtain the maximum request processing limit S of the current downstream systemmax

For each of the upstream systems, the flow restrictor passes the SmaxMultiplying the ratio of the maximum request sending quota of the upstream system by the ratio of the maximum request sending quota of the upstream system;

when the sending quota ratio of the upstream system changes, if no started upstream server exists currently, for each upstream system, the current flow restrictor multiplies the maximum request processing quota of the current downstream system by the sending quota ratio of the current upstream system to obtain the maximum request sending quota of the current upstream system.

12. An upstream system flow-limiting device disposed in a flow restrictor, comprising:

the event monitoring module is used for monitoring whether a preset quota configuration trigger event occurs at present or not in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

the system comprises a flow limiting control module, a flow control module and a flow control module, wherein the flow limiting control module is used for determining a maximum request sending limit for a corresponding upstream server which is started currently according to the maximum request processing capacity supported by a current downstream system when monitoring that a preset limit configuration triggering event occurs currently and at least one upstream server is started currently, and notifying the upstream server so as to trigger the upstream server to create or recreate a thread pool for requesting the downstream system locally for the first time according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

13. An electronic device comprising a processor, a memory, and a computer program stored on the memory and executable on the processor, wherein the processor when executing the program performs the steps of:

monitoring whether a preset quota configuration trigger event occurs at present or not in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

when the limit configuration triggering event is monitored to occur and at least one current upstream server is started, configuring a maximum request sending limit for the corresponding currently started upstream server according to the maximum request processing capacity supported by the current downstream system so as to trigger the upstream server to locally and firstly create or recreate a thread pool for requesting the downstream system according to the configuration; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

14. A computer readable storage medium having computer readable instructions stored therein which, when executed by a processor, perform the steps of:

monitoring whether a preset quota configuration trigger event occurs at present or not in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

when the limit configuration triggering event is monitored to occur and at least one upstream server is started currently, determining a maximum request sending limit for the corresponding upstream server which is started currently according to the maximum request processing capacity supported by the current downstream system, and notifying the upstream server so as to trigger the upstream server to locally create or recreate a thread pool for requesting the downstream system for the first time according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

Technical Field

The invention relates to the technical field of computers, in particular to a method and a device for limiting current of an upstream system.

Background

The current limiting mechanism is a mechanism for limiting the request quantity flowing into the system so as to ensure that the request quantity entering the system is controllable at any time, namely the request quantity cannot exceed a maximum flow value preset by the system, and if the request quantity exceeds the maximum flow value, the request quantity needs to be queued for waiting or directly rejected, so that the problems that the high concurrent flow completely floods the system, the processing capacity of the system is exceeded, and the machine breakdown and the service unavailability of the system occur.

Currently, the current throttling schemes mainly include a counter method, a leaky bucket method, and a token bucket method.

In the counter method, the number of requests in one second is limited, and in each second, when the accumulated number of requests reaches a limit, the subsequent requests are rejected.

In the leaky bucket method, flow is limited by the leaky bucket algorithm, processing requests every 10ms, regardless of how unstable the service call is. Because the speed of processing is fixed, the speed of incoming requests is unknown, many requests may come in suddenly, have no time to process and are placed in the bucket first, and are discarded directly when the bucket is full.

In the token bucket scheme, a bucket is used for storing a fixed number of tokens, the tokens are placed into the bucket at a certain speed, each request must first obtain the tokens, and only when the tokens are taken, the request has an opportunity to continue execution, otherwise, the request waits for available tokens. The act of placing the token is ongoing and if the token comes online, the token is discarded. There are a large number of tokens available in the initial state bucket, and incoming requests can now be directed to token execution. If there are no tokens in the bucket, it waits, which is equivalent to performing at a certain rate.

In the process of implementing the present invention, the inventor finds that the above-mentioned existing current limiting scheme is easy to cause request failure, specifically for the following reasons:

the current limiting scheme is realized by adopting a mode of limiting the current of a downstream system. The downstream system is the target system of the request, and the upstream system is the initiator of the request. For example, if the a system requests to call a certain function of the B system, the a system is an upstream system and the B system is a downstream system. The current limiting scheme only controls the processing speed of the downstream system to the request and cannot control the request initiating amount of the upstream system due to the fact that the current limiting scheme limits the current of the downstream system, so that the request received by the downstream system is discarded or waited when the processing capacity of the request is exceeded, the bandwidth of a service end is full when the number of requests initiated by the whole downstream system is large, and a large number of requests are lost due to timeout, so that the upstream system cannot request the downstream system.

In addition, because the current limiting scheme is to implement current limiting on the downstream system, so that only the requests of all the upstream systems can be subjected to current limiting processing as a whole, and different upstream systems cannot be distinguished to perform current limiting respectively, so that if the bandwidth of a service end is full due to a large request amount of a certain upstream system, other upstream systems cannot request the downstream system, and thus, the current limiting is not smooth.

Disclosure of Invention

In view of the above, the present invention provides a method and an apparatus for limiting a current in an upstream system, which can improve a success rate of a request from the upstream system.

In order to achieve the above purpose, the embodiment of the present invention provides a technical solution:

an upstream system throttling method comprising:

the current limiter monitors whether a preset quota configuration trigger event occurs at present in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

when the quota configuration trigger event occurs and at least one upstream server is started currently, the current limiter determines a maximum request sending quota for the corresponding upstream server which is started currently according to the maximum request processing capacity supported by the current downstream system and informs the upstream server; the upstream server establishes a thread pool locally according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification;

and each upstream server which is started currently requests the downstream system by using the thread pool which is created locally and newly.

Preferably, the quota configuration triggering event further comprises: the ratio of the transmission quota of the upstream system changes.

Preferably, when the number of activated downstream servers in the downstream system changes and at least one upstream server is activated currently, the determining the maximum request sending quota for the corresponding upstream server that is activated currently comprises:

accumulating the maximum request processing quota supported by all the currently started downstream servers to obtain the maximum request processing quota S of the current downstream systemmax

For each of the upstream systems, the SmaxMultiplying the ratio of the maximum request sending quota of the upstream system by the ratio of the maximum request sending quota of the upstream system; and if the started upstream server exists in the upstream system, determining the maximum request sending quota of each upstream server started in the upstream system according to the maximum request sending quota of the upstream system and the number of the upstream servers started in the upstream system.

Preferably, when the number of the started upstream servers in any upstream system changes and at least one upstream server is started currently, the determining the maximum request sending quota for the corresponding upstream server which is started currently comprises:

for each upstream system, if the number of the upstream servers started in the upstream system currently changes, determining the maximum request sending quota of each upstream server started in the upstream system currently according to the maximum request sending quota of the upstream system currently and the number of the upstream servers started in the upstream system currently; the maximum request sending quota of the current upstream system is the product of the ratio of the sending quota of the current upstream system and the accumulated value of the maximum request processing quotas of all the currently started downstream servers.

Preferably, when the ratio of the sending quota of the upstream system changes and at least one upstream server is started currently, the determining the maximum request sending quota for the corresponding upstream server which is started currently comprises:

for each upstream system with the changed sending quota ratio, multiplying the current sending quota ratio of the upstream system by the maximum request processing quota of the current downstream system to obtain the maximum request sending quota of the upstream system; and if the started upstream server exists in the upstream system, determining the maximum request sending quota of each upstream server started in the upstream system according to the maximum request sending quota of the upstream system and the number of the upstream servers started in the upstream system.

Preferably, the determining the maximum request sending quota for each upstream server that has been currently started in the upstream system comprises:

will be the current upstream system GiMaximum request sending quota and upstream system GiDividing the number of the currently started upstream servers;

generating an upstream system G according to the division resultiThe maximum request sending quota of each upstream server that has been started.

Preferably, the upstream system G is determined based on the result of said divisioniThe maximum request sending quota for each upstream server that has been started comprises:

if d is 0, the upstream system G is startediDetermining the maximum request sending quota of each upstream server which is started currently as the result of the division; d is the remainder of the division;

if d ≠ 0, then for the upstream system GiDetermining the maximum request sending quota of the first d started upstream servers as the result of rounding up the division result, and dividing the division resultThe maximum request sending quota of other upstream servers except the d started upstream servers is determined as a result of rounding down the division result.

Preferably, the method further comprises:

when the sending quota ratio of more than one upstream system needs to be increased, the current limiter correspondingly reduces the sending quota ratios of other upstream systems while performing the increase; wherein the reduced transmission limit ratio total is the same as the increased transmission limit ratio total.

Preferably, the method further comprises:

establishing a long connection with the flow restrictor when a downstream server of the downstream system is started;

establishing a long connection with the flow restrictor when an upstream server of the upstream system is started;

and the current limiter acquires the real-time running state of the corresponding downstream server or the upstream server according to the communication state of the long connection.

Preferably, the method further comprises:

when the number of started downstream servers in the downstream system decreases to zero, the current limiter notifies all the upstream servers that have been currently started to prohibit requesting the downstream system.

Preferably, the method further comprises:

when the downstream server in the downstream system is started, if the started upstream server does not exist currently, the current limiter accumulates the maximum request processing limits respectively supported by all the currently started downstream servers to obtain the maximum request processing limit S of the current downstream systemmax

For each of the upstream systems, the flow restrictor passes the SmaxMultiplying the ratio of the maximum request sending quota of the upstream system by the ratio of the maximum request sending quota of the upstream system;

when the sending quota ratio of the upstream system changes, if no started upstream server exists currently, for each upstream system, the current flow restrictor multiplies the maximum request processing quota of the current downstream system by the sending quota ratio of the current upstream system to obtain the maximum request sending quota of the current upstream system.

The embodiment of the invention also discloses a current limiting device of an upstream system, which is arranged in the current limiter and comprises:

the event monitoring module is used for monitoring whether a preset quota configuration trigger event occurs at present or not in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

the system comprises a flow limiting control module, a flow control module and a flow control module, wherein the flow limiting control module is used for determining a maximum request sending limit for a corresponding upstream server which is started currently according to the maximum request processing capacity supported by a current downstream system when monitoring that a preset limit configuration triggering event occurs currently and at least one upstream server is started currently, and notifying the upstream server so as to trigger the upstream server to create or recreate a thread pool for requesting the downstream system locally for the first time according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

The embodiment of the invention also discloses an electronic device, which comprises a processor, a memory and a computer program which is stored on the memory and can be run on the processor, wherein the processor executes the program to realize the following steps:

monitoring whether a preset quota configuration trigger event occurs at present or not in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

when the limit configuration triggering event is monitored to occur and at least one current upstream server is started, configuring a maximum request sending limit for the corresponding currently started upstream server according to the maximum request processing capacity supported by the current downstream system so as to trigger the upstream server to locally and firstly create or recreate a thread pool for requesting the downstream system according to the configuration; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

The embodiment of the invention also discloses a computer readable storage medium, wherein computer readable instructions are stored, and when the computer readable instructions are executed by a processor, the following steps are realized:

monitoring whether a preset quota configuration trigger event occurs at present or not in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

when the limit configuration triggering event is monitored to occur and at least one upstream server is started currently, determining a maximum request sending limit for the corresponding upstream server which is started currently according to the maximum request processing capacity supported by the current downstream system, and notifying the upstream server so as to trigger the upstream server to locally create or recreate a thread pool for requesting the downstream system for the first time according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

It can be seen from the above technical solutions that the upstream system current limiting method and apparatus provided by the present invention monitor whether a preset quota configuration trigger event occurs in real time, and when an event occurs, according to the maximum request processing capability supported by the current downstream system, set or update the maximum request sending quota of the currently started corresponding upstream server, trigger the upstream server to perform the first creation or re-creation of a thread pool for requesting the downstream system, thus implementing dynamic current limiting on the upstream system within the range of the maximum request processing capability supported by the downstream system, so that the request amount of the upstream system does not exceed the processing capability of the downstream system, thereby avoiding the occurrence of the situation that the bandwidth of the upstream system is occupied, further avoiding the failure of request due to the discarding of the upstream system due to overtime of the request, and thus effectively improving the request success rate, and the waste of upstream system bandwidth resources is avoided.

Drawings

FIG. 1 is a flow chart of an upstream system flow limiting method according to an embodiment of the present invention;

FIG. 2 is a diagram illustrating an implementation of a scene one according to an embodiment of the present invention;

FIG. 3 is a diagram illustrating an implementation of a scene two according to an embodiment of the present invention;

FIG. 4 is a diagram illustrating an implementation of a third scenario in accordance with an embodiment of the present invention;

FIG. 5 is a diagram illustrating an implementation of a scene four according to an embodiment of the present invention;

FIG. 6 is a diagram illustrating an implementation of a scene five according to an embodiment of the present invention;

FIG. 7 is a diagram illustrating a sixth implementation of the present invention;

fig. 8 is a block diagram of an upstream system current limiting device according to an embodiment of the present invention.

Detailed Description

In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in further detail with reference to the accompanying drawings and specific embodiments.

Fig. 1 is a schematic flow diagram of a method for limiting a current of an upstream system according to an embodiment of the present invention, and as shown in fig. 1, the method for limiting a current of an upstream system implemented according to the embodiment mainly includes:

step 101, the current limiter monitors whether a preset quota configuration trigger event occurs currently in real time.

In this step, the method is used for monitoring preset quota configuration trigger events in real time, so as to realize dynamic current limitation of an upstream system according to the events occurring in real time.

The quota configuration trigger event specifically includes: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes. Therefore, when the maximum request processing capacity supported by the downstream system changes or the request demand of the upstream system changes, the request quota of each server of the upstream system can be timely adjusted, so that the dynamic current limitation of the upstream system can be better realized.

In practical applications, in order to avoid occupying a large amount of request resources due to a large amount of requests of individual upstream systems and affecting the requests of other upstream systems to the downstream systems, in one embodiment, the current limiter may configure a sending quota ratio for each upstream system, and perform current limiting for each upstream system separately, so as to ensure fairness of current limiting. Accordingly, in this step, the current limiter may further monitor that the ratio of the sending quota of the upstream system changes, and when the event occurs, trigger the currently started upstream server to update the maximum request sending quota.

The quota configuration triggering event may further comprise: the ratio of the transmission quota of the upstream system changes.

In one embodiment, in order to improve the current limiting efficiency and save the resource overhead, the current limiter may acquire the real-time operating state of the downstream server or the upstream server by comparing the connection state of the upstream server and the downstream server, and may further monitor whether the quota configuration trigger event occurs in real time. Specifically, the following technical means can be further adopted to achieve the above effects:

establishing a long connection with the flow restrictor when a downstream server of the downstream system is started;

establishing a long connection with the flow restrictor when an upstream server of the upstream system is started;

and the current limiter acquires the real-time running state of the corresponding downstream server or the upstream server according to the communication state of the long connection.

In practical applications, the real-time operation status of the downstream server or the upstream server is not limited to be monitored by establishing a long connection, and other methods, such as a heartbeat method, may also be used for the monitoring.

102, when the quota configuration trigger event occurs and at least one upstream server is started currently, the current limiter determines a maximum request sending quota for the corresponding upstream server which is started currently according to the maximum request processing capacity supported by the current downstream system and informs the upstream server; the upstream server establishes a thread pool locally according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

In this step, when any quota configuration triggering event in step 101 occurs, and the current existing upstream server is started, the maximum request sending quota of the started upstream server needs to be adjusted in time to ensure that the current limit matches with the actual operating environment, so that not only can a better current limit effect be obtained, but also bandwidth resources and system processing resources can be fully utilized.

The following describes a specific implementation of determining the maximum request sending quota in this step, with respect to each occurrence of the above event:

in one embodiment, when the number of activated downstream servers in the downstream system changes and at least one upstream server is activated currently, the following method may be used to determine the maximum request sending quota for the corresponding upstream server that is activated currently:

accumulating the maximum request processing quota supported by all the currently started downstream servers to obtain the maximum request processing quota S of the current downstream systemmax

For each of the upstream systems, the SmaxMultiplying the ratio of the maximum request sending quota of the upstream system by the ratio of the maximum request sending quota of the upstream system; and if the started upstream server exists in the upstream system, determining the maximum request sending quota of each upstream server started in the upstream system according to the maximum request sending quota of the upstream system and the number of the upstream servers started in the upstream system.

In one embodiment, when the number of the started upstream servers in any one of the upstream systems changes and at least one upstream server is started currently, the following method may be adopted to determine the maximum request sending quota for the corresponding upstream server that is started currently:

for each upstream system, if the number of the upstream servers started in the upstream system currently changes, determining the maximum request sending quota of each upstream server started in the upstream system currently according to the maximum request sending quota of the upstream system currently and the number of the upstream servers started in the upstream system currently; the maximum request sending quota of the current upstream system is the product of the ratio of the sending quota of the current upstream system and the accumulated value of the maximum request processing quotas of all the currently started downstream servers.

In one embodiment, when the ratio of the sending quota of the upstream system changes and at least one upstream server is started currently, the following method may be adopted to determine the maximum request sending quota for the corresponding upstream server which is started currently:

for each upstream system with the changed sending quota ratio, multiplying the current sending quota ratio of the upstream system by the maximum request processing quota of the current downstream system to obtain the maximum request sending quota of the upstream system; and if the started upstream server exists in the upstream system, determining the maximum request sending quota of each upstream server started in the upstream system according to the maximum request sending quota of the upstream system and the number of the upstream servers started in the upstream system.

In the above embodiments, the following method may be specifically adopted to determine the maximum request sending quota of each upstream server that has been started in the current upstream system:

will be the current upstream system GiMaximum request sending quota and upstream system GiDividing the number of the currently started upstream servers; generating an upstream system G according to the division resultiThe maximum request sending quota of each upstream server that has been started.

Further, to avoid upstream systems GiThe accumulated value of the maximum request sending limits of all the upstream servers is greater than that of the upstream system GiMaximum request sending quota in (1)And simultaneously can make full use of the upstream system GiThe upstream system G may be determined based on the result of the division using the following methodiMaximum request sending quota for each upstream server that has been started:

if d is 0, the upstream system G is startediDetermining the maximum request sending quota of each upstream server which is started currently as the result of the division; d is the remainder of the division;

if d ≠ 0, then for the upstream system GiThe currently started upstream server determines the maximum request sending quota of the first d started upstream servers as a result of rounding up the division result, and determines the maximum request sending quota of other upstream servers except the first d started upstream servers as a result of rounding down the division result.

And 103, requesting the downstream system by each currently started upstream server by using the thread pool newly created locally.

In this step, each upstream server started in the upstream system needs to obtain a thread for a request from a thread pool created latest locally when the downstream system needs to be requested, and thus, because the number of threads in the thread pool is the maximum request sending limit of the upstream server, the number of requests initiated by the upstream server can be effectively controlled not to exceed the processing capacity of the downstream system, thereby avoiding the downstream bandwidth from being occupied, further avoiding the requests from being discarded due to timeout, thereby improving the success rate of the requests and reducing the request delay of the downstream system.

In one embodiment, the ratio of the sending quota of the upstream system may be dynamically adjusted according to the traffic needs of each actual upstream system, and to this end, the foregoing embodiment may further include:

when the sending quota ratio of more than one upstream system needs to be increased, the current limiter correspondingly reduces the sending quota ratios of other upstream systems while performing the increase; wherein the reduced transmission limit ratio total is the same as the increased transmission limit ratio total.

In one embodiment, when there is no started downstream server, each started upstream server may be notified to stop initiating the request downstream system, so as to avoid an invalid request operation, which may specifically be implemented by the following steps:

when the number of started downstream servers in the downstream system decreases to zero, the current limiter notifies all the upstream servers that have been currently started to prohibit requesting the downstream system.

In one embodiment, to improve the efficiency of throttling, when a downstream server is started, the maximum request sending quota of the upstream system is adjusted so that the maximum request sending quota of the upstream system stored in the flow limiter matches the actual request support capability of the downstream system, even if there is no upstream server that has been started at present. Therefore, when the upstream server is started later, the currently stored maximum request sending quota of the corresponding upstream system can be directly used, and the maximum request sending quota is configured for the upstream server without calculation, so that the overall efficiency of current limitation can be improved. The specific method comprises the following steps:

when the downstream server in the downstream system is started, if the started upstream server does not exist currently, the current limiter accumulates the maximum request processing limits respectively supported by all the currently started downstream servers to obtain the maximum request processing limit S of the current downstream systemmax

For each of the upstream systems, the flow restrictor passes the SmaxMultiplying the ratio of the maximum request sending quota of the upstream system by the ratio of the maximum request sending quota of the upstream system;

when the sending quota ratio of the upstream system changes, if no started upstream server exists currently, for each upstream system, the current flow restrictor multiplies the maximum request processing quota of the current downstream system by the sending quota ratio of the current upstream system to obtain the maximum request sending quota of the current upstream system.

The following describes specific implementation of the above embodiment according to scenarios such as starting the first upstream server and the first downstream server, increasing the number of the started upstream servers and the started downstream servers, closing the started upstream servers and the started downstream servers, and adjusting the sending quota share ratio of the upstream system, respectively:

suppose that: the upstream system comprises an upstream system A and an upstream system B, wherein the sending limit of the upstream system A accounts for 50% and the sending limit of the upstream system B accounts for 50% in the flow restrictor.

Scene one: the first downstream server (machine 1) starts up as shown in fig. 2.

Briefly, the following steps are carried out: the downstream system machine 1 creates a long connection with the restrictor after successful start-up, while the sending machine 1 supports the maximum requested quota.

It is assumed that each machine supports 200 requests at a time by default.

The current limiter records the maximum requested processing limit 200 for the machine 1.

Meanwhile, the maximum request transmission limit of the upstream system a is calculated to be 100. Specifically, the method is obtained by calculating the sending quota ratio of the upstream system A initialized according to the current limiter; the maximum request sending limit of the upstream system B is 100, namely the maximum request sending limit is calculated according to the sending limit ratio of the upstream system B initialized by the flow restrictor.

Scene two: the first upstream server (machine 1) starts up as shown in figure 3.

Briefly, the following steps are carried out: the upstream system machine 1 creates a long connection with the restrictor after successful start-up.

The flow restrictor calculates the maximum request sending quota issued to each connected upstream machine according to the number of long connections (i.e. the started upstream server) of the upstream system a.

The specific calculation method of the maximum request sending quota of the upstream machine comprises the following steps:

dividing the maximum request sending quota of the upstream system A by the long connection number of the upstream system A;

the remainder is 0, and the maximum request sending quota of the upstream machine is the division result of the maximum request sending quota of the upstream system A and the long connection number of the upstream system A;

the remainder is not 0, and the maximum request sending average quota of each upstream machine in the system A is obtained according to (the maximum request sending quota of the upstream system A-the remainder) ÷ the long connection number of the upstream system A. According to the connection sequence of the upstream system A and the current limiter, sequentially traversing each started upstream machine in the system A, adding 1 to the maximum request sending average quota of the upstream machine to obtain the maximum request sending quota of the upstream machine, simultaneously subtracting 1 from the remainder, and continuously traversing the next upstream machine until the remainder is 0.

The upstream system a machine 1 gets a maximum request sending quota issued by the restrictor 100. Specifically, it is obtained as 100 (i.e., the upstream system a maximum request transmission limit) × 1 (i.e., the long connection number).

Upstream system a machine 1 creates a custom thread pool (the maximum supported thread is the maximum request-to-send quota for machine 1) from its maximum request-to-send quota, by which upstream system a machine 1 requests the downstream system.

Scene three: the number of downstream servers that are started up increases as shown in fig. 4.

Briefly, the following steps are carried out: in the case where the machine 1 has started in the downstream system, the machine 2 starts up, and after successful start up, creates a long connection with the current limiter, while sending the maximum requested processing limit supported by the machine 2.

The flow restrictor adds the maximum request processing limits supported by machines 1 and 2 of the upstream system to obtain the maximum supported request number of the downstream system of 400. The calculated flow restrictor gives a limit of 200 to each machine of the upstream system a. Specifically, it is obtained as 400 (maximum request processing limit of downstream system) × 50% (upstream system a transmission limit ratio) ÷ 1 (number of upstream system a connections).

The machine 1 in the upstream system a receives the maximum request sending quota issued by the current limiter, and generates the maximum thread number 200 of the custom thread pool. Thereafter, machine 1 in upstream system a requests the downstream system through the thread pool.

Scene four: the number of upstream servers started increases as shown in fig. 5.

Briefly, the following steps are carried out: in the case where the machine 1 has started in the upstream system, the upstream machine 2 starts, and after successful start a long connection is created with the restrictor.

And the current limiter calculates the maximum request sending quota issued to the upstream machine corresponding to each connection according to the long connection number of the upstream system A.

The maximum request sending quota that the restrictor issues to each machine in the upstream system a is calculated to be 100. Specifically, it is obtained as 400 (maximum number of requests supported by downstream system) × 50% (ratio of transmission limit of upstream a system) ÷ 2 (number of connections of upstream a system).

And the machine 1 and the machine 2 in the upstream system A receive the maximum request sending quota issued by the current limiter and generate the maximum thread number 100 of the user-defined thread pool. Requesting downstream systems through a thread pool.

Scene five: the active downstream server shuts down as shown in fig. 6.

Briefly, the following steps are carried out: the downstream machine 2 in scenario four is shut down.

The current maximum requested processing limit of the downstream system is updated to the maximum requested processing limit of the original restrictor downstream system-the maximum requested processing limit supported by the downstream machine 2 is 200.

And the current limiter calculates the maximum request sending quota transmitted to the upstream machine corresponding to each connection according to the long connection number of the upstream A system.

The maximum request sending limit of the current limiter to each machine of the upstream system A is calculated to be 50. Specifically, it is calculated as 200 (maximum request processing limit of downstream system) × 50% (transmission limit of upstream system a ratio) ÷ 2 (number of connections of upstream system a).

After receiving the maximum request sending quota issued by the current limiter, the machine 1 and the machine 2 of the upstream system a generate the maximum thread number 50 of the custom thread pool, and request the downstream system through the thread pool.

If the machines of the downstream system are all shut down, i.e., there are no downstream machines establishing a connection with the restrictor, the restrictor issues a notification to the machines of the upstream system that inhibits the request for the downstream system. The upstream machine will not request the downstream system based on the notification.

Scene six: the upstream server that started is shut down as shown in fig. 7.

Briefly, the following steps are carried out: the upstream machine 2 in scenario five is shut down. The current limiter calculates according to the long connection number of the upstream A system, and sends a maximum request sending quota to each connected upstream machine.

The maximum request sending quota that the current limiter issues to each started machine in the upstream system a is recalculated to 100. Specifically, it is calculated as 200 (maximum request processing limit of downstream system) × 50% (transmission limit of upstream system a ratio) ÷ 1 (number of connections of upstream system a).

The machine 1 in the upstream system a receives the maximum request sending quota issued by the current limiter, and generates the maximum thread number 100 of the custom thread pool. Requesting downstream systems through a thread pool.

Scene seven: the transmission quota of the upstream system decreases.

In the case where the upstream system a limit is 50% and the upstream system B limit is 50%, the transmission limit ratio of the upstream system a is reduced to 40%.

The flow restrictor calculates the maximum request sending quota issued to each connected upstream machine according to the long connection number of the upstream system A.

The flow restrictor issues a maximum request-to-send quota of 80 to each enabled upstream machine in the upstream system a. Specifically, it is calculated as 200 (maximum request processing limit of downstream system) × 40% (transmission limit of upstream system a) ÷ 1 (number of connections of upstream system a).

The machine 1 in the upstream system a receives the maximum request sending quota issued by the current limiter, and generates the maximum thread number 80 of the custom thread pool. Requesting downstream systems through a thread pool.

If the upstream system A sends a limit of 0%, the restrictor sends a stop request downstream system identification to the upstream system so that the upstream system will not request the downstream system any more.

Rounding down (e.g., 8.5 to 8) is performed if the maximum request-to-send quota of upstream system a is fractional.

The maximum request sending quota calculation method of each upstream machine in the upstream system A comprises the following steps:

the quota of the upstream system A is divided by the number of long connections of the upstream system A

When the remainder is 0, the maximum request sending quota of the upstream machine is the result of division;

when the remainder is not 0, (the maximum request transmission quota of the upstream system a — the remainder) is divided by the long connection number of the upstream system a to obtain the maximum request transmission average quota. The remainder is added with 1 and subtracted with 1 in turn according to the connection order of the upstream system A and the current limiter, until the remainder is reduced to 0.

And eighth scene: the transmission quota of the upstream system increases.

When the upstream system A transmission limit ratio is 50% and the upstream system B transmission limit ratio is 50%, the transmission limit ratio of the system A needs to be increased to 60%, and correspondingly, the transmission limit ratio of the system B can be reduced to 40% so as to meet the requirement that the sum of the transmission limit ratios of all the upstream systems is 1.

And the current limiter calculates according to the long connection number of the upstream A system and sends a maximum request sending quota to the upstream machine corresponding to each connection. Specifically, 120 is obtained as 200 (maximum request processing limit of the current downstream system) × 60% (transmission limit of the upstream system a ratio) ÷ 1 (number of connections of the upstream system a).

The flow restrictor sends a maximum request sending quota 120 to each machine of the upstream system a.

And the machine 1 in the upstream system A receives the current limiter issued quota and generates the maximum thread number 120 of the user-defined thread pool. Requesting downstream systems through a thread pool.

Corresponding to the method embodiment, the embodiment of the invention also discloses an upstream system current limiting device which is arranged in the current limiter. Fig. 8 is a structural diagram of a current limiting device of an upstream system implemented in this embodiment, and as shown in fig. 8, the device includes:

the event monitoring module is used for monitoring whether a preset quota configuration trigger event occurs at present or not in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

the system comprises a flow limiting control module, a flow control module and a flow control module, wherein the flow limiting control module is used for determining a maximum request sending limit for a corresponding upstream server which is started currently according to the maximum request processing capacity supported by a current downstream system when monitoring that a preset limit configuration triggering event occurs currently and at least one upstream server is started currently, and notifying the upstream server so as to trigger the upstream server to create or recreate a thread pool for requesting the downstream system locally for the first time according to the notification; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

Corresponding to the above method embodiments, the embodiment of the present invention further discloses an electronic device, which includes a processor, a memory, and a computer program stored in the memory and operable on the processor, and when the processor executes the computer program, the following steps are implemented:

monitoring whether a preset quota configuration trigger event occurs at present or not in real time; the quota configuration triggering event comprises: the number of the started downstream servers in the downstream system changes and the number of the started upstream servers in any preset upstream system changes;

when the limit configuration triggering event is monitored to occur and at least one current upstream server is started, configuring a maximum request sending limit for the corresponding currently started upstream server according to the maximum request processing capacity supported by the current downstream system so as to trigger the upstream server to locally and firstly create or recreate a thread pool for requesting the downstream system according to the configuration; the maximum thread number supported by the thread pool is the maximum request sending quota of the notification.

The memory may be embodied as various storage media such as an Electrically Erasable Programmable Read Only Memory (EEPROM), a Flash memory (Flash memory), and a Programmable Read Only Memory (PROM). The processor may be implemented to include one or more central processors or one or more field programmable gate arrays, wherein the field programmable gate arrays integrate one or more central processor cores. In particular, the central processor or central processor core may be implemented as a CPU or MCU.

It should be noted that not all steps and modules in the above flows and structures are necessary, and some steps or modules may be omitted according to actual needs. The execution order of the steps is not fixed and can be adjusted as required. The division of each module is only for convenience of describing adopted functional division, and in actual implementation, one module may be divided into multiple modules, and the functions of multiple modules may also be implemented by the same module, and these modules may be located in the same device or in different devices.

The hardware modules in the various embodiments may be implemented mechanically or electronically. For example, a hardware module may include a specially designed permanent circuit or logic device (e.g., a special purpose processor such as an FPGA or ASIC) for performing specific operations. A hardware module may also include programmable logic devices or circuits (e.g., including a general-purpose processor or other programmable processor) that are temporarily configured by software to perform certain operations. The implementation of the hardware module in a mechanical manner, or in a dedicated permanent circuit, or in a temporarily configured circuit (e.g., configured by software), may be determined based on cost and time considerations.

In correspondence with the above method embodiments, embodiments of the present invention also disclose a computer-readable storage medium, and specifically, a system or an apparatus equipped with a storage medium on which computer-readable instructions are stored, which, when executed by a processor, implement software program code of the functions of any of the above embodiments, and cause a computer (or a CPU or MPU) of the system or apparatus to read out and execute the program code stored in the storage medium, may be provided. Further, part or all of the actual operations may be performed by an operating system or the like operating on the computer by instructions based on the program code. The functions of any of the above-described embodiments may also be implemented by writing the program code read out from the storage medium to a memory provided in an expansion board inserted into the computer or to a memory provided in an expansion unit connected to the computer, and then causing a CPU or the like mounted on the expansion board or the expansion unit to perform part or all of the actual operations based on the instructions of the program code.

Examples of the storage medium for supplying the program code include floppy disks, hard disks, magneto-optical disks, optical disks (e.g., CD-ROMs, CD-R, CD-RWs, DVD-ROMs, DVD-RAMs, DVD-RWs, DVD + RWs), magnetic tapes, nonvolatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer or the cloud by a communication network.

"exemplary" means "serving as an example, instance, or illustration" herein, and any illustration, embodiment, or steps described as "exemplary" herein should not be construed as a preferred or advantageous alternative. For the sake of simplicity, the drawings are only schematic representations of the parts relevant to the invention, and do not represent the actual structure of the product. In addition, in order to make the drawings concise and understandable, components having the same structure or function in some of the drawings are only schematically illustrated or only labeled. In this document, "a" does not mean that the number of the relevant portions of the present invention is limited to "only one", and "a" does not mean that the number of the relevant portions of the present invention "more than one" is excluded. In this document, "upper", "lower", "front", "rear", "left", "right", "inner", "outer", and the like are used only to indicate relative positional relationships between relevant portions, and do not limit absolute positions of the relevant portions.

The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

23页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:分布式限流方法、装置、设备、存储介质和系统

网友询问留言

已有0条留言

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

精彩留言,会给你点赞!