Current limiting method, device, processor and electronic device

The current limiting method uses a statistical time window and sliding window hybrid algorithm to accurately count transactions and manage concurrency, addressing server crashes and burst traffic in distributed systems by limiting based on transaction processing volume.

CN115022244BActive Publication Date: 2024-12-31INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210857532.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-20
Publication Date
2024-12-31
Estimated Expiration
2042-07-20

AI Technical Summary

Technical Problem

Existing current limiting algorithms struggle to accurately count transactions and control instantaneous traffic in complex distributed systems, leading to server crashes and inefficiencies due to time criticality and burst traffic issues.

Method used

A current limiting method that uses a statistical time window based on transaction initiation times to count transactions within a preset duration, rejecting requests when the threshold is exceeded, and employs a sliding window hybrid algorithm to manage concurrency accurately.

Benefits of technology

Accurately limits current based on transaction processing volume (TPS) rather than query rate (QPS), avoiding inaccuracies and system crashes by delineating transactions with timestamps, ensuring system availability and managing peak traffic effectively.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115022244B_ABST
    Figure CN115022244B_ABST
Patent Text Reader

Abstract

The present application discloses a flow limiting method, device, processor and electronic device. It relates to the field of information security. The method comprises: obtaining a transaction request; taking the initiation time of the transaction request as the time starting point, determining a statistical time window of a preset time length; counting the total number of transactions being executed within the statistical time window; and rejecting the transaction request when the total number of transactions exceeds a preset threshold. The present application solves the problem that the flow limiting object cannot be accurately counted in the related art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of information security, and in particular, to a current limiting method, device, processor and electronic device. Background Art

[0002] In the process of developing distributed systems, it is inevitable to encounter high concurrency problems, and current limiting is a way to protect the system by controlling the flow. There are many existing current limiting algorithms, among which the most common ones are counter algorithm, token bucket algorithm, leaky bucket algorithm, etc.

[0003] The above-mentioned common algorithms have their own advantages and disadvantages. They are usually applicable to a single scenario. Often, they cannot handle some special scenarios within the application well during use. For example, the counter algorithm has a fatal time criticality problem; the token bucket algorithm cannot control burst traffic; although the leaky bucket algorithm can smooth burst traffic on the network, it will also have serious problems in special scenarios. For example, in a distributed system, when a PaaS container crashes due to too many requests, it can no longer perform normal decrement (the leaky bucket discharges water at a constant speed), resulting in inaccurate counting. In extreme cases, it will cause the server to restart continuously, crash, or cause other servers to be restricted when the number of requests is low. In addition, compared with controlling the number of requests per unit time (QPS), actual applications generally tend to control the number of concurrent transactions (TPS), which is also difficult to achieve using the above algorithms.

[0004] For actual distributed systems, business scenarios are often complex or special. Using a single current limiting method cannot well meet the following requirements: both the current limiting of transactions and the control of instantaneous traffic must be achieved, and the problem of inaccurate counting in extreme scenarios must also be considered.

[0005] With regard to the problem in the related art that current limiting objects cannot be accurately counted, no effective solution has been proposed yet. Summary of the invention

[0006] The main purpose of the present application is to provide a current limiting method, device, processor and electronic device to solve the problem of accurately counting current limiting objects in the related art.

[0007] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a flow limiting method is provided. The method includes: obtaining a transaction request; taking the initiation time of the transaction request as the time starting point, determining a statistical time window of a preset duration; counting the total number of transaction transactions being executed within the statistical time window; and rejecting the transaction request if the total number of transactions exceeds a preset threshold.

[0008] Optionally, counting the number of transactions of the transaction being executed within the statistical time window includes: determining the access object pointed to by the transaction request; obtaining a time window sequence of the access object, wherein the time window sequence includes at least one traffic time window, each traffic time window is used to record the transaction being executed within a preset time period; selecting at least one traffic time window to be counted corresponding to the statistical time window in the time window sequence; and counting the total number of transactions in at least one traffic time window to be counted.

[0009] Optionally, obtaining the time window sequence of the access object includes: identifying the target object that initiates the transaction request; obtaining at least one transaction of the target object; adding a timestamp and identification information to each transaction according to the transaction time, wherein the identification information is determined based on the timestamp and a random number; recording at least one of the transaction transactions into the corresponding traffic time window according to the timestamp; and arranging at least one of the traffic time windows in chronological order to obtain the time window sequence.

[0010] Optionally, recording at least one of the transaction transactions into the corresponding traffic time window according to the timestamp includes: arranging at least one of the transaction transactions in chronological order according to the timestamp to obtain a transaction transaction sequence; dividing the transaction transaction sequence into multiple transaction transaction sets according to a preset time period indicated by the traffic time window; and recording each of the transaction transaction sets into the corresponding traffic time window.

[0011] Optionally, selecting at least one traffic time window to be counted corresponding to the statistical time window in the time window sequence includes: determining the time start point and time end point of the sliding time window; determining the traffic time window corresponding to the time start point as the first traffic time window; determining the traffic time window corresponding to the time end point as the second traffic time window; and determining the first traffic time window, the second traffic time window, and the traffic time window between the first traffic time window and the second traffic time window as the traffic time windows to be counted.

