Computing power unified access management method based on API (Application Program Interface) technology

Through real-time monitoring and machine learning to evaluate interface traffic and health status, the API gateway adaptively generates a current limiting fuse strategy, solving the problem that the API gateway is difficult to perceive the interface health status and automatically adjust the strategy in real time, and improving system stability and reliability.

CN119520187APending Publication Date: 2025-02-25CHINA SOUTHERN POWER GRID COMPANY
View PDF 0 Cites 7 Cited by

Patent Information

Application Number
CN202411466986.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-18
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

In complex and changeable business scenarios, API gateways are difficult to accurately capture the traffic pulse of each interface, perceive their health status in real time, and automatically adjust the current limiting and fuse strategy, resulting in a degradation in system performance and service availability.

Method used

By obtaining the indicator data of real-time traffic, response time and error rate of each interface, combining the historical traffic characteristics and fault tolerance requirements of the interface, data analysis and machine learning methods are used to evaluate and predict in real time, adaptively generate current limiting fuse strategies, and monitor and execute in real time in the current limiting fuse component of the API gateway.

Benefits of technology

It realizes intelligent protection of the API interface, and adaptively generates and executes current limiting and fuse strategies based on the real-time state and historical characteristics of the interface, effectively preventing the system from being impacted by burst traffic, and improving the stability and reliability of the API gateway.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119520187A_ABST
    Figure CN119520187A_ABST
Patent Text Reader

Abstract

The invention provides a computing power unified access management method based on an API technology, and the method comprises the steps: monitoring the request amount and response time of each interface in real time in a current-limiting fusing assembly of an AP I gateway, carrying out the current-limiting and fusing operation when the request amount exceeds a current-limiting threshold value, and queuing requests exceeding the threshold value again; a token generation rate and a leakage rate of a leaky bucket are dynamically adjusted according to real-time flow change of an interface by applying a self-adaptive flow limiting method, fine control and smooth processing are performed on flow, and impact of burst flow on a system is avoided; the flow, response time and error rate of each interface are monitored in real time, different AP I gateway interfaces are integrated, a flow-limiting fusing model is established, a random forest method is applied, historical data are trained and learned by the model, and a flow-limiting threshold value and a fusing rule are autonomously optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information technology, and in particular to a computing power unified access management method based on API technology. Background Art

[0002] In complex and ever-changing business scenarios, API gateways bear the responsibility of managing massive interfaces and services, and are also responsible for dealing with various traffic shocks and failures. When the number of requests for a certain interface suddenly soars, the performance of the entire system will decline, and even trigger a chain reaction, affecting the availability of other services. The traffic characteristics of different interfaces vary greatly, and the fault tolerance requirements are different. How to accurately capture the pulse of each interface from the vast ocean of interfaces, perceive its health status in real time, and then automatically adjust the current limiting and fuse strategy is a technical problem that needs to be overcome. The API gateway needs to be able to deeply analyze the historical traffic, response time, error rate and other indicators of each interface. This algorithm must not only be efficient and accurate, but also have adaptive capabilities. It can dynamically adjust thresholds and rules according to changes in real-time traffic to avoid being too strict and causing false positives, or being too loose and losing protection. How to implement this efficient, accurate, and adaptive current limiting and fuse mechanism in massive interfaces tests the wisdom and ability of the API gateway. Summary of the invention

[0003] The present invention provides a computing power unified access management method based on API technology, which mainly includes:

[0004] Obtain the real-time traffic, response time, and error rate indicator data of each interface. Combined with the historical traffic characteristics and fault tolerance requirements of the interface, use data analysis and machine learning methods to conduct real-time evaluation and prediction of the health status of each interface to obtain the evaluation results.

[0005] Based on the health status assessment results of the interface, adaptively generate current limiting and fusing strategies. Combined with the traffic characteristics and fault tolerance requirements of different interfaces, dynamically set current limiting thresholds and fusing rules. Send the strategies to the current limiting and fusing components of the API gateway through the strategy management module.

[0006] In the API gateway's current limiting and fuse components, the request volume and response time of each interface are monitored in real time. When the request volume exceeds the current limiting threshold, current limiting and fuse operations are performed, and requests exceeding the threshold are re-queued;

[0007] Adopting the adaptive current limiting method, the token generation rate and the leakage rate of the leaky bucket are dynamically adjusted according to the real-time traffic changes of the interface, and the traffic is finely controlled and smoothed to avoid the impact of sudden traffic on the system.

[0008] Set the state transition rules of the fuse. When the error rate and response time of the interface exceed the set threshold, the fuse changes from the closed state to the open state, quickly rejecting requests. When the interface returns to normal, the fuse gradually changes from the open state to the half-open state, allowing some requests to pass and monitoring their execution. If the request is successful, the fuse returns to the closed state, otherwise it remains open.

[0009] Monitor the traffic, response time and error rate of each interface in real time, integrate different API gateway interfaces, establish a current limiting and circuit breaking model, use the random forest method to train and learn the model on historical data, and autonomously optimize the current limiting threshold and circuit breaking rules.

[0010] The technical solution provided by the embodiment of the present invention may have the following beneficial effects:

[0011] The present invention discloses a unified access management method based on computing power and API management technology. The method uses a machine learning method to evaluate and predict the health status of the interface by real-time monitoring of interface traffic, response time and error rate, combined with historical data characteristics. Based on the evaluation results, a decision tree algorithm is used to score the health status of the interface, and a current limiting and fuse strategy is adaptively generated. At the execution level, the present invention combines token bucket and leaky bucket algorithms to achieve refined flow control, and sets fuse state transfer rules for rapid fuse and recovery. Through continuous training and optimization of the random forest model, the current limiting threshold and fuse rules can be adjusted autonomously to achieve intelligent protection of the API interface. The technical effect of the present invention is that it can adaptively generate and execute current limiting and fuse strategies according to the real-time status and historical characteristics of the interface, effectively prevent the system from being impacted by burst traffic, and improve the stability and reliability of the API gateway. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 The present invention is a flowchart of a method for unified access management of computing power based on API technology.

[0013] Figure 2 It is a schematic diagram of a computing power unified access management method based on API technology of the present invention.

[0014] Figure 3 This is another schematic diagram of a unified computing power access management method based on API technology of the present invention. DETAILED DESCRIPTION

[0015] In order to further understand the content of the present invention, the present invention is described in detail in conjunction with the accompanying drawings and embodiments. The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are only used to explain the relevant inventions, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the invention are shown in the accompanying drawings.

[0016] like Figure 1-3 In this embodiment, a computing power unified access management method based on API technology may specifically include:

[0017] Step S101, obtain the indicator data of real-time traffic, response time and error rate of each interface, combine the historical traffic characteristics and fault tolerance requirements of the interface, use data analysis and machine learning methods to perform real-time evaluation and prediction of the health status of each interface to obtain the evaluation results.

