Dynamic current limiting method and device, computer equipment and storage medium
By building a relationship model of the interface response time and number of requests and calculating the adjustment factor, dynamically adjusting the service request frequency of the server interface, the problem that the existing flow-limiting method cannot be adjusted according to the server's processing capacity is solved, and the call speed is improved.
Patent Information
- Application Number
- CN202510092467.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-05-16
AI Technical Summary
The existing server flow restriction method is fixed and cannot be dynamically adjusted according to the server processing capabilities of the service provider, resulting in slow call speed of the caller.
By obtaining the historical average response time and historical service request frequency of the server interface, a relationship model of the interface response time and number of requests is built, and the adjustment factor is calculated based on the response time and logical complexity of each target service request, and the service request frequency is dynamically adjusted.
It realizes dynamic adjustment of the current limiting speed according to the server processing capabilities of the service provider, improves the call speed of the caller, and avoids the performance bottleneck caused by the fixed current limiting method.
Smart Images

Figure CN120017713A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of server technology, and in particular to a dynamic current limiting method, device, computer equipment and storage medium. Background Art
[0002] When the server processes a service request, it will form a request queue for the service requests received by the server interface and process the service requests in order. In order to ensure the stability of the server, the caller's traffic (i.e., the number of requests per second QPS) will be limited. If the traffic exceeds the limit, the interface will be returned as unavailable, causing the caller to be unable to obtain the corresponding data, and ultimately causing the call to fail. Generally, the caller will continue to retry the failed call data and repeatedly initiate service requests, resulting in an increase in the number of service requests received by the interface. In addition, the data that originally needed to be called will cause greater pressure on the interface, resulting in greater pressure on the server, resulting in a vicious cycle that may cause the server to crash.
[0003] The current common solution is to use a current limiting component on the caller, but the current current limiting component is a fixed current limiting measure, such as a fixed number of queries per second. However, the service provider's server will have different service capabilities due to the amount of access and the load of the real-time machine, and the current limiting speed will also be different. As a result, the current limiting speed cannot be dynamically adjusted according to the service provider's server's ability to process service requests, which ultimately causes the caller's call speed to be slow. Summary of the invention
[0004] Based on this, a dynamic current limiting method, apparatus, computer device and storage medium are provided to solve the technical problem that the current server uses a fixed current limiting method for the caller, resulting in the inability to dynamically adjust the current limiting speed according to the service provider's server's ability to process service requests, ultimately causing the caller to call at a slower speed.
[0005] In one aspect, a dynamic current limiting method is provided, the method comprising:
[0006] Get the historical average response time and historical service request frequency of the server interface;
[0007] A relationship model between interface response time and number of requests is constructed based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the relationship model between interface response time and number of requests is negatively correlated with the response time and the logic complexity of the interface;
[0008] After calling the interface through the target service request, the interface response time and the logic complexity of the interface are obtained, an adjustment factor is calculated according to the interface response time and the logic complexity of the interface, and the service request frequency of the relationship model between the interface response time and the number of requests is adjusted according to the adjustment factor;
[0009] The adjusted relationship model between the interface response time and the number of requests is used to control the service request frequency of the interface for responding to service requests.
[0010] In one embodiment, calculating the adjustment factor according to the interface response time and the logic complexity of the interface includes:
[0011] Setting a value of a smoothing factor according to the logic complexity of the interface;
[0012] An expected interface response time is obtained, and an adjustment factor is calculated by dividing the interface response time by the expected interface response time and multiplying the smoothing factor.
[0013] In one embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor includes:
[0014] Get the value of the calculated adjustment factor;
[0015] If the calculated value of the adjustment factor is greater than 1, reducing the service request frequency of the interface response time and request number relationship model;
[0016] If the calculated value of the adjustment factor is less than 1, the service request frequency of the interface response time and request number relationship model is increased.
[0017] In one embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0018] The current service request frequency of the interface response time and request number relationship model is obtained, and the service request frequency of the interface response time and request number relationship model is adjusted by dividing the current service request frequency by the value of the calculated adjustment factor.
[0019] In one embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0020] Setting a control coefficient for controlling the service request frequency adjustment speed of the interface response time and request number relationship model to k, where k is a positive number less than 1;
[0021] The process of smoothly adjusting the service request frequency of the interface response time and request number relationship model is controlled by current_qps×(1-k)+(current_qps / adjustment_factor)×k, where current_qps is the current service request frequency of the interface response time and request number relationship model, and adjustment_factor is the calculated value of the adjustment factor.
[0022] In one embodiment, the method further comprises:
[0023] Acquire a numerical range of a service request frequency of the interface according to a historical service request frequency of the interface, and set a maximum request frequency threshold and a minimum request frequency threshold based on the numerical range of the service request frequency of the interface;
[0024] The adjusted service request frequency of the interface response time and request number relationship model is set between the maximum request frequency threshold and the minimum request frequency threshold.
[0025] In one embodiment, the service request frequency of the interface response time and request number relationship model after setting the adjustment includes between the maximum request frequency threshold and the minimum request frequency threshold:
[0026] Obtain the current service request frequency of the interface response time and request number relationship model, and adjust the service request frequency of the interface response time and request number relationship model according to the current service request frequency, the maximum request frequency threshold, and the minimum request frequency threshold. The adjusted service request frequency of the interface response time and request number relationship model is max[min(current_qps, max_qps), min_qps], where current_qps is the current service request frequency, max_qps is the maximum request frequency threshold, and min_qps is the minimum request frequency threshold.
[0027] On the other hand, a dynamic current limiting device is provided, the device comprising:
[0028] A historical data acquisition module is used to obtain the historical average response time and historical service request frequency of the server interface;
[0029] A relationship model building module is used to build an interface response time and request number relationship model based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the interface response time and request number relationship model is negatively correlated with the response time and the logic complexity of the interface;
[0030] An adjustment relationship model module is used to obtain the interface response time and the logic complexity of the interface after calling the interface through the target service request, calculate the adjustment factor according to the interface response time and the logic complexity of the interface, and adjust the service request frequency of the interface response time and request number relationship model according to the adjustment factor;
[0031] The service request frequency control module is used to control the service request frequency of the interface for responding to service requests by using the adjusted relationship model between the interface response time and the number of requests.
[0032] In another aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are implemented:
[0033] Get the historical average response time and historical service request frequency of the server interface;
[0034] A relationship model between interface response time and number of requests is constructed based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the relationship model between interface response time and number of requests is negatively correlated with the response time and the logic complexity of the interface;
[0035] After calling the interface through the target service request, the interface response time and the logic complexity of the interface are obtained, an adjustment factor is calculated according to the interface response time and the logic complexity of the interface, and the service request frequency of the relationship model between the interface response time and the number of requests is adjusted according to the adjustment factor;
[0036] The adjusted relationship model between the interface response time and the number of requests is used to control the service request frequency of the interface for responding to service requests.
[0037] In another aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0038] Get the historical average response time and historical service request frequency of the server interface;
[0039] A relationship model between interface response time and number of requests is constructed based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the relationship model between interface response time and number of requests is negatively correlated with the response time and the logic complexity of the interface;
[0040] After calling the interface through the target service request, the interface response time and the logic complexity of the interface are obtained, an adjustment factor is calculated according to the interface response time and the logic complexity of the interface, and the service request frequency of the relationship model between the interface response time and the number of requests is adjusted according to the adjustment factor;
[0041] The adjusted relationship model between the interface response time and the number of requests is used to control the service request frequency of the interface for responding to service requests.
[0042] The above-mentioned dynamic current limiting method, device, computer equipment and storage medium construct an interface response time and request number relationship model based on the historical average response time of the interface and the historical service request frequency, and calculate the adjustment factor based on the interface response time after each target service request calls the interface and the logical complexity of the interface, and then adjust the service request frequency of the interface response time and request number relationship model based on the calculated adjustment factor. The interface response time and request number relationship model can be used to dynamically adjust the service request frequency of the service provider's server processing service requests, which can improve the caller's call speed and realize adaptive dynamic adjustment of the caller's current limiting speed without being constrained by a fixed current limiting method. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0044] Figure 1 This is an application environment diagram of a dynamic current limiting method in one embodiment of the present application;
[0045] Figure 2 This is a flow chart of a dynamic current limiting method in one embodiment of the present application;
[0046] Figure 3 A logic diagram of a dynamic current limiting method in one embodiment of the present application;
[0047] Figure 4 This is a structural block diagram of a dynamic current limiting device in one embodiment of the present application;
[0048] Figure 5 This is a diagram of the internal structure of a computer device in one embodiment of the present application. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0050] The dynamic current limiting method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The server 104 provides a three-party docking interface for the terminal 102. The caller initiates a service request through the interface of the server 104 to call the data stored in the server 104. The server 104 controls the service request frequency of the interface used to respond to the service request through the interface response time and request number relationship model to avoid the problem of slow call speed caused by the caller using the current limiting component to perform a fixed current limiting method in the terminal 102. Among them, the terminal 102 can be but not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server 104 can be implemented with an independent server or a server cluster composed of multiple servers.
[0051] In one embodiment, Figure 2 , Figure 3 As shown, a dynamic current limiting method is provided, which is applied to Figure 1 Taking the server 104 in the example as an example, the following steps are included:
[0052] Step S1, obtaining the historical average response time and historical service request frequency of the server interface;
[0053] Step S2, constructing an interface response time and request number relationship model based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the interface response time and request number relationship model is negatively correlated with the response time and the logic complexity of the interface;
[0054] Step S3, after calling the interface through the target service request, obtaining the interface response time and the logic complexity of the interface, calculating an adjustment factor according to the interface response time and the logic complexity of the interface, and adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor;
[0055] Step S4: Using the adjusted relationship model between the interface response time and the number of requests, the service request frequency of the interface for responding to service requests is controlled.
[0056] Preferably, the service request frequency is the number of service requests per second or the number of service requests per minute.
[0057] Among them, an interface response time and request number relationship model is constructed according to the historical average response time of the interface and the historical service request frequency, and an adjustment factor is calculated based on the interface response time after each target service request calls the interface and the logical complexity of the interface. Then, the service request frequency of the interface response time and request number relationship model is adjusted based on the calculated adjustment factor. The interface response time and request number relationship model can be used to dynamically adjust the service request frequency of the service provider's server processing service requests, which can improve the caller's call speed and realize adaptive dynamic adjustment of the caller's flow limiting speed without being constrained by a fixed flow limiting method.
[0058] In this embodiment, the calculating of the adjustment factor according to the interface response time and the logic complexity of the interface includes:
[0059] Setting a value of a smoothing factor according to the logic complexity of the interface;
[0060] An expected interface response time is obtained, and an adjustment factor is calculated by dividing the interface response time by the expected interface response time and multiplying the smoothing factor.
[0061] Specifically, the adjustment factor is calculated as follows: adjustment_factor=response_time / target_response_time×complexity_factor, where adjustment_factor is the value of the adjustment factor, response_time is the interface response time, target_response_time is the expected interface response time, and complexity_factor is the smoothing factor.
[0062] In another embodiment, setting the value of the smoothing factor according to the logic complexity of the interface includes:
[0063] Obtain the resource consumption and operation complexity of the interface, and obtain the logic complexity of the interface by multiplying the resource consumption and operation complexity of the interface by the corresponding weight coefficient and adding them together, wherein the resource consumption includes computing resource consumption, memory resource consumption and read-write resource consumption, and the operation complexity includes data complexity and algorithm complexity;
[0064] The calculated logic complexity of the interface is obtained, and a smoothing factor value is calculated based on an inverse relationship.
[0065] Specifically, the calculation formula of the logic complexity of the interface is:
[0066]
[0067] Among them, C represents the calculated logic complexity, R cpu Indicates the number of CPUs used when calling the interface, R cpuMax Indicates the maximum CPU usage allocated to the interface. represents the computing resource consumption of the interface, α represents the weight coefficient of computing resource consumption, R men Indicates the amount of memory used when the interface is called, R memMax Indicates the maximum amount of memory allocated to the interface. represents the memory resource consumption of the interface, β represents the weight coefficient of memory resource consumption, and R IO Indicates the number of data read and write times during interface calls, R IOMax Indicates the maximum number of data read and write times assigned to the interface. represents the read and write resource consumption of the interface, γ represents the weight coefficient of the read and write resource consumption, D represents the data complexity of the interface, which is exponentially related to the total amount of data and data structure of the interface input, δ represents the weight coefficient of data complexity, E represents the algorithm complexity of the interface, which is positively correlated with the time complexity and space complexity of the algorithm, and ε represents the weight coefficient of the interface algorithm complexity;
[0068] Specifically, the calculation formula for obtaining the smoothing factor value based on the inverse relationship is:
[0069]
[0070] In one embodiment, a method for calculating the data complexity of an interface is: D = n p , where n represents the data scale, which is positively correlated with the total amount of data input by the interface, and p represents the interface data complexity index factor, which is set according to the data structure of the interface input. For example, when the data structure is a linear table, p is set to 1;
[0071] In this embodiment, a calculation method for the algorithm complexity of the interface is: A = μ·Alg·f(n), where μ represents the space complexity factor of the algorithm, which is set according to the positive correlation between the algorithm space complexity, Alg is the algorithm constant coefficient, which represents the deviation value between the algorithm and the theoretical complexity during execution, obtained through experiments or measurements, and f(n) is the time complexity function of the algorithm. For example, the time complexity function of the sorting algorithm is n 2 , n also represents the data size.
[0072] In one embodiment, before calculating the adjustment factor, query the server historical data to determine whether there is a historical adjustment factor in the server historical cache data;
[0073] In response to the absence of the historical adjustment factor, obtaining the server real-time data to calculate the adjustment factor and storing it in the server;
[0074] In response to the existence of the historical adjustment factor, the most recently generated historical adjustment factor is selected to perform availability judgment, wherein the availability judgment includes at least one of the following: environment similarity judgment, access similarity judgment, and update time judgment;
[0075] In response to the availability determination being negative, obtaining the server real-time data to calculate the adjustment factor and storing it in the server;
[0076] In response to the availability determination being yes, the selected most recently generated historical adjustment factor is used as the adjustment factor used in subsequent calculations to participate in subsequent interface request frequency adjustments.
[0077] Specifically, the usability judgment includes the following steps:
[0078] Obtain the server historical environment data and current server environment data corresponding to the historical adjustment factor, and compare whether the server environment fluctuation is greater than the fluctuation threshold. If so, the environment similarity is judged as no, otherwise it is yes;
[0079] Obtain the interface history access record corresponding to the history adjustment factor, obtain the interface history access source address and the interface history access data volume, compare them with the pre-obtained interface current access source address and interface current access data volume, and determine whether the change rate of the interface access source address is greater than the change threshold, or whether the change amount of the interface access data volume is greater than the change threshold. If either is true, the access similarity is judged as no, otherwise it is true;
[0080] Get the generation time of the historical adjustment factor, combine it with the current time to get the update time difference, and judge whether the update time difference exceeds the maximum trust time. If so, the update time is judged as no, otherwise it is yes;
[0081] In response to the environmental similarity judgment, the access similarity judgment, and the update time judgment being all negative, the availability judgment is positive.
[0082] It is worth noting that the large fluctuations in environmental similarity judgment, large-scale changes in the source addresses of interface access, and large changes in the amount of interface access data are all obtained through comparison based on several preset thresholds, among which several preset thresholds and maximum trust time can be obtained based on experiments or set in combination with historical data and needs.
[0083] In this embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor includes:
[0084] Get the value of the calculated adjustment factor;
[0085] If the calculated value of the adjustment factor is greater than 1, reducing the service request frequency of the interface response time and request number relationship model;
[0086] If the calculated value of the adjustment factor is less than 1, the service request frequency of the interface response time and request number relationship model is increased.
[0087] Among them, if the service request response is slow within a certain time period, it is considered that the pressure on the other party's server is greater, so the number of service request calls is reduced. Conversely, if the response of the other party's server is faster, the number of service request calls is increased. Therefore, if you want to accurately control the number of service request calls, you need to calculate the relationship between the number of service request calls and the interface response time. Using the historical interface response time and number of requests as the input parameters of the model, a model of the relationship between interface response time and number of requests is obtained, and then the interface response time of each call data is used as the correction data to correct the service request frequency of the interface response time and number of requests relationship model, as the service request frequency of the interface call data in the next call cycle.
[0088] In this embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0089] The current service request frequency of the interface response time and request number relationship model is obtained, and the service request frequency of the interface response time and request number relationship model is adjusted by dividing the current service request frequency by the value of the calculated adjustment factor.
[0090] Specifically, the service request frequency of the interface response time and request number relationship model is adjusted by current_qps / adjustment_factor, where current_qps is the current service request frequency and adjustment_factor is the value of the adjustment factor.
[0091] In this embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0092] Setting a control coefficient for controlling the service request frequency adjustment speed of the interface response time and request number relationship model to k, where k is a positive number less than 1;
[0093] The process of smoothly adjusting the service request frequency of the interface response time and request number relationship model is controlled by current_qps×(1-k)+(current_qps / adjustment_factor)×k, where current_qps is the current service request frequency of the interface response time and request number relationship model, and adjustment_factor is the calculated value of the adjustment factor.
[0094] In this embodiment, the method further includes:
[0095] Acquire a numerical range of a service request frequency of the interface according to a historical service request frequency of the interface, and set a maximum request frequency threshold and a minimum request frequency threshold based on the numerical range of the service request frequency of the interface;
[0096] The adjusted service request frequency of the interface response time and request number relationship model is set between the maximum request frequency threshold and the minimum request frequency threshold.
[0097] In this embodiment, the service request frequency of the interface response time and request number relationship model after the setting adjustment includes between the maximum request frequency threshold and the minimum request frequency threshold:
[0098] Obtain the current service request frequency of the interface response time and request number relationship model, and adjust the service request frequency of the interface response time and request number relationship model according to the current service request frequency, the maximum request frequency threshold, and the minimum request frequency threshold. The adjusted service request frequency of the interface response time and request number relationship model is max[min(current_qps, max_qps), min_qps], where current_qps is the current service request frequency, max_qps is the maximum request frequency threshold, and min_qps is the minimum request frequency threshold.
[0099] In the above-mentioned dynamic current limiting method, an interface response time and request number relationship model is constructed according to the historical average response time of the interface and the historical service request frequency, and an adjustment factor is calculated based on the interface response time after each target service request calls the interface and the logical complexity of the interface. Then, the service request frequency of the interface response time and request number relationship model is adjusted based on the calculated adjustment factor. The interface response time and request number relationship model can be used to dynamically adjust the service request frequency of the service provider's server processing service requests, which can improve the caller's call speed and realize adaptive dynamic adjustment of the caller's current limiting speed without being constrained by a fixed current limiting method.
[0100] In one embodiment, Figure 4 As shown, a dynamic current limiting device 10 is provided, comprising: a historical data acquisition module 1, a relationship model construction module 2, a relationship model adjustment module 3 and a service request frequency control module 4.
[0101] The historical data acquisition module 1 is used to obtain the historical average response time and historical service request frequency of the server interface.
[0102] The relationship model building module 2 is used to build an interface response time and request number relationship model based on the historical average response time of the interface and the historical service request frequency. In the interface response time and request number relationship model, the service request frequency is negatively correlated with the response time and the logical complexity of the interface.
[0103] The adjustment relationship model module 3 is used to obtain the interface response time and the logical complexity of the interface after the interface is called through the target service request, calculate the adjustment factor according to the interface response time and the logical complexity of the interface, and adjust the service request frequency of the interface response time and request number relationship model according to the adjustment factor.
[0104] The service request frequency control module 4 is used to control the service request frequency of the interface for responding to service requests by using the adjusted relationship model between the interface response time and the number of requests.
[0105] In this embodiment, the calculating of the adjustment factor according to the interface response time and the logic complexity of the interface includes:
[0106] Setting a value of a smoothing factor according to the logic complexity of the interface;
[0107] An expected interface response time is obtained, and an adjustment factor is calculated by dividing the interface response time by the expected interface response time and multiplying the smoothing factor.
[0108] Specifically, the adjustment factor is calculated as follows: adjustment_factor=response_time / target_response_time×complexity_factor, where adjustment_factor is the value of the adjustment factor, response_time is the interface response time, target_response_time is the expected interface response time, and complexity_factor is the smoothing factor.
[0109] In this embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor includes:
[0110] Get the value of the calculated adjustment factor;
[0111] If the calculated value of the adjustment factor is greater than 1, reducing the service request frequency of the interface response time and request number relationship model;
[0112] If the calculated value of the adjustment factor is less than 1, the service request frequency of the interface response time and request number relationship model is increased.
[0113] In this embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0114] The current service request frequency of the interface response time and request number relationship model is obtained, and the service request frequency of the interface response time and request number relationship model is adjusted by dividing the current service request frequency by the value of the calculated adjustment factor.
[0115] Specifically, the service request frequency of the interface response time and request number relationship model is adjusted by current_qps / adjustment_factor, where current_qps is the current service request frequency and adjustment_factor is the value of the adjustment factor.
[0116] In this embodiment, adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0117] Setting a control coefficient for controlling the service request frequency adjustment speed of the interface response time and request number relationship model to k, where k is a positive number less than 1;
[0118] The process of smoothly adjusting the service request frequency of the interface response time and request number relationship model is controlled by current_qps×(1-k)+(current_qps / adjustment_factor)×k, where current_qps is the current service request frequency of the interface response time and request number relationship model, and adjustment_factor is the calculated value of the adjustment factor.
[0119] In this embodiment, the service request frequency control module 4 is further used for:
[0120] Acquire a numerical range of a service request frequency of the interface according to a historical service request frequency of the interface, and set a maximum request frequency threshold and a minimum request frequency threshold based on the numerical range of the service request frequency of the interface;
[0121] The adjusted service request frequency of the interface response time and request number relationship model is set between the maximum request frequency threshold and the minimum request frequency threshold.
[0122] In this embodiment, the service request frequency of the interface response time and request number relationship model after the setting adjustment includes between the maximum request frequency threshold and the minimum request frequency threshold:
[0123] Obtain the current service request frequency of the interface response time and request number relationship model, and adjust the service request frequency of the interface response time and request number relationship model according to the current service request frequency, the maximum request frequency threshold, and the minimum request frequency threshold. The adjusted service request frequency of the interface response time and request number relationship model is max[min(current_qps, max_qps), min_qps], where current_qps is the current service request frequency, max_qps is the maximum request frequency threshold, and min_qps is the minimum request frequency threshold.
[0124] In the above-mentioned dynamic current limiting device, an interface response time and request number relationship model is constructed according to the historical average response time of the interface and the historical service request frequency, and an adjustment factor is calculated based on the interface response time after each target service request calls the interface and the logical complexity of the interface. Then, the service request frequency of the interface response time and request number relationship model is adjusted based on the calculated adjustment factor. The interface response time and request number relationship model can be used to dynamically adjust the service request frequency of the service provider's server processing service requests, which can improve the caller's call speed and realize adaptive dynamic adjustment of the caller's current limiting speed without being constrained by a fixed current limiting method.
[0125] For the specific definition of the dynamic current limiting device, please refer to the definition of the dynamic current limiting method above, which will not be repeated here. Each module in the above-mentioned dynamic current limiting device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0126] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0127] Get the historical average response time and historical service request frequency of the server interface;
[0128] A relationship model between interface response time and number of requests is constructed based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the relationship model between interface response time and number of requests is negatively correlated with the response time and the logic complexity of the interface;
[0129] After calling the interface through the target service request, the interface response time and the logic complexity of the interface are obtained, an adjustment factor is calculated according to the interface response time and the logic complexity of the interface, and the service request frequency of the relationship model between the interface response time and the number of requests is adjusted according to the adjustment factor;
[0130] The adjusted relationship model between the interface response time and the number of requests is used to control the service request frequency of the interface for responding to service requests.
[0131] In one embodiment, the computer program further implements the following steps when executed by a processor:
[0132] The calculating of the adjustment factor according to the interface response time and the logic complexity of the interface includes:
[0133] Setting a value of a smoothing factor according to the logic complexity of the interface;
[0134] An expected interface response time is obtained, and an adjustment factor is calculated by dividing the interface response time by the expected interface response time and multiplying the smoothing factor.
[0135] Specifically, the adjustment factor is calculated as follows: adjustment_factor=response_time / target_response_time×complexity_factor, where adjustment_factor is the value of the adjustment factor, response_time is the interface response time, target_response_time is the expected interface response time, and complexity_factor is the smoothing factor.
[0136] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0137] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor comprises:
[0138] Get the value of the calculated adjustment factor;
[0139] If the calculated value of the adjustment factor is greater than 1, reducing the service request frequency of the interface response time and request number relationship model;
[0140] If the calculated value of the adjustment factor is less than 1, the service request frequency of the interface response time and request number relationship model is increased.
[0141] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0142] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0143] The current service request frequency of the interface response time and request number relationship model is obtained, and the service request frequency of the interface response time and request number relationship model is adjusted by dividing the current service request frequency by the value of the calculated adjustment factor.
[0144] Specifically, the service request frequency of the interface response time and request number relationship model is adjusted by current_qps / adjustment_factor, where current_qps is the current service request frequency and adjustment_factor is the value of the adjustment factor.
[0145] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0146] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0147] Setting a control coefficient for controlling the service request frequency adjustment speed of the interface response time and request number relationship model to k, where k is a positive number less than 1;
[0148] The process of smoothly adjusting the service request frequency of the interface response time and request number relationship model is controlled by current_qps×(1-k)+(current_qps / adjustment_factor)×k, where current_qps is the current service request frequency of the interface response time and request number relationship model, and adjustment_factor is the calculated value of the adjustment factor.
[0149] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0150] The method further comprises:
[0151] Acquire a numerical range of a service request frequency of the interface according to a historical service request frequency of the interface, and set a maximum request frequency threshold and a minimum request frequency threshold based on the numerical range of the service request frequency of the interface;
[0152] The adjusted service request frequency of the interface response time and request number relationship model is set between the maximum request frequency threshold and the minimum request frequency threshold.
[0153] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0154] The service request frequency of the interface response time and request number relationship model after the setting adjustment includes between the maximum request frequency threshold and the minimum request frequency threshold:
[0155] Obtain the current service request frequency of the interface response time and request number relationship model, and adjust the service request frequency of the interface response time and request number relationship model according to the current service request frequency, the maximum request frequency threshold, and the minimum request frequency threshold. The adjusted service request frequency of the interface response time and request number relationship model is max[min(current_qps, max_qps), min_qps], where current_qps is the current service request frequency, max_qps is the maximum request frequency threshold, and min_qps is the minimum request frequency threshold.
[0156] For the specific limitations on the steps implemented when the computer program is executed by the processor, please refer to the limitations on the dynamic current limiting method above, which will not be repeated here.
[0157] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store dynamic current limiting data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a dynamic current limiting method is implemented.
[0158] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0159] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0160] Get the historical average response time and historical service request frequency of the server interface;
[0161] A relationship model between interface response time and number of requests is constructed based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the relationship model between interface response time and number of requests is negatively correlated with the response time and the logic complexity of the interface;
[0162] After calling the interface through the target service request, the interface response time and the logic complexity of the interface are obtained, an adjustment factor is calculated according to the interface response time and the logic complexity of the interface, and the service request frequency of the relationship model between the interface response time and the number of requests is adjusted according to the adjustment factor;
[0163] The adjusted relationship model between the interface response time and the number of requests is used to control the service request frequency of the interface for responding to service requests.
[0164] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0165] The calculating of the adjustment factor according to the interface response time and the logic complexity of the interface includes:
[0166] Setting a value of a smoothing factor according to the logic complexity of the interface;
[0167] An expected interface response time is obtained, and an adjustment factor is calculated by dividing the interface response time by the expected interface response time and multiplying the smoothing factor.
[0168] Specifically, the adjustment factor is calculated as follows: adjustment_factor=response_time / target_response_time×complexity_factor, where adjustment_factor is the value of the adjustment factor, response_time is the interface response time, target_response_time is the expected interface response time, and complexity_factor is the smoothing factor.
[0169] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0170] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor comprises:
[0171] Get the value of the calculated adjustment factor;
[0172] If the calculated value of the adjustment factor is greater than 1, reducing the service request frequency of the interface response time and request number relationship model;
[0173] If the calculated value of the adjustment factor is less than 1, the service request frequency of the interface response time and request number relationship model is increased.
[0174] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0175] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0176] The current service request frequency of the interface response time and request number relationship model is obtained, and the service request frequency of the interface response time and request number relationship model is adjusted by dividing the current service request frequency by the value of the calculated adjustment factor.
[0177] Specifically, the service request frequency of the interface response time and request number relationship model is adjusted by current_qps / adjustment_factor, where current_qps is the current service request frequency and adjustment_factor is the value of the adjustment factor.
[0178] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0179] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0180] Setting a control coefficient for controlling the service request frequency adjustment speed of the interface response time and request number relationship model to k, where k is a positive number less than 1;
[0181] The process of smoothly adjusting the service request frequency of the interface response time and request number relationship model is controlled by current_qps×(1-k)+(current_qps / adjustment_factor)×k, where current_qps is the current service request frequency of the interface response time and request number relationship model, and adjustment_factor is the calculated value of the adjustment factor.
[0182] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0183] The method further comprises:
[0184] Acquire a numerical range of a service request frequency of the interface according to a historical service request frequency of the interface, and set a maximum request frequency threshold and a minimum request frequency threshold based on the numerical range of the service request frequency of the interface;
[0185] The adjusted service request frequency of the interface response time and request number relationship model is set between the maximum request frequency threshold and the minimum request frequency threshold.
[0186] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0187] The service request frequency of the interface response time and request number relationship model after the setting adjustment includes between the maximum request frequency threshold and the minimum request frequency threshold:
[0188] Obtain the current service request frequency of the interface response time and request number relationship model, and adjust the service request frequency of the interface response time and request number relationship model according to the current service request frequency, the maximum request frequency threshold, and the minimum request frequency threshold. The adjusted service request frequency of the interface response time and request number relationship model is max[min(current_qps, max_qps), min_qps], where current_qps is the current service request frequency, max_qps is the maximum request frequency threshold, and min_qps is the minimum request frequency threshold.
[0189] For the specific limitations on the steps implemented when the processor executes a computer program, please refer to the limitations on the dynamic current limiting method above, which will not be repeated here.
[0190] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0191] Get the historical average response time and historical service request frequency of the server interface;
[0192] A relationship model between interface response time and number of requests is constructed based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the relationship model between interface response time and number of requests is negatively correlated with the response time and the logic complexity of the interface;
[0193] After calling the interface through the target service request, the interface response time and the logic complexity of the interface are obtained, an adjustment factor is calculated according to the interface response time and the logic complexity of the interface, and the service request frequency of the relationship model between the interface response time and the number of requests is adjusted according to the adjustment factor;
[0194] The adjusted relationship model between the interface response time and the number of requests is used to control the service request frequency of the interface for responding to service requests.
[0195] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0196] The calculating of the adjustment factor according to the interface response time and the logic complexity of the interface includes:
[0197] Setting a value of a smoothing factor according to the logic complexity of the interface;
[0198] An expected interface response time is obtained, and an adjustment factor is calculated by dividing the interface response time by the expected interface response time and multiplying the smoothing factor.
[0199] Specifically, the adjustment factor is calculated as follows: adjustment_factor=response_time / target_response_time×complexity_factor, where adjustment_factor is the value of the adjustment factor, response_time is the interface response time, target_response_time is the expected interface response time, and complexity_factor is the smoothing factor.
[0200] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0201] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor comprises:
[0202] Get the value of the calculated adjustment factor;
[0203] If the calculated value of the adjustment factor is greater than 1, reducing the service request frequency of the interface response time and request number relationship model;
[0204] If the calculated value of the adjustment factor is less than 1, the service request frequency of the interface response time and request number relationship model is increased.
[0205] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0206] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0207] The current service request frequency of the interface response time and request number relationship model is obtained, and the service request frequency of the interface response time and request number relationship model is adjusted by dividing the current service request frequency by the value of the calculated adjustment factor.
[0208] Specifically, the service request frequency of the interface response time and request number relationship model is adjusted by current_qps / adjustment_factor, where current_qps is the current service request frequency and adjustment_factor is the value of the adjustment factor.
[0209] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0210] The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes:
[0211] Setting a control coefficient for controlling the service request frequency adjustment speed of the interface response time and request number relationship model to k, where k is a positive number less than 1;
[0212] The process of smoothly adjusting the service request frequency of the interface response time and request number relationship model is controlled by current_qps×(1-k)+(current_qps / adjustment_factor)×k, where current_qps is the current service request frequency of the interface response time and request number relationship model, and adjustment_factor is the calculated value of the adjustment factor.
[0213] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0214] The method further comprises:
[0215] Acquire a numerical range of a service request frequency of the interface according to a historical service request frequency of the interface, and set a maximum request frequency threshold and a minimum request frequency threshold based on the numerical range of the service request frequency of the interface;
[0216] The adjusted service request frequency of the interface response time and request number relationship model is set between the maximum request frequency threshold and the minimum request frequency threshold.
[0217] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0218] The service request frequency of the interface response time and request number relationship model after the setting adjustment includes between the maximum request frequency threshold and the minimum request frequency threshold:
[0219] Obtain the current service request frequency of the interface response time and request number relationship model, and adjust the service request frequency of the interface response time and request number relationship model according to the current service request frequency, the maximum request frequency threshold, and the minimum request frequency threshold. The adjusted service request frequency of the interface response time and request number relationship model is max[min(current_qps, max_qps), min_qps], where current_qps is the current service request frequency, max_qps is the maximum request frequency threshold, and min_qps is the minimum request frequency threshold.
[0220] For the specific limitations on the steps implemented when the computer program is executed by the processor, please refer to the limitations on the dynamic current limiting method above, which will not be repeated here.
[0221] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0222] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0223] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A dynamic current limiting method, characterized in that: include: Get the historical average response time and historical service request frequency of the server interface; A relationship model between interface response time and number of requests is constructed based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the relationship model between interface response time and number of requests is negatively correlated with the response time and the logic complexity of the interface; After calling the interface through the target service request, the interface response time and the logic complexity of the interface are obtained, an adjustment factor is calculated according to the interface response time and the logic complexity of the interface, and the service request frequency of the relationship model between the interface response time and the number of requests is adjusted according to the adjustment factor; The adjusted relationship model between the interface response time and the number of requests is used to control the service request frequency of the interface for responding to service requests.
2. The dynamic current limiting method according to claim 1, characterized in that: The calculating of the adjustment factor according to the interface response time and the logic complexity of the interface includes: Setting a value of a smoothing factor according to the logic complexity of the interface; An expected interface response time is obtained, and an adjustment factor is calculated by dividing the interface response time by the expected interface response time and multiplying the smoothing factor.
3. The dynamic current limiting method according to claim 2, characterized in that: The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor comprises: Get the value of the calculated adjustment factor; If the calculated value of the adjustment factor is greater than 1, reducing the service request frequency of the interface response time and request number relationship model; If the calculated value of the adjustment factor is less than 1, the service request frequency of the interface response time and request number relationship model is increased.
4. The dynamic current limiting method according to claim 3, characterized in that: The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes: The current service request frequency of the interface response time and request number relationship model is obtained, and the service request frequency of the interface response time and request number relationship model is adjusted by dividing the current service request frequency by the value of the calculated adjustment factor.
5. The dynamic current limiting method according to claim 3 or 4, characterized in that: The step of adjusting the service request frequency of the interface response time and request number relationship model according to the adjustment factor further includes: Setting a control coefficient for controlling the service request frequency adjustment speed of the interface response time and request number relationship model to k, where k is a positive number less than 1; The process of smoothly adjusting the service request frequency of the interface response time and request number relationship model is controlled by current_qps×(1-k)+(current_qps / adjustment_factor)×k, where current_qps is the current service request frequency of the interface response time and request number relationship model, and adjustment_factor is the calculated value of the adjustment factor.
6. The dynamic current limiting method according to claim 1, characterized in that: The method further comprises: Acquire a numerical range of a service request frequency of the interface according to a historical service request frequency of the interface, and set a maximum request frequency threshold and a minimum request frequency threshold based on the numerical range of the service request frequency of the interface; The adjusted service request frequency of the interface response time and request number relationship model is set between the maximum request frequency threshold and the minimum request frequency threshold.
7. The dynamic current limiting method according to claim 6, characterized in that: The service request frequency of the interface response time and request number relationship model after the setting adjustment includes between the maximum request frequency threshold and the minimum request frequency threshold: Obtain the current service request frequency of the interface response time and request number relationship model, and adjust the service request frequency of the interface response time and request number relationship model according to the current service request frequency, the maximum request frequency threshold, and the minimum request frequency threshold. The adjusted service request frequency of the interface response time and request number relationship model is max[min(current_qps, max_qps), min_qps], where current_qps is the current service request frequency, max_qps is the maximum request frequency threshold, and min_qps is the minimum request frequency threshold.
8. A dynamic current limiting device, characterized in that: The device comprises: A historical data acquisition module is used to obtain the historical average response time and historical service request frequency of the server interface; A relationship model building module is used to build an interface response time and request number relationship model based on the historical average response time of the interface and the historical service request frequency, wherein the service request frequency in the interface response time and request number relationship model is negatively correlated with the response time and the logic complexity of the interface; An adjustment relationship model module is used to obtain the interface response time and the logic complexity of the interface after calling the interface through the target service request, calculate the adjustment factor according to the interface response time and the logic complexity of the interface, and adjust the service request frequency of the interface response time and request number relationship model according to the adjustment factor; The service request frequency control module is used to control the service request frequency of the interface for responding to service requests by using the adjusted relationship model between the interface response time and the number of requests.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.