[0012] Optionally, counting the number of transactions in at least one traffic time window to be counted includes: counting the number of window transactions of transaction transactions in each of the traffic time windows to be counted; and accumulating the number of window transactions to determine the total number of transactions.

[0013] Optionally, after determining the total number of transaction transactions being executed within the statistical time window, the method further includes: responding to the transaction request if the total number of transactions does not exceed a preset threshold; recording the transaction generated in response to the transaction request; monitoring the transaction status of the transaction; and deleting the record of the transaction if the transaction status is that the transaction is completed.

[0014] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a current limiting device is provided. The device includes: an acquisition module for acquiring a transaction request; a determination module for determining a statistical time window of a preset duration using the initiation time of the transaction request as the time starting point; a statistical module for counting the total number of transaction transactions being executed within the statistical time window; and a current limiting module for rejecting the transaction request when the total number of transactions exceeds a preset threshold.

[0015] In order to achieve the above object, according to another aspect of the present application, a processor is provided. The processor is used to run a program, wherein the above current limiting method is executed when the program is run.

[0016] In order to achieve the above-mentioned purpose, according to another aspect of the present application, an electronic device is provided. The electronic device includes one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the current limiting method described above.

[0017] Through the present application, the following steps are adopted: obtaining a transaction request; taking the initiation time of the transaction request as the time starting point, and determining a statistical time window of a preset time length; determining the total number of transactions being executed in the statistical time window; when the total number of transactions exceeds the preset threshold, rejecting the transaction request; solving the problem that the current limiting object cannot be accurately counted in the related technology; since the statistical time window delineates the transaction being executed, the current is limited according to the transaction being executed, and the purpose of current limiting based on the transaction processing volume TPS is achieved. Compared with the prior art solution of limiting the current based on the query rate per second QPS, the current limiting based on the transaction processing volume TPS can more accurately limit the current according to the processing capacity of the transaction; and since the statistical time window in the present application is delineated according to the transaction initiation time, there is no accumulation of historical transaction transactions. Compared with the solution used in the existing sliding time window technology of adding windows in the sliding time window according to fixed time intervals, the transaction being executed can be more accurately counted, and the technical effect of accurately counting the current limiting objects is achieved. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] Figure 1 is a flow chart of a current limiting method provided according to an embodiment of the present application;

[0020] Figure 2 is a schematic diagram of a statistical time window provided according to an embodiment of the present application;

[0021] Figure 3 is a schematic diagram of a distributed global current limiting mechanism based on an improved sliding window algorithm according to an embodiment of the present application;

[0022] Figure 4 is a schematic diagram of a current limiting device provided according to an embodiment of the present application;

[0023] Figure 5 is a schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0024] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] For the convenience of description, some nouns or terms involved in the embodiments of the present application are explained below:

[0028] Distributed application: refers to a working method in which applications are distributed on different computers and work together to complete a task through the network.

[0029] Current limiting: Limit the number of requests within a time window to maintain system availability and stability and prevent system slowdown or downtime caused by traffic surges.

[0030] Global flow control: Different from single-point flow control, single-point flow control only limits the flow of transaction requests on a single server, while global flow control can control the flow of all servers as a whole in a distributed application.

[0031] Token Bucket Algorithm: One of the most commonly used current limiting algorithms, used to control the amount of data sent to the network and allow burst data to be sent.

[0032] Leaky Bucket Algorithm: The main purpose is to control the rate at which data is injected into the network and smooth out burst traffic on the network.

[0033] It should be noted that the relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. For example, an interface is set between this system and the relevant user or organization. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or organization.

[0034] The present invention is described below in conjunction with preferred implementation steps. Figure 1 is a flow chart of a current limiting method provided according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:

[0035] Step S102, obtaining a transaction request;

[0036] Step S104, taking the initiation time of the transaction request as the time starting point, determining a statistical time window of a preset time length;

[0037] Step S106, determining the total number of transactions being executed within the statistical time window;

[0038] Step S108: If the total number of transactions exceeds a preset threshold, the transaction request is rejected.

[0039] Obtain a transaction request; take the initiation time of the transaction request as the time starting point, and determine a statistical time window of a preset time length; determine the total number of transactions being executed within the statistical time window; if the total number of transactions exceeds the preset threshold, reject the transaction request; solve the problem that the current limiting object cannot be accurately counted in the related technology; since the statistical time window delineates the transaction being executed, the current is limited according to the transaction being executed, and the purpose of current limiting based on the transaction processing volume TPS is achieved. Compared with the current limiting solution based on the query rate per second QPS in the prior art, the current limiting based on the transaction processing volume TPS can more accurately limit the current according to the processing capacity of the transaction; and since the statistical time window in the present application is delineated according to the transaction initiation time, there is no accumulation of historical transaction transactions. Compared with the solution used in the existing sliding time window technology of adding windows in the sliding time window according to fixed time intervals, the transaction being executed can be more accurately counted, and the technical effect of accurately counting the current limiting objects is achieved.

[0040] The above current limiting method can be applied in the development process of distributed systems to avoid high concurrency problems in transaction transactions.