[0018] The number of requests, average response time and number of errors of each interface collected by the monitoring system every 10 seconds is obtained, and the real-time traffic, average response time and error rate indicators of the interface are calculated based on the above. According to the real-time traffic indicators and the historical traffic data of each interface in the past 30 days read from the database, the peak and valley distribution and periodic pattern of the historical traffic data are identified by time series analysis method, and the traffic feature archive of the interface is constructed. For each interface, the real-time indicators are compared and analyzed with the historical data of the same period in the traffic feature archive, and the real-time indicators for the next 24 hours are predicted by the ARIMA model. If the real-time indicators exceed the preset fault tolerance threshold, they are marked as potential abnormalities. For the interfaces marked as potential abnormalities, a health status classification model is established by using the random forest algorithm, and the input features of the health status classification model include the real-time indicators of the interface, the historical data features in the traffic feature archive and the preset fault tolerance threshold. According to the classification results of the health status classification model, combined with the change trend of the real-time indicators and the predicted value of the ARIMA model, an evaluation report is generated for the health status of each abnormal interface, and the evaluation report includes the current status of the interface, the cause analysis of the abnormality and the performance prediction for the next 24 hours.

[0019] Specifically, the number of requests, average response time, and number of errors per 10 seconds of each interface are obtained from the monitoring system, and the real-time traffic, average response time, and error rate indicators are calculated. At the same time, the historical traffic data of each interface in the past 30 days and the preset fault tolerance threshold are read from the database. Time series analysis is performed on the historical traffic data to identify features such as peak and valley distribution and periodic patterns, and the traffic feature archive of the interface is constructed. The real-time indicators of each interface are compared and analyzed with the historical data of the same period, and the ARIMA model is used to predict the traffic, response time, and error rate in the next 24 hours. The real-time indicators are compared with the preset fault tolerance threshold, and those exceeding the threshold are marked as potential anomalies. Based on the comprehensive comparison of real-time indicators, prediction results, and fault tolerance thresholds, a preliminary assessment is made on the current health status of the interface. For interfaces with abnormal preliminary assessment results, a health status classification model is established using the random forest algorithm. A training set is constructed using historical data, including known normal and abnormal state samples. The input features include multi-dimensional data such as the real-time indicators of the interface, historical data features, and fault tolerance requirements. The model is updated every day with newly collected data to ensure the accuracy and adaptability of the model. A more accurate classification judgment is made on the health status of abnormal interfaces. According to the classification results of the random forest model, combined with the change trend and predicted value of each indicator, a detailed evaluation report is given for the health status of each abnormal interface. The feature importance analysis method of the decision tree is used to identify the main factors causing the abnormality. The evaluation report contains the current status of the interface, the analysis of the cause of the abnormality, and the performance forecast for the next 24 hours. For normal interfaces, the changes in their indicators are continuously monitored, and warning information is issued when they are close to the preset threshold. The monitoring system collects interface data every 10 seconds. For example, if an interface receives 100 requests within 10 seconds, the average response time is 50 milliseconds, and the number of errors is 2 times, the real-time traffic is calculated to be 600 times / minute, the average response time is 50 milliseconds, and the error rate is 2%. At the same time, the historical data of the interface in the past 30 days is read. For example, the traffic is higher from 9:00 to 18:00 on weekdays, averaging 500 times / minute, and the traffic is lower on weekends, averaging 200 times / minute. The preset fault tolerance threshold is that the traffic fluctuation does not exceed 20%, the response time does not exceed 100 milliseconds, and the error rate does not exceed 5%. The historical data is analyzed in time series to identify the traffic difference pattern between weekdays and weekends, and to build an interface traffic feature archive. The ARIMA model is used to predict the indicators for the next 24 hours. For example, the average traffic from 9:00 to 18:00 on the next working day is predicted to be 550 times / minute, the response time is 60 milliseconds, and the error rate is 3%. The real-time indicators are compared with the preset thresholds, and if they exceed the thresholds, they are marked as potential anomalies. For example, the current traffic of 600 times / minute exceeds the historical average of 500 times / minute by 20%, which is marked as a potential anomaly. Taking into account the real-time indicators, prediction results, and fault tolerance thresholds, a preliminary assessment of the health status of the interface is performed. For interfaces that are initially assessed as abnormal, a health status classification model is established using the random forest algorithm.The training set contains 1,000 known normal state samples and 200 abnormal state samples, each of which contains 15 features, such as real-time traffic, response time, error rate, historical average, peak value, etc. The model uses 100 decision trees with a maximum depth of 10 and a minimum number of leaf node samples of 5. The model is updated with newly collected data every day to maintain the accuracy of the model. The health status of abnormal interfaces is classified more accurately and the abnormal probability is output. A detailed evaluation report is generated based on the classification results of the random forest model. The feature importance analysis method of the decision tree is used to identify the main factors causing the abnormality. For example, the analysis results show that the sudden increase in traffic contributes 60% of the abnormal probability, the increase in response time contributes 30%, and the increase in error rate contributes 10%. The evaluation report contains the current status of the interface, such as severe abnormalities, abnormal cause analysis, such as the sudden increase in traffic causing excessive server load, and performance forecasts for the next 24 hours, such as the expected traffic will return to normal after 3 hours. For normal interfaces, when the indicator approaches 80% of the preset threshold, such as the traffic reaches 480 times / minute, an early warning message is automatically issued.

[0020] Step S102, based on the health status assessment results of the interface, adaptively generate a current limiting and fuse strategy, dynamically set the current limiting threshold and fuse rules in combination with the traffic characteristics and fault tolerance requirements of different interfaces, and send the strategy to the current limiting and fuse components of the API gateway through the policy management module.

[0021] Acquire real-time health status data sent by the health status assessment module, wherein the real-time health status data includes interface identifier, current traffic, response time, error rate and health status score; generate a current limiting and fuse strategy using a random forest algorithm based on the real-time health status data, traffic feature description and fault tolerance requirements, wherein the random forest algorithm uses historical traffic characteristics, fault tolerance requirements and current health status as input features; convert the current limiting and fuse strategy into a standard policy description file in JSON format through a policy management module, wherein the standard policy description file includes interface identifier, current limiting threshold, fuse condition, recovery time and policy version number; push the standard policy description file to the configuration center of the API gateway, wherein the configuration center is used to store the latest policy description file; pull the latest policy description file from the configuration center, parse the JSON content of the policy description file and dynamically update the current limiting counter and fuse state machine in the memory, wherein the current limiting counter uses a sliding window algorithm to record the number of requests in each time window, and the fuse state machine includes three states: closed, half-open and open.

