Universal and special mixed flow control method, computer equipment and storage medium

文档序号:1908211 发布日期:2021-11-30 浏览:28次 中文

阅读说明:本技术 一种通用与专用混合流量控制方法、计算机设备和存储介质 (Universal and special mixed flow control method, computer equipment and storage medium ) 是由 陈琮 魏明丽 周高翔 严萍萍 张磊 贾龙龙 于 2021-08-23 设计创作,主要内容包括:本发明涉及一种通用与专用混合流量控制方法、计算机设备和存储介质,将现有系统流量上限设定阈值,将整体流量分为通用流量和专用流量;对请求的参数中设定一个权重值,根据权重值判定请求为高低;请求到达时,首先向通用流量令牌桶请求令牌,若获取到令牌,则执行请求,并将通用流量令牌桶中的令牌数减少一个,若此刻通用流量令牌桶中的令牌数量不足,则判断该请求的权重,若为低权重请求,则拒绝请求,若为高权重请求,则再向专用流量令牌桶请求令牌,若获取到令牌,则执行请求,若专用流量令牌桶中令牌不足,则拒绝请求。与现有技术相比,本发明可优先保障高权限请求处理,将低权重请求抛弃降低系统负载,提高系统资源使用效能。(The invention relates to a general and special mixed flow control method, computer equipment and a storage medium, wherein the upper limit of the flow of the existing system is set as a threshold value, and the whole flow is divided into general flow and special flow; setting a weight value in the requested parameters, and judging the request to be high or low according to the weight value; when a request arrives, firstly, a token is requested from a general traffic token bucket, if the token is acquired, the request is executed, the number of the tokens in the general traffic token bucket is reduced by one, if the number of the tokens in the general traffic token bucket is insufficient at the moment, the weight of the request is judged, if the request is a low weight request, the request is rejected, if the request is a high weight request, the token is requested from a special traffic token bucket, if the token is acquired, the request is executed, and if the token in the special traffic token bucket is insufficient, the request is rejected. Compared with the prior art, the method and the device can preferentially ensure the processing of the high-authority request, abandon the low-weight request to reduce the system load and improve the use efficiency of system resources.)

1. A general and special mixed flow control method is characterized by comprising the following steps:

1) setting a threshold value for the upper limit of the flow of the existing system in advance, dividing the whole flow into general flow and special flow according to the threshold value, and correspondingly generating a general flow token bucket and a special flow token bucket;

2) setting a weight value for the request, and judging the request to be a high-weight request or a low-weight request according to the weight value;

3) when a request arrives, firstly requesting a token from a general traffic token bucket, if the token is obtained, executing the request, reducing the number of the tokens in the general traffic token bucket by one, and if the number of the tokens in the general traffic token bucket is insufficient at the moment, executing the next step;

4) judging the weight of the request, if the request is a low-weight request, rejecting the request, if the request is a high-weight request, requesting a token from a special traffic token bucket, if the token is obtained, executing the request, and if the token in the special traffic token bucket is insufficient, rejecting the request.

2. The mixed universal and dedicated flow control method as claimed in claim 1, wherein in step 1), the tokens are continuously put into the universal traffic token bucket at a rate until the universal traffic token bucket is full, and the tokens are continuously put into the dedicated traffic token bucket at a rate until the universal traffic token bucket is full, the rates of putting the tokens being different.

3. The mixed universal and dedicated flow control method according to claim 2, wherein in step 1), the upper limit of the existing system flow is R, the token placing rate of the universal flow token bucket is R × percentage corresponding to the set threshold, and the token placing rate of the dedicated flow token bucket is R × 1 percentage corresponding to the set threshold.

4. The mixed universal and dedicated flow control method according to claim 3, wherein the upper limit of the existing system flow is set to 500 requests/sec, and the percentage corresponding to the threshold is set to 80%, the rate of placing tokens in the token bucket for universal flow is 500 x 80% ═ 400 requests/sec, and the rate of placing tokens in the token bucket for dedicated flow is 500 x 20% ═ 100 requests/sec.

5. The mixed universal and dedicated flow control method according to claim 1, wherein the weight value set for the request is in a range of 1 to 10.

6. The combined universal and dedicated flow control method according to claim 5, wherein if the weight value of the request is greater than 5, it is determined that the request belongs to a high weight request, and if the weight value of the request is less than or equal to 5, it is determined that the request belongs to a low weight request.

7. The mixed universal and dedicated flow control method as claimed in claim 1, wherein when the number of tokens in the universal traffic token bucket is zero, it is determined that the number of tokens in the universal traffic token bucket is insufficient.