[0041] In the above step S102, the object of obtaining the transaction request may be a server. On the server side, the process of receiving the transaction request, processing the transaction request, and then returning the processing result is a complete transaction.

[0042] It should be noted that TPS: Transactions Per Second, means the number of transactions per second; and QPS: Queries Per Second, means the query rate per second. One transaction can include multiple queries.

[0043] For example, if a transaction includes three server response events and the processing time of a transaction is 1S, the statistical result of TPS is 1 and the statistical result of QPS is 3.

[0044] In the above step S102, the device that responds to the transaction request and executes the transaction behavior may be a distributed server. The execution capacity of each server is limited. In order to avoid high concurrency problems when the server is executing the transaction behavior, before responding to the transaction request, it is necessary to count the transaction transactions being executed and determine the total number of transactions. Then, based on the total number of transactions, it is determined whether to respond to the transaction request.

[0045] Optionally, the current limiting method provided by the present invention can be applied to each node of the distributed system and deployed separately, or can be deployed globally in the distributed system.

[0046] In the above step S106, the transaction transactions generated in response to the transaction request in each time period can be recorded through the traffic time window.

[0047] In the above step S106, the statistical time window is a fixed-width time window, that is, the time period represented by the statistical time window is fixed, and the transaction transactions generated by the transaction requests responded to within the specified time period can be determined through the statistical time window.

[0048] Optionally, in the flow limiting method provided in the embodiment of the present application, counting the number of transactions being executed within a time window includes: determining the access object to which the transaction request points; obtaining a time window sequence of the access object, wherein the time window sequence includes at least one traffic time window, and each traffic time window is used to record the transactions being executed within a preset time period; selecting at least one traffic time window to be counted corresponding to the statistical time window in the time window sequence; and counting the total number of transactions in at least one traffic time window to be counted.

[0049] Optionally, the access object may be an object that obtains the transaction request, such as a server.

[0050] In the above-mentioned embodiment of the present invention, after receiving a transaction request, it is necessary to count the transaction transactions generated by the responded transaction request. During the statistical process, a time window sequence can be established according to the initiation time of the transaction request, and the traffic time windows can be set in the time window sequence in time order, and each traffic time window records the transaction transactions generated in response to the transaction request in each preset time period; and then, when the total number of transactions in the statistical time window is determined, the traffic time window included in the statistical time window can be circled in the time window sequence, and the total number of transactions can be counted based on the circled traffic time window; because the traffic time windows in the statistical window sequence are arranged in time order, after determining the time starting point of the statistical time window, the statistical time window can be quickly circled based on the time window sequence, which facilitates the selection of the statistical time window.

[0051] In the above step S106, the statistical time window is a fixed-width time window, and each traffic time window corresponds to a preset time period. The statistical time window may include a preset number of traffic time windows. By counting the transaction transactions in each traffic time window in the statistical time window, the total number of transaction transactions in the statistical time window can be determined.

[0052] Figure 2 is a schematic diagram of a statistical time window provided according to an embodiment of the present application, such as Figure 2As shown in the figure, the statistical time window is a fixed-width time window, and the score of the zset basic data type of Redis is used to circle this sliding time window. The zset data type is equivalent to an ordered set, and the order of different values ​​is distinguished by the size of the score.

[0053] In the above step S106, the statistical time window is redefined each time the total number of transactions is counted.

[0054] In the above step S108, when the total number of transactions exceeds the preset threshold, it means that the transaction being executed has reached the maximum execution number. Therefore, in order to ensure the correct execution of the transaction, it is necessary to reject subsequent transaction requests and perform a flow control operation.

[0055] In the above step S108, when the total number of transactions exceeds the preset threshold, an alarm message is triggered to prompt that the transaction being executed has reached the maximum execution number.

[0056] The technical solution provided by the present invention is improved based on the original sliding window algorithm to form a "sliding window hybrid counting algorithm" (i.e. a counting algorithm based on a statistical time window), which strives to accurately control transaction concurrency while calmly responding to emergency scenarios, avoiding losing the big picture for the small, and introducing new problems due to current limiting.

[0057] The technical solution provided by the present invention is an improvement based on a simple sliding window algorithm, which is like a sliding window, nested on a time window sequence and constantly moving forward, while the number of transactions contained in the window is limited and fixed. Whenever a transaction enters, it is placed in the front position of the time window sequence (arranged in order according to the timestamp when the transaction came in), and the flow count in the window is increased by one; and when the transaction is executed, it is cleared, and the flow count in the window is reduced by one. In this way, only a fixed number of transactions are allowed to proceed at the same time within a certain period of time, that is, instantaneous concurrency is limited. At the same time, since the statistical time window is implemented based on timestamps, as time goes by, transactions will eventually be removed from the window, so that even in special scenarios such as peak service request timeouts or server downtime causing service unresponsiveness, there is no need to worry about affecting the accuracy of the count.

[0058] Optionally, operations such as data calculation and storage are implemented through the Rdis database, which can meet the needs of each server in a distributed application to share the same data storage space and achieve more accurate global current limiting.

[0059] Optionally, the same time window sequence may represent multiple transactions of the same target object.