[0022] Specifically, the real-time health status data of each interface is obtained from the health status assessment module, including interface identification, current traffic, response time, error rate and health status score, and the historical traffic characteristics and preset fault tolerance requirements of each interface are read from the database. According to the historical traffic characteristics, the average traffic, peak traffic and fluctuation range of the past 7 days are calculated to obtain the traffic characteristic description of each interface. According to the interface health status data, traffic characteristic description and fault tolerance requirements, the random forest algorithm is used to generate the current limiting and fuse strategy. The historical traffic characteristics, fault tolerance requirements and current health status are used as input features to train the random forest model to predict the appropriate current limiting threshold and fuse rules. The current limiting threshold is dynamically set according to the prediction results, and the fuse rule includes the trigger condition and recovery time. After the strategy is generated, the historical data is used to simulate the effect of applying the new strategy. If the effect is not good, the random forest model parameters are adjusted to regenerate the strategy. The generated current limiting and fuse strategy is converted into a standard policy description file in JSON format through the policy management module, which includes the interface identification, current limiting threshold, fuse condition, recovery time and policy version number. The policy management module re-evaluates and generates the strategy every 5 minutes to ensure the dynamic and adaptive nature of the strategy. Push the latest policy description file to the configuration center of the API gateway to dynamically update the policy. The current limiting and fuse components of the API gateway pull the latest policy description file from the configuration center, parse the JSON content, and dynamically update the current limiting counter and fuse state machine in the memory. The current limiting counter uses a sliding window algorithm to record the number of requests in each time window. The fuse state machine contains three states: closed, half-open, and open, and the state transition is performed according to the fuse condition and recovery time. Through these mechanisms, precise control and dynamic protection of interface requests are achieved. The health status assessment module obtains interface data from the monitoring system every minute. For example, the current flow of interface A is 1000 times / minute, the average response time is 80 milliseconds, the error rate is 1.5%, and the health score is 85 points. At the same time, the historical data of interface A is read, and the average flow in the past 7 days is calculated to be 800 times / minute, the peak flow is 1500 times / minute, and the fluctuation range is 500-1200 times / minute. The preset fault tolerance requirements are the maximum allowed flow of 1800 times / minute, the maximum response time is 200 milliseconds, and the maximum error rate is 5%. The random forest algorithm uses this data as input features to train 100 decision trees, with a maximum depth of 10 for each tree. The model output recommends a current limiting threshold of 1200 times / minute, and a fuse rule of an average response time of more than 150 milliseconds or an error rate of more than 3% for 30 consecutive seconds. The policy management module uses historical data from the past 24 hours to simulate the application of a new policy and finds that it can reduce overload by 50%, so the policy is adopted. The policy is converted to JSON format, containing the following fields:

[0023] {"interfaceId":"A","limitThreshold":1200,"circuitBreakerCondition":{"avgResponseTime":150,"errorRate":3},"recoveryTime":60,"version":10}. After receiving the new policy, the API Gateway's current limiting circuit breaker component updates the sliding window counter in memory, sets the window size to 1 minute, and updates once per second. The circuit breaker state machine is initially in the closed state, and turns to the open state when the circuit breaker condition is triggered. After 60 seconds, it turns to the semi-open state, allowing a small number of requests to pass. If these requests are successful, it returns to the closed state, otherwise it re-enters the open state. Through this dynamic adjustment and precise control, adaptive protection of the interface is achieved.

[0024] According to the health status of the interface, the decision tree method is used to score the health status of each interface. If the score is higher than the preset threshold of the interface current limiting, the fuse is triggered; if the score is lower than the preset threshold of the interface current limiting, the fuse is stopped. The generated current limiting threshold and fuse rules are encapsulated into a policy object. If the policy object has a large amount of data and the delivery time is longer than the preset time, the API gateway current limiting fuse component will periodically select the latest policy configuration from the database.

[0025] Acquire the real-time data of the interface of the health status monitoring module and the historical data of the past seven days, wherein the real-time data of the interface includes the request volume, response time and error rate; construct a health status assessment model based on the real-time data and historical data of the interface using a decision tree algorithm, select the request volume, response time and error rate as features, and the health status as a label; perform quantitative scoring on the health status of the interface through the health status assessment model to obtain an interface score; compare the interface score with a preset current limiting threshold, and if the interface score is higher than the current limiting threshold, generate a fuse trigger instruction; if the interface score is lower than the current limiting threshold, generate a stop fuse instruction; and The difference in flow thresholds is used to dynamically adjust the flow limiting threshold in proportion to obtain a new flow limiting threshold; the new flow limiting threshold, fuse rules, and trigger instructions are encapsulated into a policy object; the data volume of the policy object after serialization is calculated, and if the data volume exceeds the preset network transmission threshold, the policy object is stored in the database; if the data volume does not exceed the network transmission threshold, the policy object is sent to the API gateway through the network; the flow limiting and fuse components of the API gateway trigger tasks through timers, read the latest policy configuration from the database, and if the version number of the latest policy configuration is greater than the locally cached policy version number, update the locally cached policy configuration.

[0026] Specifically, the real-time data of the interface is obtained from the health status monitoring module, including the request volume, response time, and error rate, and the historical data of the past 7 days is read at the same time. The decision tree algorithm is used to build a health status assessment model, and the request volume, response time, and error rate are selected as features, and the health status is used as a label. The information gain ratio is used to select the best split feature, and the maximum depth of the tree is set to 5 layers. The interface health status is quantitatively scored through the trained decision tree model to obtain a score of 0-100. The interface score is compared with the preset current limiting threshold. If the interface score is higher than the threshold, a fuse trigger instruction is generated; if the interface score is lower than the threshold, a stop fuse instruction is generated. According to the difference between the current score and the preset threshold, the current limiting threshold is dynamically adjusted in proportion, and the adjustment range does not exceed 10% of the original threshold. The specific adjustment formula is: new threshold = original threshold * (1 + (current score - preset threshold) / preset threshold * 0.1). The generated current limiting threshold, fuse rule, trigger instruction, and adjusted threshold are encapsulated into a policy object. The data volume after serialization of the policy object is calculated, and the network transmission threshold is set to 100KB. If the data volume exceeds the network transmission threshold, the policy object is stored in the database, and the storage timestamp and version number are recorded. If the data volume does not exceed the threshold, the policy object is directly sent to the API gateway through the network. The current limiting and fuse component of the API gateway triggers a task every 30 seconds through a timer to read the latest policy configuration from the database. When reading, the policy version number of the local cache is compared with the version number in the database. If the database version number is updated, the new policy is read and the local cache is updated. If the version number is the same, the current cache is kept unchanged. Through this mechanism, large-scale policies can be quickly applied to avoid affecting real-time performance due to long policy delivery time. The health status monitoring module obtains real-time data from interface A every minute, such as the current request volume of 1000 times / minute, the average response time of 80 milliseconds, and the error rate of 1.5%. At the same time, historical data for the past 7 days is read, totaling 10080 records. The decision tree algorithm uses this data to build a health status assessment model, taking the request volume, response time and error rate as features, and the health status, including normal / abnormal, as a label. Through the information gain ratio calculation, the error rate is selected as the split feature of the root node, and the threshold is 2%. The maximum depth of the tree is set to 5 layers, and the final decision tree contains 31 nodes. The current status of interface A is scored and 85 points are obtained, with a full score of 100 points. The score of 85 is compared with the preset current limiting threshold of 80 points to determine that interface A needs to trigger a fuse. The current limiting threshold is dynamically adjusted, and the new threshold = 80*(1+(85-80) / 80*0.1) = 82 points. The current limiting threshold of 82 points, the fuse rule, such as triggering a fuse when the score is higher than the threshold for 3 consecutive minutes, the fuse trigger instruction, and the adjusted threshold are encapsulated into a policy object.The serialized policy object size is 150KB, which exceeds the network transmission threshold of 100KB, so the policy object is stored in the database, and the storage time is recorded as 2024-03-15, 14:30:00, and the version number is 10. The current limiting and fuse component of the API gateway triggers a scheduled task at 14:30:30, reads the latest policy from the database, and finds that version number 10 is higher than version 09 in the local cache, updates the local cache, and applies the new current limiting and fuse policy.

[0027] Step S103, in the current limiting and fuse component of the API gateway, the request volume and response time of each interface are monitored in real time. When the request volume exceeds the current limiting threshold, current limiting and fuse operations are performed, and requests exceeding the threshold are re-queued.