8. The mixed universal and dedicated flow control method as claimed in claim 1, wherein when the number of tokens in the dedicated flow token bucket is zero, it is determined that the number of tokens in the dedicated flow token bucket is insufficient.

9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method of any of claims 1 to 8 are implemented when the computer program is executed by the processor.

10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 8.

Technical Field

The present invention relates to the field of traffic management technologies, and in particular, to a general and specific hybrid traffic control method, a computer device, and a storage medium.

Background

With the development of computer technology, more and more technologies are applied to the fields of finance, IT technology and the like, but higher requirements are also put forward on the technologies due to the requirements of safety and real-time performance of various industries. In the aspect of data traffic management, in order to prevent a system from being paralyzed due to an excessive access amount of a certain server or an excessive access amount of a certain application, a traffic control mode is often adopted to protect a server or an application background.

The conventional flow control method adopts a token bucket algorithm, and as shown in fig. 1, a program firstly sets a token bucket for storing a fixed number of tokens. The program adds tokens to the token bucket at a rate of r (r ═ the flow limit value/time period second) until the token bucket is full. When the request arrives, a token needs to be requested from the token bucket, if the token is obtained, the request is passed, and otherwise, a current limiting strategy is triggered. This action of placing tokens is persistent, and if the token bucket is full, no more tokens can be placed. And if the number of tokens in the token bucket is 0, the request is blocked or denied. In token bucket algorithms, the token bucket capacity typically corresponds to an upper limit of requests that can be handled by system resources. The token bucket algorithm has the advantages of guaranteeing the inflow frequency of the flow and guaranteeing that the system can still stably run when the system requests sudden increase. The current method of throttling using token bucket algorithm is to set the maximum number of tokens in token bucket, and usually limit the capacity that can be borne by the corresponding system resource. However, in this way, when the system resource is insufficient and the current limiting policy is started to be executed, all requests are blocked or rejected all at once, and the system resource cannot be fully utilized to guarantee the processing of important requests.

Disclosure of Invention

The present invention provides a general and special mixed flow control method, a computer device and a storage medium for overcoming the defects of the prior art, which can preferentially ensure the processing of high-authority requests (system core service requests) under the condition of shortage or insufficiency of system resources, abandon low-weight requests to reduce system load and improve the use efficiency of the system resources.

The purpose of the invention can be realized by the following technical scheme:

a method for controlling a combined universal and proprietary flow, the method comprising the steps of:

s1: the method comprises the steps of setting a threshold value for the upper limit of the flow of the existing system in advance, dividing the whole flow into general flow and special flow according to the threshold value, and correspondingly generating a general flow token bucket and a special flow token bucket.

S2: and setting a weight value for the request, and judging the request to be a high-weight request or a low-weight request according to the weight value.

S3: when the request arrives, firstly, a token is requested from the general traffic token bucket, if the token is obtained, the request is executed, the number of the tokens in the general traffic token bucket is reduced by one, and if the number of the tokens in the general traffic token bucket is insufficient at the moment, the next step is executed.

S4: judging the weight of the request, if the request is a low-weight request, rejecting the request, if the request is a high-weight request, requesting a token from a special traffic token bucket, if the token is obtained, executing the request, and if the token in the special traffic token bucket is insufficient, rejecting the request.

In S1, tokens are continuously put into the general traffic token bucket at a certain rate until the general traffic token bucket is full, and tokens are continuously put into the dedicated traffic token bucket at a certain rate until the general traffic token bucket is full, the rates of putting tokens in the general traffic token bucket and the dedicated traffic token bucket are different. And making the upper limit of the flow of the existing system be R, setting the token placing rate of the general flow token bucket to be R x and the percentage corresponding to the set threshold value, and setting the token placing rate of the special flow token bucket to be R x (1-the percentage corresponding to the set threshold value).

Further, the upper limit of the existing system traffic is set to 500 requests/second, and the percentage corresponding to the threshold is set to 80%, then the rate of placing tokens by the general traffic token bucket is 500 × 80% — 400 requests/second, and the rate of placing tokens by the special traffic token bucket is 500 × 20% — 100 requests/second.

Furthermore, the weight value set for the request is in the range of 1-10. If the weight value of the request is greater than 5, the request is judged to belong to a high-weight request, and if the weight value of the request is less than or equal to 5, the request is judged to belong to a low-weight request.

Further, when the number of tokens in the general traffic token bucket is zero, it is determined that the number of tokens in the general traffic token bucket is insufficient. And when the number of the tokens in the special traffic token bucket is zero, judging that the number of the tokens in the special traffic token bucket is insufficient.