[0060] Optionally, in the flow limiting method provided in an embodiment of the present application, obtaining a time window sequence of an access object includes: identifying a target object for initiating a transaction request; obtaining at least one transaction transaction of the target object; adding a timestamp and identification information to each transaction transaction according to the transaction time, wherein the identification information is determined based on the timestamp and a random number; recording at least one transaction transaction into a corresponding traffic time window according to the timestamp; and arranging at least one traffic time window in chronological order to obtain a time window sequence.

[0061] In the actual operation process, each user's transaction is stored in a zset, and the key value of the set is: user number + transaction name, zset = {(score1, value1), (score2, value2), ...}, where each (score, value) represents a call record for each transaction.

[0062] In the above-mentioned embodiment of the present invention, a transaction table of each target object can be recorded through user number + transaction name. The transaction table can record the transaction of the target object through the zset data type, wherein score is Long type data, recording a millisecond timestamp, which is used to represent the timestamp of the transaction, and value is String type data, recorded as a timestamp + random number, which is used to represent the identification information of the transaction. This can avoid the problem of inaccurate final current limiting statistics caused by the transaction being overwritten when multiple calls are made instantaneously, and multiple calls made concurrently at the same time can be distinguished through the identification information.

[0063] In the above-mentioned embodiment of the present invention, when using traffic time windows to record transaction transactions, each traffic time window corresponds to a preset time period. The transaction transactions can be filled into the corresponding traffic time window according to the timestamp of each transaction transaction, and the traffic time windows can be sorted in chronological order to obtain a time window sequence.

[0064] Optionally, in the flow limiting method provided in the embodiment of the present application, recording at least one transaction transaction into the corresponding traffic time window according to the timestamp includes: arranging at least one transaction transaction in chronological order according to the timestamp to obtain a transaction transaction sequence; dividing the transaction transaction sequence into multiple transaction transaction sets according to a preset time period indicated by the traffic time window; and recording each transaction transaction set into the corresponding traffic time window.

[0065] In the above-mentioned embodiment of the present invention, when using a traffic time window to record transaction transactions, the transaction transactions can be sorted in chronological order according to the timestamp to obtain a transaction transaction sequence. According to the preset time period indicated by the traffic time window, the transaction transaction sequence arranged in chronological order can be divided into multiple transaction transaction sets. Each transaction transaction set can represent the transaction transactions generated within the corresponding preset time period, and then the corresponding traffic time window can be recorded according to the transaction transaction set, thereby achieving the purpose of recording transaction transactions through the traffic time window.

[0066] For example, the first traffic time window represents the first time period, and the second traffic time window represents the second time period. The transaction sequence can be divided into a first transaction set corresponding to the first time period, and a second transaction set corresponding to the second time period. Then, the transaction transactions in the first transaction set can be recorded in the first traffic time window, and the transaction transactions in the second transaction set can be recorded in the second traffic time window.

[0067] Optionally, in the flow limiting method provided in an embodiment of the present application, selecting at least one traffic time window to be counted corresponding to the statistical time window in the time window sequence includes: determining the time start point and time end point of the statistical time window; determining the traffic time window corresponding to the time start point as the first traffic time window; determining the traffic time window corresponding to the time end point as the second traffic time window; and determining the first traffic time window, the second traffic time window, and the traffic time window between the first traffic time window and the second traffic time window as the traffic time windows to be counted.

[0068] Optionally, the time end point may be determined according to the time start point and the width of the statistical time window (ie, a preset duration).

[0069] In the above-mentioned embodiment of the present invention, a first flow window corresponding to the start time of the statistical time window and a second flow window corresponding to the end time are determined in the time window sequence, and then the first flow time window, the second flow time window, and the flow time window between the first flow time window and the second flow time window are determined in the time window sequence as the time windows to be counted, thereby realizing the determination of the time windows to be counted.

[0070] Optionally, in the flow limiting method provided in the embodiment of the present application, counting the number of transactions in at least one traffic time window to be counted includes: counting the number of window transactions of transaction transactions in each traffic time window to be counted; accumulating the number of window transactions to determine the total number of transactions.

[0071] In the above-mentioned embodiment of the present invention, since the statistical time window includes a preset number of traffic time windows, the total number of transactions in the statistical time window is calculated, that is, the window transaction volume of the preset number of statistical time windows. After determining the statistical time window, the traffic time window in the statistical time window can be determined as the traffic time window to be counted, and then the transaction transactions in the traffic time window to be counted are counted separately to determine the number of window transactions of each traffic time window to be counted. The number of window transactions of the preset number of traffic time windows to be counted is accumulated to determine the total number of transactions, thereby realizing the statistics of the total number of transactions in the statistical time window.

[0072] Optionally, in the flow limiting method provided in the embodiment of the present application, after determining the total number of transaction transactions being executed within the statistical time window, the method also includes: responding to transaction requests when the total number of transactions does not exceed a preset threshold; recording transaction transactions generated in response to transaction requests; monitoring the transaction status of transaction transactions; and deleting the record of transaction transactions when the transaction status is that the transaction is completed.