[0028] Receive request information carrying an interface identifier, wherein the request information is sent by an API caller; use a sliding time window algorithm to count the number of requests and the average response time of the interface in real time according to the request information, wherein the sliding time window algorithm uses a ring buffer to store the number of requests per second and the sum of the response time; determine whether the request volume exceeds a preset current limiting threshold, and if the request volume exceeds the current limiting threshold, trigger a current limiting operation; obtain requests that exceed the current limiting threshold, and put the requests that exceed the current limiting threshold into a priority queue for queue processing, wherein the priority queue calculates a priority score based on the importance and waiting time of the request; start a fuse timer to record the fuse start time, and if the current limiting is continuously triggered or the response time exceeds the limit within a preset time window, perform a fuse operation; take out the highest priority request from the priority queue for processing, monitor the response time of the request, and determine whether the response time is lower than the preset threshold, and if the average response time of the request group taken out for multiple consecutive times is lower than the preset threshold, release the fuse state.

[0029] Specifically, the API gateway's current limiting and fuse component identifies each interface through the interface identifier, and uses a sliding time window algorithm to count the number of requests and the average response time of the interface in real time. The algorithm uses a ring buffer to store the number of requests per second and the sum of the response time. The buffer size is set to 60, corresponding to a 1-minute time window. It is updated once a second, and the sum of the latest 60 data points is calculated to obtain the request volume, and the sum of the response time is divided by the request volume to obtain the average response time. According to the pre-set current limiting threshold, it is determined whether the current request volume exceeds the threshold. If it exceeds the threshold, the current limiting operation is triggered. After the current limiting is triggered, the requests exceeding the threshold are placed in the priority queue for queue processing. The priority queue calculates the priority score based on the importance and waiting time of the request. The score calculation formula is: priority score = request importance * 0.7 + waiting time * 0.3. Requests with high scores are processed first. At the same time, the average response time is monitored. If it exceeds the preset threshold, such as 200 milliseconds, the fuse operation is also triggered. After the current limiting or response time exceeds the limit, the fuse timer is started and the fuse start time is recorded. If the current limit is continuously triggered or the response time exceeds the limit within the preset time window, such as 5 minutes, the circuit breaker operation is performed and new requests are suspended. During the circuit breaker period, an error response is directly returned to the newly received request, and a maximum waiting time is set for the queued request. Requests that exceed the maximum waiting time, such as 60 seconds, also return an error response. During the circuit breaker period, 5 requests with the highest priority are taken out from the priority queue every 30 seconds for processing, and the response time of these requests is monitored. If the average response time of the request group taken out for 3 consecutive times is lower than the threshold, the circuit breaker state is released and normal request processing is resumed. After returning to normal, the number of processed requests is gradually increased by 10% per minute until the current limit threshold is reached or the queue is cleared. The current limit circuit breaker component of the API gateway monitors the interface "user_login" and uses a ring buffer of size 60 to implement a sliding time window. It is updated once a second. If 100 requests are received in the last second and the total response time is 8000 milliseconds, (100,8000) is recorded in the buffer. By calculating the latest 60 data points, we know that the current request volume is 5000 times / minute and the average response time is 80 milliseconds. Assuming that the preset current limiting threshold is 4000 times / minute and the response time threshold is 200 milliseconds, the current limiting operation is triggered at this time. The 1000 requests that exceed the threshold are put into the priority queue, and there are already 500 requests in the queue. For the newly queued request, assuming the importance is 0.8, the full score is 1, and the waiting time is 0 seconds, the priority score is 0.8*0.7+0*0.3=0.56. The request with the longest waiting time in the queue has waited for 50 seconds, and its score is 0.6*0.7+50*0.3=0.42+15=15.42, which is processed first. Start the fuse timer and record the current time as 10:00:00. In the next 5 minutes, the system continues to trigger the current limiting, and the fuse operation is performed at 10:05:00.During the circuit breaker period, 5 highest priority requests are taken out of the queue for processing every 30 seconds. For example, 5 requests are processed at 10:05:30, and the average response time is 150 milliseconds.

[0030] At 10:06:00, another 5 were processed with an average response time of 100 milliseconds; at 10:06:30, another 5 were processed with an average response time of 90 milliseconds. The average response time was below the 200 millisecond threshold for three consecutive times, and the system was released from the fuse state at 10:07:00 and resumed normal processing. The initial processing volume was set to 3000 times / minute, increasing by 10% every minute until it reached the current limit threshold of 4000 times / minute or the queue was cleared.

[0031] The token bucket method is used to implement the current limiting function. The number of tokens in the token bucket represents the number of requests allowed to pass. When a request arrives, it is determined whether there are enough tokens in the token bucket. If there are, the request is passed and the corresponding tokens are consumed. If not, the current limiting measures are triggered. At the same time, the leaky bucket algorithm is combined to implement traffic shaping, and sudden large traffic requests are handled at a uniform speed.

[0032] According to the historical request volume statistics, the token bucket capacity and token generation rate are dynamically calculated; the token generation rate is used to determine the number of tokens added to the token bucket per second. A high priority request queue and a normal priority request queue are created; the high priority request queue and the normal priority request queue have a fixed size. A preset number of tokens are added to the token bucket using atomic operations; if the number of tokens in the token bucket reaches the upper capacity limit, the addition is stopped. When receiving a request, the priority of the request is determined; according to the priority of the request, the number of tokens in the token bucket of the corresponding priority is checked. If the number of tokens in the token bucket is greater than or equal to 1, a token is atomically taken out of the token bucket; if the number of tokens in the token bucket is 0, the request is placed in the request queue of the corresponding priority. A separate processing thread is used to take out a request from the high priority request queue or the normal priority request queue for processing; the processing thread preferentially takes out a request from the high priority request queue for processing.

[0033] Specifically, the token bucket is initialized, and the exponential moving average algorithm is used to dynamically calculate the bucket capacity and token generation rate based on historical request statistics. Two fixed-size request queues are created, one for high-priority and one for normal-priority requests, to achieve differentiated processing. Read-write locks are used to protect concurrent access to the token bucket and request queue to ensure thread safety. Atomic operations are used to implement the token generation process, adding a preset number of tokens to the token bucket per second. If the number of tokens in the bucket reaches the upper limit of capacity, the addition is stopped. The token generation function is triggered by a timer to execute the process to ensure correctness in concurrent situations. When a request arrives, the request priority is first determined, and then the number of tokens in the token bucket of the corresponding priority is checked. If the number of tokens is greater than or equal to 1, a token is atomically taken out of the bucket to allow the request to pass; if the number of tokens is 0, the request is placed in the request queue of the corresponding priority to wait for processing. After the request is placed in the queue, the wake-up operation of the processing thread is immediately triggered to ensure timely processing of queued requests. A separate processing thread is used to control the processing frequency through the token bucket algorithm to ensure the stability of the processing rate. The processing thread preferentially takes out requests from the high-priority queue for processing, and processes requests in the normal-priority queue if the high-priority queue is empty. If both queues are empty, the processing thread enters a waiting state until it is awakened by a new request. Monitor the system load in real time, dynamically adjust the token generation rate and request processing rate according to the load level, and implement adaptive flow control. When the system is initialized, by analyzing the request logs of the past 24 hours, the average request rate is calculated to be 1000 times / minute and the peak request rate is 3000 times / minute. Using the exponential moving average algorithm, the weight factor is set to 0.2, and the estimated request rate is calculated to be 1400 times / minute. Based on this, the token bucket capacity is set to 2800, which is twice the estimated request rate, and the token generation rate is 23 per second (1400 / 60). Create a high-priority request queue with a capacity of 500 and a normal-priority request queue with a capacity of 1000. Use read-write locks to protect these resources, set the maximum number of concurrent read threads to 16, and the number of write threads to 1. Trigger the token generation function every 100 milliseconds, and add 2 tokens to the token bucket through atomic operations, 23 / 10, rounded down. When a high-priority request arrives, if the current token number is 2630, the token number is atomically reduced by 1 and the request is passed directly; if the token number is 0, the request is placed in the high-priority queue and the processing thread is immediately awakened. The processing thread is awakened every 50 milliseconds, 1000 /