A computer arrangement comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the general and specific mixed flow control method described above when executing the computer program.

A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned general and specific mixed flow control method.

Compared with the prior art, the universal and special mixed flow control method, the computer equipment and the storage medium provided by the invention at least have the following beneficial effects:

1) the invention distinguishes the request set weight value or priority, the request with high weight allows the request special flow, and sets different flow pools for the system resource according to the threshold value, aiming at the situation that the system resource is in shortage, the special flow can be used according to the request weight value or priority, and the situation that all the requests are blocked or rejected all together can be avoided;

2) compared with the existing flow control method adopting the token bucket algorithm, the method can preferentially guarantee the service of the high-weight request after the system resources reach the shortage threshold according to the weight of the request, abandon the low-weight request, improve the utilization efficiency of the system resources and guarantee the operation of the core service; and the system stability can be improved, unimportant requests are rejected after the system processing threshold value is approached, and the system resource bottleneck is avoided.

Drawings

FIG. 1 is a schematic diagram illustrating a flow control method using a token bucket algorithm;

FIG. 2 is a schematic flow chart of the general and special mixing flow control method in the embodiment.

Detailed Description

The invention is described in detail below with reference to the figures and specific embodiments. It is to be understood that the embodiments described are only a few embodiments of the present invention, and not all embodiments. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, shall fall within the scope of protection of the present invention.

Examples

Fig. 2 is a schematic main flow diagram of a general and specific mixed flow control method according to an embodiment of the present invention. As an embodiment of the present invention, as shown in fig. 2, the general and specific mixed flow control method may include:

step one, a threshold value is set in advance for the upper limit R of the flow of the existing system, the whole flow is divided into general flow and special flow, and a general flow token bucket and a special flow token bucket are correspondingly generated.

In the actual process, tokens are put into the general traffic token bucket at a certain speed, the action of putting the tokens is continuous all the time, and if the token bucket is full, more tokens can not be put in. Meanwhile, tokens are placed in the special traffic token bucket at a certain rate, the action of placing the tokens is continuous all the time, and if the token bucket is full, more tokens cannot be placed. The rate at which tokens are placed by the two buckets is different. The rate of tokens put by the general traffic token bucket is R threshold (percentage), and the rate of tokens put by the special traffic token bucket is R threshold (1).

In a preferred embodiment, the total upper limit of the traffic is set to (R: 500 requests/sec), and if the resource usage reaches a threshold of 80%, it is considered that the resource is in shortage and the flow limitation is required, and the upper limit of the general traffic token bucket is set to 500 × 80%: 400 requests/sec. The dedicated traffic token bucket is capped at 500 x 20% ═ 100 requests/second. That is, if R is the upper limit 500 requests/sec of the system processing request and the threshold is 80%, the token placing speed of the general traffic token bucket is R1-400 requests/sec, and the token placing speed of the special traffic token bucket is R2-100/sec.

And step two, setting a weight value Q (in a range of 1-10) for the request, and judging the height of the request according to the weight value. The weight setting mode may be set according to the importance of the system service request, and is not limited in this embodiment.

Preferably, if Q >5 belongs to a high weight request, and if Q < ═ 5, the request is considered to be of low weight.

And step three, when the request arrives, firstly requesting the token from the general flow token bucket, and if the token is obtained, executing the request. The number of tokens in the token bucket is reduced by one. If the number of tokens in the generic traffic token bucket at this moment is insufficient (the number of tokens is 0), the next step is performed.

And step four, checking the weight of the request under the condition that the number of the tokens is insufficient, and rejecting the request if the request is a low-weight request. And if the request is a high-weight request, requesting the token from the special traffic token bucket. If the token is acquired, the request is executed, and if the token in the special traffic token bucket is insufficient (the number of tokens is 0), the request is rejected.

In this embodiment, there is also provided a computer device, which may be a server, comprising a processor, a memory and a network interface connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement the general and specific mixed flow control method described above.

In this embodiment, there is also provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the above-described general and specific mixed flow control method.

Compared with the existing common token bucket algorithm, the method does not distinguish the request weight and the token bucket classification. In the actual service scene of the system, the importance degrees of all requests are not the same, in order to more effectively utilize system resources and ensure the important services of the system, the invention distinguishes the weight of the requests, thereby distributing a flow pool. Under the condition that system resources are in shortage or insufficient, the processing of high-authority requests (system core service requests) can be preferentially ensured, low-weight requests are abandoned, the system load is reduced, and the use efficiency of the system resources is improved.

While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and those skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

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

网友询问留言

已有0条留言

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

精彩留言,会给你点赞!