[0073] In the above-mentioned embodiment of the present invention, when the total number of transactions does not exceed the preset threshold, it indicates that the transaction being executed has not reached the maximum execution number, and the current transaction request can be responded to, and then the transaction generated in response to the transaction request is recorded through the traffic time window, and the transaction status of the transaction is detected during the transaction process. After the transaction is completed, the record of the transaction is deleted to avoid interference with the statistical results by the completed transaction, thereby ensuring the accuracy of the statistical results.

[0074] The flow limiting method provided in the embodiment of the present application obtains a transaction request; takes the initiation time of the transaction request as the time starting point, and determines a statistical time window of a preset time length; determines the total number of transactions being executed in the statistical time window; and rejects the transaction request when the total number of transactions exceeds a preset threshold. The problem that the flow limiting object cannot be accurately counted in the related technology is solved; since the statistical time window delimits the transaction being executed, the flow is limited according to the transaction being executed, and the purpose of flow limiting based on the transaction processing volume TPS is achieved. Compared with the solution of limiting the flow based on the query rate per second QPS in the prior art, the flow limiting based on the transaction processing volume TPS can be more accurately limited according to the processing capacity of the transaction; and since the statistical time window in the present application is delimited according to the transaction initiation time, there is no accumulation of historical transaction transactions. Compared with the solution of adding windows in the sliding time window according to a fixed time interval used in the existing sliding time window technology, the transaction being executed can be more accurately counted, and the technical effect of accurately counting the flow limiting object is achieved.

[0075] The present invention also provides a preferred embodiment, which provides a distributed global current limiting mechanism based on an improved sliding window algorithm, that is, a current limiting mechanism based on a statistical time window.

[0076] Figure 3 is a schematic diagram of a distributed global current limiting mechanism based on an improved sliding window algorithm according to an embodiment of the present application, such as Figure 3 As shown in the figure, the aspects in the Spring framework are used to start a series of operations when the transaction enters and determine whether it exceeds the limit, and then delete the transaction record after the transaction ends.

[0077] As an optional embodiment, Figure 3 As shown, after the container for responding to transaction requests is started, the current limiting configuration is obtained and initialized, and then the ring section starts to execute to determine whether to execute current limiting. If not, the execution ends. If so, the tool class is called to execute the transaction service, and the call is stored on Redis (that is, the transaction is recorded). The total number of transactions in the statistical time window is dynamically calculated, and then it is determined whether the total number of transactions exceeds the preset threshold. If it does not exceed the preset threshold, the transaction service returns normally; if it exceeds the preset threshold, the transaction service returns and reports an error, an alarm is issued, and current limiting is performed.

[0078] Optionally, after determining to execute current limiting, the number of reconnections of the transaction service (i.e., transaction request) can be checked. If the number of reconnections of the transaction service (i.e., transaction request) exceeds the abnormal threshold, an error is reported; the number of reconnections of the transaction service (i.e., transaction request) can be stored on Redis.

[0079] Optionally, after the transaction is executed, the post-aspect is executed, the transaction service tool is called, and the call record stored in Redis is deleted (that is, the transaction is deleted).

[0080] Optionally, when a transaction enters, it is only necessary to count whether the current limit value within the current statistical time window (which can be set as the transaction timeout) exceeds the threshold. The Redis.ZremRangeByScore() and Redis.zcard() methods can be used to circle the statistical time window and calculate the total number of transactions in the window for two concurrent operations. If the concurrent threshold (i.e. the preset threshold) is exceeded, an error message of "exceeding the current limit threshold" is returned, and the transaction is rejected. At this time, an alarm mechanism can be added to prompt the operation and maintenance personnel to analyze or increase manual intervention. When the transaction is completed, the Redis.zrem() method is called to delete the transaction.

[0081] Optionally, the current limiting mechanism provided by the present invention can support current limiting in different dimensions by autonomously configuring the nodes where the current limiting mechanism takes effect. When only a single node is configured, single-point current limiting is performed, that is, only the service of a single container is subject to current limiting control, and other containers are not included in the management and control scope. When no node is configured, all nodes are subject to current limiting control by default, that is, global current limiting. In addition, current limiting control can be performed on the service calls of a single group, and current limiting control can also be performed on all groups in the "service + method" dimension. This multi-dimensional current limiting control is conducive to pilot verification work in the early stage of promotion, and is conducive to more accurate evaluation of the current limiting threshold while reducing the impact on customers.

[0082] The technical solution provided by the present invention can accurately control the entry of instantaneous traffic, avoid damage to the system caused by sudden traffic during peak trading hours, and ensure the availability of the system. At the same time, the mechanism of statistical time windows can avoid the problem that the count cannot be decreased after a single container is damaged, thereby affecting the current limiting count of other containers. More importantly, the algorithm limits the number of concurrent transactions rather than the number of requests per unit time, which is more reasonable and humane for actual business scenarios. Combined with the use of Redis, the algorithm can well perform unified traffic management from the overall processing capacity of the service cluster, and is an effective means of protecting distributed systems.

[0083] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0084] The present application also provides a current limiting device. It should be noted that the current limiting device in the present application can be used to execute the current limiting method provided in the present application. The current limiting device provided in the present application is introduced below.