[0034] (1400 / 60), try to process a request, and check the high priority queue first. If the high priority queue is empty, process the request in the normal priority queue. If both queues are empty, the processing thread enters a waiting state of up to 100 milliseconds. The system calculates the average load every 5 minutes. If the load exceeds 80%, the token generation rate and processing rate will be reduced by 10% at the same time. Otherwise, they will be increased by 10%, but not more than 150% of the initial setting value.

[0035] Step S104, using an adaptive current limiting method, dynamically adjusts the token generation rate and the leakage rate of the leaky bucket according to the real-time traffic changes of the interface, performs refined control and smoothing of the traffic, and avoids the impact of sudden traffic on the system.

[0036] A sliding time window algorithm is used to monitor interface traffic in real time. The sliding time window algorithm uses a circular buffer to store the number of requests per second and the average response time. According to the traffic status monitored by the sliding time window algorithm, an exponentially weighted moving average algorithm is used to calculate the expected traffic, and the exponentially weighted moving average algorithm obtains the new expected traffic. The new expected traffic is set as the benchmark value of the token generation rate and the leaky bucket leakage rate, and the benchmark value is adjusted according to the CPU utilization and memory occupancy. If the deviation between the actual traffic and the expected traffic exceeds the preset threshold and meets the cooling period requirements, the dynamic adjustment mechanism is triggered, and the dynamic adjustment mechanism updates the relevant parameters of the token bucket and the leaky bucket. According to the parameters updated by the dynamic adjustment mechanism, the system processing capacity is recalculated, and the system processing capacity is used to adjust the request queue size.

[0037] Specifically, a sliding time window algorithm is used to monitor interface traffic in real time. The window size is set to 1 minute, and a ring buffer is used to store the number of requests per second and the average response time. It is updated once a second, only the latest data point is updated, and the data of the previous 59 seconds is retained to calculate the current traffic status. Independent ring buffers are set for monitoring requests of different priorities. According to the monitored traffic status, the expected traffic is calculated using the exponentially weighted moving average algorithm. The specific calculation process is: new expected traffic = current actual traffic * 0.2 + old expected traffic * 0.8. The calculation result is used as the benchmark value of the token generation rate and the leaky bucket leakage rate, and the rates of high priority and normal priority are set respectively. At the same time, the CPU usage and memory occupancy are monitored. When the resource usage exceeds 80%, the benchmark value is multiplied by (1-resource usage) as the actual setting value. Set a dynamic adjustment threshold and a cooling period mechanism. When the deviation between the actual traffic and the expected traffic exceeds 20%, and the time from the last adjustment exceeds 30 seconds, the adjustment mechanism is triggered. The token generation rate and leaky bucket leakage rate are adjusted synchronously, with an adjustment range of 50% of the deviation value, and the upper and lower limits are 150% and 50% of the baseline value respectively. The current timestamp is recorded during adjustment for cooling-off period judgment. A dynamic adjustment check is performed every 5 seconds. If the adjustment mechanism is triggered, atomic operations are used to update the relevant parameters of the token bucket and leaky bucket, including bucket capacity, generation rate, and leakage rate. During the update process, the new parameters are first written to temporary variables, and then atomic comparison and exchange operations are performed to ensure the consistency of the parameter update. After the update is completed, the system processing capacity is recalculated, and the request queue size is adjusted appropriately to achieve adaptive control and smooth processing of traffic. In interface traffic monitoring, the system creates a circular buffer of size 60 for high-priority and normal-priority requests respectively. Taking high-priority requests as an example, the current number of requests per second in 1 minute is

[0038] [95,100,105,...,98], the average response time is [50ms,55ms,52ms,...,48ms]. The latest data point is updated every second, and the current high priority traffic is calculated to be 6000 requests / minute, with an average response time of 51ms. Using the exponentially weighted moving average algorithm, assuming that the last expected traffic was 5500 requests / minute, the new expected traffic = 6000*0.2+5500*0.8=5600 requests / minute. Set 5600 as the benchmark value for the high priority token generation rate and the leaky bucket leakage rate. At the same time, the CPU usage is monitored to be 75%, and the memory usage is 70%, which does not exceed the 80% threshold, so the benchmark value remains unchanged. The system records that the last adjustment time was 30 seconds ago. The deviation between the current actual traffic of 6000 and the expected traffic of 5600 is 7.14%, which does not exceed the 20% threshold and does not trigger the adjustment mechanism. After checking again 5 seconds later, it was found that the actual traffic suddenly increased to 7000, with a deviation of 25%, and it had been more than 30 seconds since the last adjustment, triggering the adjustment mechanism. The adjustment range is (7000-5600)*50%=700, and the new token generation rate and leaky bucket leakage rate are set to 6300, which does not exceed the 150% upper limit of the baseline value of 5600. The system uses atomic operations to update the token bucket capacity to 12600, 2 times the rate, and the generation rate and leakage rate are both 6300. After the update is completed, the system recalculates the processing capacity and adjusts the request queue size from the original 1000 to 1200, completing an adaptive control and smoothing process.

[0039] Step S105, set the state transfer rule of the fuse. When the error rate and response time of the interface exceed the set threshold, the fuse transfers from the closed state to the open state, and quickly rejects the request; when the interface returns to normal, the fuse gradually transfers from the open state to the half-open state, allowing some requests to pass and monitoring their execution. If the request is successful, the fuse returns to the closed state, otherwise it continues to remain in the open state.

[0040] Receive real-time request data from a service interface, and process the real-time request data using a sliding time window algorithm; calculate the current error rate and average response time according to the sliding time window algorithm, wherein the error rate includes network timeout errors and business logic errors; determine whether the error rate exceeds a preset threshold, and if the error rate exceeds the preset threshold, record the time for which the error rate exceeds the threshold continuously; set a fuse state according to the time for which the error rate exceeds the threshold continuously, and if the time for which the error rate exceeds the threshold continuously reaches a predetermined value, set the fuse state to open; when the fuse state is open, start a timer and use a polling mechanism to select some requests to pass; monitor the requests that pass, and obtain the success rate and average response time of the requests that pass; determine whether to restore the fuse state to closed according to the success rate and average response time, and if the success rate exceeds the preset success rate threshold and the average response time is lower than the preset response time threshold, restore the fuse state to closed.

[0041] Specifically, the error rate and response time of the interface are monitored in real time. The sliding time window algorithm is used to use a ring buffer of size 60 to store the total number of requests, errors and response time per second. It is updated once a second, only the latest data point is updated, and the data of the first 59 seconds is retained. The current error rate and average response time are calculated, and the network timeout error and business logic error are distinguished, and the weights of 0.7 and 0.3 are assigned respectively. It is determined whether the weighted error rate exceeds the preset threshold of 5% or whether the average response time exceeds 200 milliseconds. According to the monitoring results, the fuse state transition rules are set. A counter is used to record the number of seconds that exceed the threshold continuously. When the counter reaches 30, the fuse state is changed from closed to open. In the open state, all requests are quickly rejected and the preset error response is returned. At the same time, the system resource usage is monitored. When the CPU usage or memory usage exceeds 80%, the error rate threshold and response time threshold are adjusted to 4% and 180 milliseconds respectively. After the fuse is turned on, the timer is started and the state is tried to be turned to half-open every 30 seconds. Use the polling mechanism to select 10% of the requests to pass, focus on monitoring these requests, and record their success rate and average response time. The remaining 90% of the requests are temporarily stored in a buffer queue with a capacity of 1000. If the queue is full, they are quickly rejected. In the half-open state, continuously monitor the requests that are allowed to pass. Set a sliding window of size 10 and record the results of the last 10 requests. If the success rate of the requests in the window exceeds 95% and the average response time is less than 150 milliseconds, the fuse state is restored to closed and the requests in the buffer queue are cleared. If the conditions are not met, keep the open state and wait for the next attempt. During the judgment period, continue to use the polling mechanism to process newly arrived requests to ensure that the system continues to run. During the interface monitoring process, the system uses a ring buffer of size 60 to record data per second. Assume that 100 requests are received in the last second, of which 5 are errors, 3 network timeouts, 2 business logic errors, and the total response time is 8000 milliseconds. The system updates the latest data point to [100,5,8000], and calculates that the current error rate is 5%, the weighted error rate is 0.73%+0.32%=2.7%, and the average response time is 80 milliseconds. Since the weighted error rate does not exceed the 5% threshold and the response time does not exceed 200 milliseconds, the fuse remains closed. At this time, the CPU usage is 85%, triggering dynamic adjustment, and the error rate threshold is adjusted to 4%. After 30 seconds of continuous monitoring, the weighted error rate of a certain second reaches 4.5%, exceeding the new threshold, and the counter starts counting. After 29 seconds, the counter reaches 30, the fuse turns to the open state and begins to reject requests. After 30 seconds, the fuse tries to turn to the half-open state, using the polling mechanism to select 10% of the requests to pass. Assume that 50 requests arrive at this time, 5 are allowed to be processed, and 45 enter the buffer queue. Focus on monitoring these 5 requests and record them in a sliding window of size 10.If 9 out of the 10 requests are successful, the average response time is 140 milliseconds, and the recovery condition is met, the fuse state returns to closed. The system then clears the requests in the buffer queue and resumes normal processing.

[0042] Step S106: monitor the traffic, response time and error rate of each interface in real time, integrate different API gateway interfaces, and establish a current limiting and fuse model. Use the random forest method to train and learn the model on historical data, and autonomously optimize the current limiting threshold and fuse rules.

[0043] A sliding time window algorithm is used to monitor the flow, response time and error rate of each interface in real time. The sliding time window size is set to five minutes and updated every ten seconds. The number of requests, average response time and number of errors in the current time window are obtained based on the monitoring data. A current limiting and fuse model is constructed in combination with the characteristics of the API gateway interface. The characteristics of the API gateway interface include interface type, business importance and average request size. The interface identifier, request volume, average response time, error rate, system load and interface characteristics are used as features, and the current limiting threshold and fuse rules are used as labels. The random forest algorithm is used to train historical data and construct peak and trough periods respectively. The model is a random forest algorithm in which the number of decision trees is set to one hundred, the maximum depth is set to ten, the feature sampling ratio is set to 0.8, and the data sampling ratio is set to 0.7. New monitoring data is obtained every hour, and the model is incrementally trained. The new data is merged with the latest 24 hours of data of the original data set, and the size of the data set is kept unchanged. The random forest model is retrained according to the merged data set, and the weights of the decision trees are updated. The new model is applied to real-time data, and the current limiting threshold and fuse rules of each interface are dynamically adjusted. If the error between the model prediction value and the actual observation value exceeds the preset threshold, the model structure adjustment is triggered, and the feature importance and the number of decision trees are re-evaluated.

[0044] Specifically, a sliding time window algorithm is used to monitor the traffic, response time, and error rate of each interface in real time. The window size is set to 5 minutes and updated every 10 seconds. The number of requests, average response time, and number of errors in the current time window are recorded. For the data of multiple API gateways, a weighted average method is used for aggregation, and the weight is dynamically adjusted according to the traffic ratio of each gateway. At the same time, peak periods, such as 9:00-18:00 on weekdays, and trough periods are distinguished, and data is recorded separately. According to the monitoring data, combined with the characteristics of the API gateway interface, a current limiting and fuse model is constructed. Interface characteristics include interface type, including read / write, business importance, including high / medium / low, average request size, etc. Interface identification, request volume, average response time, error rate, system load, interface characteristics, etc. are used as features, and current limiting thresholds and fuse rules are used as labels. The historical data is arranged in chronological order, and the data per hour is used as a sample to construct a training data set. The random forest algorithm is used to train the historical data, and models are constructed for peak and trough periods respectively. Set the number of decision trees to 100, the maximum depth to 10, the feature sampling ratio to 0.8, and the data sampling ratio to 0.7. Use the 5-fold cross-validation method to divide the data set into 5 parts, and use 4 parts as training sets and 1 part as validation sets in turn. Select the optimal parameter combination based on the average error on the validation set. Use new monitoring data every hour to incrementally train the model. Merge the new data with the latest 24 hours of data from the original data set to keep the data set size unchanged. Use the merged data set to retrain the random forest model and update the weights of the decision tree. After training, apply the new model to real-time data to dynamically adjust the current limiting threshold and fuse rules for each interface. At the same time, compare the error between the model prediction value and the actual observation value. If the error exceeds the preset threshold, such as 20%, the model structure adjustment is triggered to re-evaluate the feature importance and the number of decision trees. During real-time monitoring, the system monitors interface A for 5 minutes with a sliding window and updates the data every 10 seconds. Assume that within a 10-second interval, interface A receives 100 and 50 requests from gateway 1 and gateway 2, respectively, with an average response time of 80ms and 90ms, and the number of errors is 3 and 2. The system uses the weighted average method to calculate the comprehensive indicators of interface A based on the traffic ratio of 2:1: 150 requests, 83.3ms average response time, and 3.3% error rate. The current time is 10:30 on a weekday, which is a peak period, and this set of data is marked as a peak period sample. The system combines the characteristics of interface A, including read interface, high business importance, and average request size of 5KB, with the monitoring data to construct a training sample. The random forest algorithm uses 100 decision trees with a maximum depth of 10 to train on the peak period data of the past 24 hours. A 5-fold cross validation is used, for example, the first fold uses data from 0:00-4:00, 8:00-12:00, and 16:00-20:00 for training, and data from 4:00-8:00 for verification, and an average error of 7% is obtained.After repeating 5 times, select the parameter combination with the smallest error. After training, the model predicts that the optimal flow limit threshold of interface A is 200 requests / second, and the fuse rule is "the error rate exceeds 5% for 30 consecutive seconds". The prediction results are applied to real-time control and compared with the actual observed values. If the error between the predicted value and the actual optimal value exceeds 20%, the model adjustment is triggered, and the feature importance is re-evaluated. The "average load in the previous hour" may be added as a new feature.