[0085] Figure 4 Schematic diagram of a current limiting device according to an embodiment of the present application. Figure 4 As shown, the device includes: an acquisition module 42, used to acquire a transaction request; a first determination module 44, used to determine a statistical time window of a preset time length using the initiation time of the transaction request as a time starting point; a second determination module 46, used to determine the total number of transaction transactions being executed within the statistical time window; and a flow limiting module 48, used to reject the transaction request when the total number of transactions exceeds a preset threshold.

[0086] It should be noted that the acquisition module 42 in this embodiment can be used to execute step S102 in the embodiment of the present application, the first determination module 44 in this embodiment can be used to execute step S104 in the embodiment of the present application, the second determination module 46 in this embodiment can be used to execute step S106 in the embodiment of the present application, and the current limiting module 48 in this embodiment can be used to execute step S108 in the embodiment of the present application. The examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments.

[0087] The above-mentioned embodiment of the present invention obtains a transaction request; takes the initiation time of the transaction request as the time starting point, and determines a statistical time window of a preset time length; determines the total number of transactions being executed in the statistical time window; and rejects the transaction request when the total number of transactions exceeds a preset threshold. The problem that the current limiting object cannot be accurately counted in the related art is solved; since the statistical time window delimits the transaction being executed, the current is limited according to the transaction being executed, and the purpose of current limiting based on the transaction processing volume TPS is achieved. Compared with the current limiting solution based on the query rate per second QPS in the prior art, the current limiting based on the transaction processing volume TPS can be more accurately limited according to the processing capacity of the transaction; and since the statistical time window in the present application is delimited according to the transaction initiation time, there is no accumulation of historical transaction transactions. Compared with the solution used in the existing sliding time window technology of adding windows in the sliding time window according to fixed time intervals, the transaction being executed can be more accurately counted, and the technical effect of accurately counting the current limiting object is achieved.

[0088] Optionally, in the flow limiting device provided in the embodiment of the present application, the second determination module includes: a determination unit, used to determine the access object pointed to by the transaction request; an acquisition unit, used to acquire a time window sequence of the access object, wherein the time window sequence includes at least one traffic time window, and each traffic time window is used to record the transaction transactions being executed within a preset time period; a selection unit, used to select at least one traffic time window to be counted corresponding to the statistical time window in the time window sequence; and a statistical unit, used to count the total number of transactions in at least one traffic time window to be counted.

[0089] Optionally, in the flow limiting device provided in the embodiment of the present application, the acquisition unit includes: an identification unit, used to identify the target object that initiates the transaction request; an acquisition sub-unit, used to acquire at least one transaction transaction of the target object; an adding unit, used to add a timestamp and identification information to each transaction transaction according to the transaction time, wherein the identification information is determined based on the timestamp and the random number; a recording unit, used to record at least one transaction transaction into the corresponding traffic time window according to the timestamp; and a sorting unit, used to arrange at least one traffic time window in chronological order to obtain a time window sequence.

[0090] Optionally, in the flow limiting device provided in the embodiment of the present application, the recording unit includes: a sorting subunit, used to arrange at least one transaction transaction in chronological order according to the timestamp to obtain a transaction transaction sequence; a division subunit, used to divide the transaction transaction sequence into multiple transaction transaction sets according to a preset time period indicated by the traffic time window; and a recording subunit, used to record each transaction transaction set into the corresponding traffic time window.

[0091] Optionally, in the flow limiting device provided in the embodiment of the present application, the selection unit includes: a first determination subunit, used to determine the time start point and time end point of the statistical time window; a second determination subunit, used to determine the flow time window corresponding to the time start point as the first flow time window; a third determination subunit, used to determine the flow time window corresponding to the time end point as the second flow time window; and a fourth determination subunit, used to determine the first flow time window, the second flow time window, and the flow time window between the first flow time window and the second flow time window as the flow time window to be counted.

[0092] Optionally, in the flow limiting device provided in the embodiment of the present application, the second determination module includes: a statistical subunit, used to count the number of window transactions of transaction transactions in each traffic time window to be counted; and an accumulation subunit, used to accumulate the number of window transactions to determine the total number of transactions.

[0093] Optionally, in the current limiting device provided in the embodiment of the present application, the device also includes: an execution module, which is used to respond to a transaction request after determining the total number of transaction transactions being executed within the statistical time window, if the total number of transactions does not exceed a preset threshold; a recording module, which is used to record the transaction transactions generated in response to the transaction request; a detection module, which is used to monitor the transaction status of the transaction; and a deletion module, which is used to delete the record of the transaction when the transaction status is the end of the transaction.

[0094] The flow limiting device provided in the embodiment of the present application obtains a transaction request; takes the initiation time of the transaction request as the time starting point, and determines a statistical time window of a preset time length; determines the total number of transactions being executed in the statistical time window; and rejects the transaction request when the total number of transactions exceeds a preset threshold. The problem that the flow limiting object cannot be accurately counted in the related art is solved; since the statistical time window delimits the transaction being executed, the flow is limited according to the transaction being executed, and the purpose of flow limiting based on the transaction processing volume TPS is achieved. Compared with the solution of limiting the flow based on the query rate per second QPS in the prior art, the flow limiting based on the transaction processing volume TPS can more accurately limit the flow according to the processing capacity of the transaction; and since the statistical time window in the present application is delimited according to the transaction initiation time, there is no accumulation of historical transaction transactions. Compared with the solution of adding windows in the sliding time window according to a fixed time interval used in the existing sliding time window technology, the transaction being executed can be more accurately counted, and the technical effect of accurately counting the flow limiting object is achieved.