[0045] Based on the above embodiments of the present invention, relevant personnel can make various changes and modifications without departing from the technical concept of the present invention through the above description. The technical scope of the present invention is not limited to the content in the specification, and its technical scope must be determined according to the scope of the claims.

Claims

1. A computing power unified access management method based on API technology, characterized in that: The method comprises: Obtain the real-time traffic, response time, and error rate indicator data of each interface. Combined with the historical traffic characteristics and fault tolerance requirements of the interface, use data analysis and machine learning methods to conduct real-time evaluation and prediction of the health status of each interface to obtain the evaluation results. Based on the health status assessment results of the interface, adaptively generate current limiting and fusing strategies. Combined with the traffic characteristics and fault tolerance requirements of different interfaces, dynamically set current limiting thresholds and fusing rules. Send the strategies to the current limiting and fusing components of the API gateway through the strategy management module. In the API gateway's current limiting and fuse components, the request volume and response time of each interface are monitored in real time. When the request volume exceeds the current limiting threshold, current limiting and fuse operations are performed, and requests exceeding the threshold are re-queued; Adopting the adaptive current limiting method, the token generation rate and the leakage rate of the leaky bucket are dynamically adjusted according to the real-time traffic changes of the interface, and the traffic is finely controlled and smoothed to avoid the impact of sudden traffic on the system. Set the state transition rules of the fuse. When the error rate and response time of the interface exceed the set threshold, the fuse changes from the closed state to the open state, quickly rejecting requests. When the interface returns to normal, the fuse gradually changes from the open state to the half-open state, allowing some requests to pass and monitoring their execution. If the request is successful, the fuse returns to the closed state, otherwise it remains open. Monitor the traffic, response time and error rate of each interface in real time, integrate different API gateway interfaces, establish a current limiting and circuit breaking model, use the random forest method to train and learn the model on historical data, and autonomously optimize the current limiting threshold and circuit breaking rules.

2. The method according to claim 1, characterized in that The real-time traffic, response time and error rate indicator data of each interface are obtained, and the health status of each interface is evaluated and predicted in real time by using data analysis and machine learning methods in combination with the historical traffic characteristics and fault tolerance requirements of the interface, and the evaluation results are obtained, including: Obtain the number of requests, average response time and number of errors per 10 seconds for each interface collected by the monitoring system, and calculate the real-time traffic, average response time and error rate indicators of the interface based on this; Based on the real-time traffic index and the historical traffic data of each interface in the past 30 days read from the database, a time series analysis method is used to identify the peak and valley distribution and periodic pattern of the historical traffic data, and a traffic feature file of the interface is constructed; For each interface, the real-time indicators are compared and analyzed with the historical data of the same period in the traffic feature archive, and the real-time indicators for the next 24 hours are predicted using the ARIMA model. If the real-time indicators exceed the preset fault tolerance threshold, they are marked as potential anomalies. For interfaces marked as potential anomalies, a health status classification model is established using a random forest algorithm, wherein the input features of the health status classification model include the real-time indicators of the interface, the historical data features in the traffic feature archive, and the preset fault tolerance threshold; According to the classification results of the health status classification model, combined with the change trend of the real-time indicators and the predicted value of the ARIMA model, an evaluation report is generated for the health status of each abnormal interface, and the evaluation report includes the current status of the interface, the analysis of the cause of the abnormality and the performance forecast for the next 24 hours.

3. The method according to claim 1, characterized in that The method adaptively generates a current limiting and fusing strategy based on the health status evaluation results of the interface, dynamically sets the current limiting threshold and fusing rules in combination with the traffic characteristics and fault tolerance requirements of different interfaces, and sends the strategy to the current limiting and fusing component of the API gateway through the policy management module, including: Acquire real-time health status data sent by the health status assessment module, wherein the real-time health status data includes interface identification, current flow, response time, error rate and health status score; According to the real-time health status data, flow feature description and fault tolerance requirements, a current limiting and fusing strategy is generated using a random forest algorithm, wherein the random forest algorithm uses historical flow characteristics, fault tolerance requirements and current health status as input features; The current limiting and fusing policy is converted into a standard policy description file in JSON format through a policy management module, wherein the standard policy description file includes an interface identifier, a current limiting threshold, a fusing condition, a recovery time, and a policy version number; Push the standard policy description file to the configuration center of the API gateway, where the configuration center is used to store the latest policy description file; Pull the latest policy description file from the configuration center, parse the JSON content of the policy description file and dynamically update the current limiting counter and the fuse state machine in the memory. The current limiting counter uses a sliding window algorithm to record the number of requests in each time window. The fuse state machine includes three states: closed, half-open, and open. It also includes: according to the health status of the interface, using the decision tree method to score the health status of each interface. If the score is higher than the preset threshold of the interface current limiting, the fuse is triggered; if the score is lower than the preset threshold of the interface current limiting, the fuse trigger is stopped, and the generated current limiting threshold and fuse rules are encapsulated into a policy object. If the policy object has a large amount of data and the delivery time is longer than the preset time, the API gateway current limiting fuse component will periodically select the latest policy configuration from the database.

4. The method according to claim 3, characterized in that: According to the health status of the interface, the decision tree method is used to score the health status of each interface. If the score is higher than the preset threshold of the interface current limiting, the fuse is triggered; if the score is lower than the preset threshold of the interface current limiting, the fuse trigger is stopped, and the generated current limiting threshold and fuse rule are encapsulated into a policy object. If the policy object has a large amount of data and the delivery time is longer than the preset time, the API gateway current limiting fuse component will periodically select the latest policy configuration from the database, including: Obtain the real-time data of the interface of the health status monitoring module and the historical data of the past seven days, wherein the real-time data of the interface includes the request volume, response time and error rate; According to the real-time data and historical data of the interface, A decision tree algorithm is used to construct a health status assessment model, and the request volume, response time and error rate are selected as features, and the health status is used as a label; The health status of the interface is quantitatively scored through the health status assessment model to obtain an interface score; the interface score is compared with a preset current limiting threshold, if the interface score is higher than the current limiting threshold, a fuse trigger instruction is generated, if the interface score is lower than the current limiting threshold, a stop fuse instruction is generated; according to the difference between the interface score and the current limiting threshold, the current limiting threshold is dynamically adjusted in proportion to obtain a new current limiting threshold; the new current limiting threshold, fuse rule, and trigger instruction are encapsulated into a policy object; the data volume of the policy object after serialization is calculated, if the data volume exceeds the preset network transmission threshold, the policy object is stored in a database, if the data volume does not exceed the network transmission threshold, the policy object is sent to the API gateway through the network; the current limiting fuse component of the API gateway triggers a task through a timer to read the latest policy configuration from the database, if the version number of the latest policy configuration is greater than the locally cached policy version number, the locally cached policy configuration is updated.