[0095] The current limiting device includes a processor and a memory. The detection module 42, the statistical module 44, the current limiting module 46, etc. are all stored in the memory as program units, and the processor executes the program units stored in the memory to implement corresponding functions.

[0096] The processor includes a kernel, which calls the corresponding program unit from the memory. One or more kernels can be set, and the current limiting objects can be accurately counted by adjusting the kernel parameters.

[0097] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0098] An embodiment of the present invention provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, the current limiting method is implemented.

[0099] An embodiment of the present invention provides a processor, which is used to run a program, wherein the current limiting method is executed when the program is running.

[0100] Figure 5 is a schematic diagram of an electronic device according to an embodiment of the present application, such as Figure 5As shown, an embodiment of the present invention provides an electronic device 50, which includes a processor 52, a memory 54 and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: obtaining a transaction request; taking the initiation time of the transaction request as the time starting point, determining a statistical time window of a preset time length; determining the total number of transaction transactions being executed within the statistical time window; and rejecting the transaction request when the total number of transaction transactions exceeds a preset threshold.

[0101] Optionally, the processor implements the following steps when executing the program: determining the access object pointed to by the transaction request of the transaction transaction; determining the access object pointed to by the transaction request; obtaining a time window sequence of the access object, wherein the time window sequence includes at least one traffic time window, and each traffic time window is used to record the transaction transactions being executed within a preset time period; selecting at least one traffic time window to be counted corresponding to the statistical time window in the time window sequence; and counting the total number of transactions in at least one traffic time window to be counted.

[0102] Optionally, the processor implements the following steps when executing the program: identifying the target object for initiating a transaction request; obtaining at least one transaction of the target object; adding a timestamp and identification information to each transaction according to the transaction time, wherein the identification information is determined based on the timestamp and the random number; recording at least one transaction into a corresponding traffic time window according to the timestamp; and arranging at least one traffic time window in chronological order to obtain a time window sequence.

[0103] Optionally, the processor implements the following steps when executing the program: arranging at least one transaction transaction in chronological order according to the timestamp to obtain a transaction transaction sequence; dividing the transaction transaction sequence into multiple transaction transaction sets according to a preset time period indicated by the traffic time window; and recording each transaction transaction set in the corresponding traffic time window.

[0104] Optionally, the processor implements the following steps when executing the program: determining the time start point and time end point of the statistical time window; determining the traffic time window corresponding to the time start point as the first traffic time window; determining the traffic time window corresponding to the time end point as the second traffic time window; determining the first traffic time window, the second traffic time window, and the traffic time window between the first traffic time window and the second traffic time window as the traffic time windows to be counted.

[0105] Optionally, when the processor executes the program, the following steps are implemented: counting the number of window transactions of transaction transactions in each traffic time window to be counted; accumulating the number of window transactions to determine the total number of transactions.

[0106] Optionally, the processor implements the following steps when executing the program: after determining the total number of transaction transactions being executed within the statistical time window, if the total number of transactions does not exceed a preset threshold, respond to the transaction request; record the transaction generated in response to the transaction request; monitor the transaction status of the transaction; and delete the record of the transaction when the transaction status is that the transaction is completed.

[0107] The devices in this article can be servers, PCs, PADs, mobile phones, etc.

[0108] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that initializes the following method steps: obtaining a transaction request; taking the initiation time of the transaction transaction request as the time starting point, and determining a statistical time window of a preset time length; determining the total number of transaction transactions being executed within the statistical time window; and rejecting the transaction transaction request when the total number of transaction transactions exceeds a preset threshold.

[0109] Optionally, when executed on a data processing device, it is suitable for executing a program that is initialized with the following method steps: determining the access object pointed to by the transaction request; obtaining a time window sequence of the access object, wherein the time window sequence includes at least one traffic time window, and each traffic time window is used to record the transaction transactions being executed within a preset time period; selecting at least one traffic time window to be counted corresponding to the statistical time window in the time window sequence; and counting the total number of transactions in at least one traffic time window to be counted.

[0110] Optionally, when executed on a data processing device, it is suitable for executing a program that initializes the following method steps: identifying the target object that initiates the transaction request; obtaining at least one transaction transaction of the target object; adding a timestamp and identification information to each transaction transaction according to the transaction time, wherein the identification information is determined based on the timestamp and the random number; recording at least one transaction transaction into a corresponding traffic time window according to the timestamp; and arranging at least one traffic time window in chronological order to obtain a time window sequence.

[0111] Optionally, when executed on a data processing device, it is suitable for executing an initialization program having the following method steps: arranging at least one transaction transaction in chronological order according to timestamps to obtain a transaction transaction sequence; dividing the transaction transaction sequence into multiple transaction transaction sets according to a preset time period indicated by a traffic time window; and recording each transaction transaction set in a corresponding traffic time window.

[0112] Optionally, when executed on a data processing device, it is suitable for executing an initialization program having the following method steps: determining the time start point and time end point of the statistical time window; determining the traffic time window corresponding to the time start point as the first traffic time window; determining the traffic time window corresponding to the time end point as the second traffic time window; determining the first traffic time window, the second traffic time window, and the traffic time window between the first traffic time window and the second traffic time window as the traffic time windows to be counted.

[0113] Optionally, when executed on a data processing device, it is suitable for executing a program that is initialized with the following method steps: counting the number of window transactions of transaction transactions in each traffic time window to be counted; accumulating the number of window transactions to determine the total number of transactions.

[0114] Optionally, when executed on a data processing device, the program is suitable for executing initialization having the following method steps: after determining the total number of transaction transactions being executed within a statistical time window, responding to a transaction request if the total number of transactions does not exceed a preset threshold; recording the transaction transactions generated in response to the transaction request; monitoring the transaction status of the transaction; and deleting the record of the transaction if the transaction status is that the transaction is completed.

[0115] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0116] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0117] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0118] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0119] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0120] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0121] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0122] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0123] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0124] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A current limiting method, characterized in that: include: Get transaction request; Taking the initiation time of the transaction request as the time starting point, determining a statistical time window of a preset duration; Determine the total number of transactions being executed within the statistical time window, wherein one transaction includes multiple query times, and each transaction is stored in a zset, zset = {(score1, value1), (score2, value2), ...}, each (score, value) represents a call record of each transaction, score records a millisecond timestamp, which is used to represent the timestamp of the transaction, and value records a timestamp + a random number, which is used to represent the identification information of the transaction; If the total number of transactions exceeds a preset threshold, reject the transaction request; After determining the total number of transactions being executed within the statistical time window, the method further includes: If the total number of transactions does not exceed a preset threshold, responding to the transaction request; Recording transaction transactions generated in response to the transaction request; Monitoring the transaction status of the transaction; When the transaction status is that the transaction is completed, the record of the transaction is deleted.

2. The method according to claim 1, characterized in that Determining the number of transactions being executed within the statistical time window includes: Determine the access object pointed to by the transaction request; Acquire a time window sequence of the access object, wherein the time window sequence includes at least one flow time window, and each flow time window is used to record a transaction being executed within a preset time period; Selecting at least one time window for traffic statistics corresponding to the statistical time window in the time window sequence; Count the total number of transactions in at least one traffic time window to be counted.

3. The method according to claim 2, characterized in that Acquiring the time window sequence of the access object includes: Identify a target object that initiates the transaction request; Obtain at least one transaction of the target object; Adding a timestamp and identification information to each transaction according to the transaction time, wherein the identification information is determined based on the timestamp and the random number; Recording at least one of the transaction transactions into the corresponding traffic time window according to the timestamp; Arrange at least one of the flow time windows in chronological order to obtain the time window sequence.

4. The method according to claim 3, characterized in that Recording at least one of the transaction transactions into the corresponding traffic time window according to the timestamp includes: Arrange at least one of the transaction in chronological order according to the timestamp to obtain a transaction sequence; Dividing the transaction sequence into a plurality of transaction sets according to a preset time period indicated by the traffic time window; Each of the transaction transactions is recorded in the corresponding flow time window.

5. The method according to claim 2, characterized in that: Selecting at least one time window for traffic statistics corresponding to the statistical time window in the time window sequence includes: Determine the time starting point and time ending point of the statistical time window; Determine that the flow time window corresponding to the time starting point is the first flow time window; Determine that the flow time window corresponding to the time end point is a second flow time window; The first traffic time window, the second traffic time window, and the traffic time window between the first traffic time window and the second traffic time window are determined as the traffic time windows to be counted.

6. The method according to claim 2, characterized in that Counting the number of transactions in at least one traffic time window to be counted includes: Counting the number of window transactions in each of the traffic time windows to be counted; The window transaction quantity is accumulated to determine the total transaction quantity.

7. A current limiting device, characterized in that: include: The acquisition module is used to obtain the transaction request; A first determination module, configured to determine a statistical time window of a preset duration by taking the initiation time of the transaction request as a time starting point; The second determination module is used to count the total number of transactions being executed within the statistical time window, wherein one transaction includes multiple query times, and each transaction is stored in a zset, zset = {(score1, value1), (score2, value2), ...}, each (score, value) represents a call record of each transaction, score records a millisecond timestamp, which is used to represent the timestamp of the transaction, and value records a timestamp + a random number, which is used to represent the identification information of the transaction; A flow limiting module, used for rejecting the transaction request when the total number of transactions exceeds a preset threshold; Wherein, the device further comprises: An execution module, configured to respond to the transaction request after determining the total number of transactions being executed within the statistical time window and if the total number of transactions does not exceed a preset threshold; A recording module, used to record the transaction generated in response to the transaction request; A detection module, used for monitoring the transaction status of the transaction; The deletion module is used to delete the record of the transaction when the transaction status is that the transaction is completed.

8. A processor, characterized in that: The processor is used to run a program, wherein the program executes the current limiting method described in any one of claims 1 to 6 when running.

9. An electronic device, characterized in that: It includes one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the current limiting method described in any one of claims 1 to 6.