5. The method according to claim 1, characterized in that In the current limiting and fusing component of the API gateway, the request volume and response time of each interface are monitored in real time. When the request volume exceeds the current limiting threshold, current limiting and fusing operations are performed, and requests exceeding the threshold are re-queued, including: Receiving a request message carrying an interface identifier, wherein the request message is sent by an API caller; Using a sliding time window algorithm to count the request volume and average response time of the interface in real time according to the request information, wherein the sliding time window algorithm uses a ring buffer to store the number of requests per second and the total response time; Determine whether the request amount exceeds a preset current limiting threshold, and if the request amount exceeds the current limiting threshold, trigger a current limiting operation; Obtaining requests that exceed the current limiting threshold, and placing the requests that exceed the threshold into a priority queue for queue processing, wherein the priority queue calculates a priority score based on the importance and waiting time of the request; Start the fuse timer to record the fuse start time. If the current limit is continuously triggered or the response time exceeds the limit within the preset time window, the fuse operation is executed; Taking out the request with the highest priority from the priority queue for processing, monitoring the response time of the request, and judging whether the response time is lower than a preset threshold value, and releasing the fuse state if the average response time of the request group taken out for multiple consecutive times is lower than the preset threshold value; It also includes: using the token bucket method to implement the current limiting function. The number of tokens in the token bucket represents the number of requests allowed to pass. When a request arrives, it is determined whether there are enough tokens in the token bucket. If so, the request is passed and the corresponding tokens are consumed. If not, the current limiting measures are triggered. At the same time, the leaky bucket algorithm is combined to implement traffic shaping to handle sudden large-traffic requests at a uniform speed.

6. The method according to claim 5, characterized in that The token bucket method is used to implement the current limiting function. The number of tokens in the token bucket represents the number of requests allowed to pass. When a request arrives, it is determined whether there are enough tokens in the token bucket. If there are, the request is passed and the corresponding tokens are consumed. If not, the current limiting measures are triggered. At the same time, the leaky bucket algorithm is combined to implement traffic shaping, and sudden large traffic requests are processed in a uniform manner, including: Dynamically calculate the token bucket capacity and token generation rate based on historical request statistics; The token generation rate is used to determine the number of tokens added to the token bucket per second; Create a high-priority request queue and a normal-priority request queue; The high priority request queue and the normal priority request queue have fixed sizes; Adding a preset number of tokens to the token bucket using an atomic operation; If the number of tokens in the token bucket reaches the upper limit of capacity, stop adding; When receiving a request, determining a priority of the request; According to the priority of the request, checking the number of tokens in the token bucket of the corresponding priority; If the number of tokens in the token bucket is greater than or equal to 1, atomically taking a token from the token bucket; If the number of tokens in the token bucket is 0, the request is placed in a request queue of the corresponding priority; Taking out requests from the high priority request queue or the normal priority request queue for processing through a separate processing thread; The processing thread preferentially takes out requests from the high priority request queue for processing.

7. The method according to claim 1, characterized in that The adaptive current limiting method is used to dynamically adjust the token generation rate and the leakage rate of the leaky bucket according to the real-time traffic changes of the interface, and finely control and smooth the traffic to avoid the impact of sudden traffic on the system, including: A sliding time window algorithm is used to monitor interface traffic in real time. The sliding time window algorithm uses a ring buffer to store the number of requests per second and the average response time. According to the flow state monitored by the sliding time window algorithm, an exponentially weighted moving average algorithm is used to calculate the expected flow, and the exponentially weighted moving average algorithm obtains a new expected flow; Setting the new expected traffic as a benchmark value of a token generation rate and a leaky bucket leakage rate, wherein the benchmark value is adjusted according to CPU usage and memory occupancy; If the deviation between the actual flow and the expected flow exceeds the preset threshold and meets the cooling period requirement, the dynamic adjustment mechanism is triggered, and the dynamic adjustment mechanism updates the relevant parameters of the token bucket and the leaky bucket; The system processing capacity is recalculated according to the parameters updated by the dynamic adjustment mechanism, and the system processing capacity is used to adjust the request queue size.

8. The method according to claim 1, characterized in that The state transition rule of setting the fuse, when the error rate and response time of the interface exceed the set threshold, the fuse is transferred from the closed state to the open state, and the request is quickly rejected. When the interface returns to normal, the fuse gradually transfers from the open state to the half-open state, allowing some requests to pass and monitoring their execution. If the request is successful, the fuse is restored to the closed state, otherwise it continues to remain in the open state, including: Receive real-time request data from a service interface, and process the real-time request data using a sliding time window algorithm; The current error rate and average response time are calculated according to the sliding time window algorithm, wherein the error rate includes network timeout errors and business logic errors; Determine whether the error rate exceeds a preset threshold, and if the error rate exceeds the preset threshold, record the time for which the error rate continuously exceeds the threshold; Setting a fuse state according to the time that the voltage continuously exceeds the threshold value, and setting the fuse state to open if the time that the voltage continuously exceeds the threshold value reaches a predetermined value; When the fuse state is open, start the timer and use the polling mechanism to select some requests to pass; Monitor the passed requests and obtain the success rate and average response time of the passed requests; Whether to restore the fuse state to closed is determined based on the success rate and the average response time. If the success rate exceeds a preset success rate threshold and the average response time is lower than a preset response time threshold, the fuse state is restored to closed.

9. The method according to claim 1, characterized in that: The real-time monitoring of the traffic, response time and error rate of each interface is carried out, and different API gateway interfaces are integrated to establish a current limiting and fuse model. The random forest method is used to train and learn the model on historical data, and the current limiting threshold and fuse rules are autonomously optimized, including: A sliding time window algorithm is used to monitor the flow, response time and error rate of each interface in real time. The sliding time window size is set to five minutes and updated every ten seconds. Obtain the number of requests, average response time, and number of errors within the current time window based on monitoring data; A current limiting and circuit breaking model is constructed in combination with the characteristics of the API gateway interface, wherein the characteristics of the API gateway interface include the interface type, business importance, and average request size; The interface identifier, request volume, average response time, error rate, system load, and interface characteristics are used as features, and the current limiting threshold and fuse rules are used as labels; The random forest algorithm is used to train the historical data, and the models are constructed for the peak period and the trough period respectively. The number of decision trees of the random forest algorithm is set to 100, the maximum depth is set to 10, the feature sampling ratio is set to 0.8, and the data sampling ratio is set to 0.7; New monitoring data is obtained every hour, and the model is incrementally trained. The new data is merged with the latest 24 hours of data in the original data set to keep the data set size unchanged; Retrain the random forest model based on the merged dataset and update the weights of the decision tree; Apply the new model to real-time data to dynamically adjust the current limiting threshold and fuse rules for each interface; If the error between the model prediction value and the actual observation value exceeds the preset threshold, the model structure adjustment is triggered and the feature importance and the number of decision trees are re-evaluated.

Citation Information

Cited By

  • Token bucket and leaky bucket combined flow limiting method and system for payment system

    CN120389987A

  • A current limiting method and system combining token bucket and leaky bucket for payment system

    CN120389987B

  • Request path flow limiting method and system, electronic device and storage medium

    CN120956669A

  • API request flow control method, system and device and medium

    CN121077980A

  • Streaming data processing method and device, equipment and medium

    CN121125625A