Dynamic current limiting method, apparatus, device, storage medium and program product
By dynamically adjusting the rate limiting threshold and sorting the access data from the traffic source, the problem of low rate limiting efficiency in existing technologies is solved, achieving a more efficient rate limiting effect and server stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU NETEASE CLOUD MUSIC TECH CO LTD
- Filing Date
- 2023-05-18
- Publication Date
- 2026-07-14
AI Technical Summary
Existing technologies are inefficient and have limited effectiveness in configuring rate limiting thresholds in mixed traffic scenarios, and cannot adapt to changes in server capabilities, resulting in poor rate limiting performance.
By acquiring access data from multiple traffic sources within the current time period, sorting and determining their respective rate-limiting thresholds, the rate-limiting strategy is dynamically adjusted to adapt to changes in server capacity.
It improves the flexibility, accuracy, and efficiency of rate limiting thresholds, enhances the rate limiting effect, and ensures stable server operation under high load.
Smart Images

Figure CN116566902B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network technology, and in particular to a dynamic rate limiting method, apparatus, device, storage medium, and program product. Background Technology
[0002] Rate limiting refers to restricting the number of requests flowing into a server. Servers have limited processing capacity. To protect servers from being overwhelmed by sudden surges in traffic and causing system crashes, self-protection components are often integrated at the system entry point. For example, rate limiting components are introduced into the server to implement rate limiting. When the number of requests received by the server exceeds the rate limiting threshold, the server can reject subsequent requests and quickly return a request failure message to the traffic source. This ensures that the server can continue to provide maximum service capacity even when receiving a high query per second (QPS), i.e., a large number of requests. The rate limiting threshold, also known as the rate limiting quota, represents the maximum number of requests allowed to access the server within a certain period. During rate limiting, the server consumes one rate limiting quota for each request received.
[0003] Mixed traffic refers to the request traffic received by a server when the requests come from multiple sources.
[0004] Currently, for mixed traffic, the common practice is to first assess server service capacity and perform performance stress tests, and then manually configure rate limiting thresholds for each traffic source based on historical experience. After that, the server needs to implement rate limiting based on the configured rate limiting thresholds.
[0005] However, when the server's service capacity changes, such as during scaling up or down, the rate limiting thresholds configured above become unsuitable for the current rate limiting requirements. This not only affects the rate limiting effect but also necessitates re-determining the rate limiting thresholds through the manual static configuration method described above. Clearly, this rate limiting method suffers from low efficiency and mediocre results. Summary of the Invention
[0006] This application provides a dynamic current limiting method, apparatus, device, storage medium, and program product, which can improve the flexibility, accuracy, and efficiency of determining the current limiting threshold, thereby improving the current limiting efficiency and effect.
[0007] In a first aspect, this application provides a dynamic rate limiting method, which includes: acquiring access data of multiple traffic sources within the current time period; sorting the multiple traffic sources according to the access data to obtain a sorting result; determining the rate limiting threshold of each of the multiple traffic sources according to the sorting result; determining the next time period; and in the next time period, rate limiting is applied to the multiple traffic sources according to the rate limiting threshold.
[0008] Optionally, the above-mentioned determination of the rate limiting thresholds for multiple traffic sources based on the sorting results includes: obtaining the total number of visits from multiple traffic sources and the number of visits from each traffic source within the current time period; calculating the rate limiting threshold for the first traffic source in the sorting results to obtain a first rate limiting threshold; calculating the difference between the number of visits from the first traffic source and the first rate limiting threshold to obtain a first difference; calculating the difference between the total number of visits and the first difference to obtain a second difference; if the second difference is less than or equal to a preset rate limiting threshold, then the rate limiting thresholds for the remaining traffic sources in the sorting results, excluding the first traffic source, are determined to be infinite; if the second difference is greater than the preset rate limiting threshold, then the first traffic source is removed from the sorting results to obtain an updated sorting result, the preset rate limiting threshold is updated using the difference between the preset rate limiting threshold and the first rate limiting threshold, the total number of visits is updated using the difference between the total number of visits and the number of visits from the first traffic source, and the calculation of the rate limiting threshold for the first traffic source in the sorting results continues until the second difference is less than or equal to the preset rate limiting threshold, thus obtaining the rate limiting thresholds for each of the multiple traffic sources.
[0009] Optionally, the first traffic limiting threshold is obtained by determining the first traffic source's traffic limiting weight in the above calculation and ranking results, including: determining the traffic limiting weight of the first traffic source; calculating the product of the first traffic source's access volume and the traffic limiting weight to obtain the first product; and determining the first traffic limiting threshold based on the first traffic source's access volume and the first product.
[0010] Optionally, determining the first rate limiting threshold based on the access volume of the first traffic source and the first product includes: calculating the difference between the total access volume and the preset rate limiting threshold to obtain a third difference; calculating the minimum value between the first product and the third difference to obtain a first value; and calculating the difference between the access volume of the first traffic source and the first value to obtain the first rate limiting threshold.
[0011] Optionally, determining the traffic limiting weight for the first traffic source includes: determining the importance level and business scenario corresponding to the first traffic source; and determining the traffic limiting weight based on the importance level and business scenario.
[0012] Optionally, the access data mentioned above includes at least one of the following: access volume, waiting time, and response time; wherein, the waiting time is the time interval between the time the request is sent and the time the request begins to be processed, and the response time is the time interval between the time the request is received and the time the request processing ends; the above-mentioned sorting of multiple traffic sources based on the access data to obtain a sorting result includes: sorting multiple traffic sources in descending order of their respective access volumes; or, sorting multiple traffic sources in descending order of their respective waiting times; or, sorting multiple traffic sources in descending order of their respective response times.
[0013] Optionally, determining the next time period as described above includes: obtaining access data from multiple traffic sources within a historical time period; and determining the next time period based on the access data from multiple traffic sources within a historical time period and the current time period.
[0014] Optionally, determining the next time period based on access data from multiple traffic sources within a historical time period and the current time period includes: analyzing access data from multiple traffic sources within a historical time period to determine a target duration, where the target duration represents the time interval between traffic peaks and traffic troughs; if the difference between the target duration and the current time period is less than a first duration, then the difference between the current time period and a second duration is determined as the duration of the next time period; if the difference between the target duration and the current time period is greater than or equal to the first duration, then the current time period is determined as the duration of the next time period.
[0015] Optionally, before sorting multiple traffic sources based on access data to obtain the sorting result, the method further includes: obtaining the traffic value within the current time period, where the traffic value represents the processing time of the request in the current time period; determining whether the traffic value is greater than a second value; the sorting of multiple traffic sources based on access data to obtain the sorting result includes: when the traffic value is greater than the second value, sorting the multiple traffic sources based on access data to obtain the sorting result.
[0016] Secondly, this application provides a dynamic rate limiting device, which includes: a first acquisition module, a sorting module, a first determination module, a second determination module, and a rate limiting module. The first acquisition module is used to acquire access data from multiple traffic sources within the current time period; the sorting module is used to sort the multiple traffic sources according to the access data to obtain a sorting result; the first determination module is used to determine the rate limiting threshold for each of the multiple traffic sources based on the sorting result; the second determination module is used to determine the next time period; and the rate limiting module is used to rate limit the multiple traffic sources according to the rate limiting threshold in the next time period.
[0017] Optionally, the first determining module described above is specifically used for: obtaining the total number of visits from multiple traffic sources and the number of visits from each of the multiple traffic sources within the current time period; calculating the rate limiting threshold for the first traffic source in the ranking result to obtain a first rate limiting threshold; calculating the difference between the number of visits from the first traffic source and the first rate limiting threshold to obtain a first difference; calculating the difference between the total number of visits and the first difference to obtain a second difference; if the second difference is less than or equal to a preset rate limiting threshold, then determining that the rate limiting thresholds for the remaining traffic sources in the ranking result, excluding the first traffic source, are infinity; if the second difference is greater than the preset rate limiting threshold, then removing the first traffic source from the ranking result to obtain an updated ranking result, updating the preset rate limiting threshold using the difference between the preset rate limiting threshold and the first rate limiting threshold, updating the total number of visits using the difference between the total number of visits and the number of visits from the first traffic source, and continuing to calculate the rate limiting threshold for the first traffic source in the ranking result until the second difference is less than or equal to the preset rate limiting threshold, thus obtaining the rate limiting thresholds for each of the multiple traffic sources.
[0018] Optionally, the first determining module is specifically used to: determine the rate limiting weight of the first traffic source; calculate the product of the access volume of the first traffic source and the rate limiting weight to obtain the first product; and determine the first rate limiting threshold based on the access volume of the first traffic source and the first product.
[0019] Optionally, the first determining module is specifically used to: calculate the difference between the total number of visits and the preset rate limiting threshold to obtain a third difference; calculate the minimum value between the first product and the third difference to obtain a first value; and calculate the difference between the number of visits from the first traffic source and the first value to obtain a first rate limiting threshold.
[0020] Optionally, the first determining module mentioned above is specifically used to: determine the importance level and business scenario corresponding to the first traffic source; and determine the traffic limiting weight based on the importance level and business scenario.
[0021] Optionally, the access data includes at least one of the following: access volume, waiting time, and response time; wherein, the waiting time is the time interval between the time the request is sent and the time the request begins to be processed, and the response time is the time interval between the time the request is received and the time the request processing ends; the sorting module is specifically used to: sort multiple traffic sources according to their respective access volumes in descending order, and obtain a sorting result; or, sort multiple traffic sources according to their respective waiting times in descending order, and obtain a sorting result; or, sort multiple traffic sources according to their respective response times in descending order, and obtain a sorting result.
[0022] Optionally, the second determining module described above is specifically used to: obtain access data from multiple traffic sources within a historical time period; and determine the next time period based on the access data from multiple traffic sources within a historical time period and the current time period.
[0023] Optionally, the second determining module is specifically used to: analyze access data from multiple traffic sources within a historical time period to determine a target duration, whereby the target duration represents the time interval between traffic peaks and traffic troughs; if the difference between the target duration and the duration of the current time period is less than a first duration, then the difference between the duration of the current time period and the second duration is determined as the duration of the next time period; if the difference between the target duration and the duration of the current time period is greater than or equal to the first duration, then the duration of the current time period is determined as the duration of the next time period.
[0024] Optionally, the dynamic rate limiting device further includes: a second acquisition module and a judgment module, wherein the second acquisition module is used to: acquire the traffic value within the current time period, the traffic value being used to characterize the processing time of the request in the current time period; the judgment module is used to: judge whether the traffic value is greater than a second value; the aforementioned sorting module is specifically used to: when the traffic value is greater than the second value, sort the multiple traffic sources according to the access data to obtain a sorting result.
[0025] Thirdly, this application provides an electronic device, including: a processor and a memory, the memory for storing a computer program, and the processor for calling and running the computer program stored in the memory to perform the methods as described in the first aspect or its various implementations.
[0026] Fourthly, this application provides a computer-readable storage medium for storing a computer program that causes a computer to perform the methods described in the first aspect or its various implementations.
[0027] Fifthly, this application provides a computer program product including computer program instructions that cause a computer to perform the methods as described in the first aspect or its various implementations.
[0028] Sixthly, this application provides a computer program that causes a computer to perform the methods described in the first aspect or its various implementations.
[0029] Through the technical solution of this application, the electronic device can first obtain access data from multiple traffic sources within the current time period. Then, the electronic device can sort the multiple traffic sources based on the access data to obtain a sorting result. Next, the electronic device can determine the rate limiting threshold for each of the multiple traffic sources based on the sorting result. Then, the electronic device can determine the next time period and, in the next time period, rate limiting is applied to the multiple traffic sources based on their respective rate limiting thresholds. In the above process, because the service capacity of the electronic device changes, such as when the electronic device expands or shrinks, the access data within the current time period will change accordingly. Therefore, the access data within the current time period can accurately and in real-time reflect the rate limiting demand in the next time period, thereby improving the flexibility, accuracy, and efficiency of determining the rate limiting threshold, and thus improving the rate limiting efficiency and effect. Attached Figure Description
[0030] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1 An application scenario diagram provided for an embodiment of this application;
[0032] Figure 2 A flowchart of a dynamic current limiting method provided in an embodiment of this application;
[0033] Figure 3 A schematic diagram illustrating a dynamic current limiting method provided in an embodiment of this application;
[0034] Figure 4 A schematic diagram of a dynamic current limiting device 400 provided in an embodiment of this application;
[0035] Figure 5 This is a schematic block diagram of an electronic device 500 provided in an embodiment of this application. Detailed Implementation
[0036] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0037] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0038] As mentioned above, the existing technology for determining the current limiting threshold suffers from low current limiting efficiency and mediocre current limiting effect.
[0039] To address the aforementioned technical problems, the inventive concept of this application is that an electronic device can determine the respective rate-limiting thresholds for multiple traffic sources in the next time period based on access data from multiple traffic sources within the current time period. This improves the flexibility, accuracy, and efficiency of determining the rate-limiting thresholds, thereby enhancing rate-limiting efficiency and effectiveness.
[0040] It should be understood that the technical solution of this application can be applied to the following scenarios, but is not limited to:
[0041] In some possible implementations, this application can be applied to rate limiting scenarios involving multiple traffic sources, but is not limited to this. For example, the rate limiting scenario can be a mixed traffic scenario: when multiple traffic sources send requests to the same server, the server can determine the rate limiting threshold for each of the multiple traffic sources, and based on the rate limiting threshold, process the requests sent by the multiple traffic sources by rejecting or responding to them.
[0042] In some possible ways, Figure 1 An application scenario diagram provided for an embodiment of this application, such as... Figure 1As shown, this application scenario may include an electronic device 110 and multiple terminal devices 120. The electronic device 110 can establish a connection with the multiple terminal devices 120 via a wired or wireless network. Then, the multiple terminal devices 120 can send requests to the electronic device 110. Based on the access data of the multiple terminal devices 120 in the current time period, the electronic device 110 determines the respective rate-limiting threshold for each of the multiple terminal devices 120 in the next time period, and applies rate-limiting to the multiple terminal devices 120 in the next time period according to the rate-limiting threshold. For example, the electronic device 110 can reject or respond to the requests sent by the multiple terminal devices 120.
[0043] For example, the multiple terminal devices 120 can be multiple traffic sources in this application. The terminal devices 120 can be mobile phones, desktop computers, laptops, tablets, etc., but are not limited to these. The electronic device 110 can be a server, a server cluster composed of multiple servers, or a cloud platform control center, but is not limited to these.
[0044] also, Figure 1 The number of electronic devices and terminal devices is merely exemplary and may actually include other numbers of electronic devices and terminal devices, which is not limited in this application.
[0045] After introducing the application scenarios of the embodiments of this application, the technical solution of this application will be described in detail below:
[0046] Figure 2 A flowchart of a dynamic current limiting method provided in this application embodiment is shown. This method can be performed by, for example... Figure 1 The electronic device 110 shown performs, but is not limited to, its functions. For example... Figure 2 As shown, the method may include the following steps:
[0047] S210: Obtain access data from multiple traffic sources within the current time period;
[0048] S220: Based on the access data, sort the multiple traffic sources to obtain the sorting results;
[0049] S230: Based on the sorting results, determine the flow limiting thresholds for each of the multiple traffic sources;
[0050] S240: Determine the next time period;
[0051] S250: In the next time period, traffic will be limited for multiple traffic sources based on the traffic limiting threshold.
[0052] In some implementation methods, multiple traffic sources can add traffic source identifiers to requests sent to electronic devices according to the setting rules of traffic source identifiers. The electronic devices may include rate limiting components. The rate limiting components can parse the traffic source identifiers from the requests sent by multiple traffic sources according to the setting rules of traffic source identifiers. Then, based on the traffic source identifiers, they can perform statistics on the access data and total access data of each of the multiple traffic sources in the current time period. The setting rules of traffic source identifiers are pre-set rules and conventions that traffic sources and electronic devices must follow to complete the sending or responding of requests.
[0053] For example, the traffic source may set the traffic source identifier in the request header of the request data sent to the electronic device, or in a field of the request data, but is not limited thereto.
[0054] For example, the traffic source identifier can be the name, address, or other information that can uniquely identify the traffic source, and this application does not impose any restrictions on this. For instance, in a scenario of processing log data, assuming the traffic source is a microservice application device, when the microservice application device sends log data to an electronic device, it can determine the application name of the microservice application device as the traffic source identifier and embed it in the log data to be sent.
[0055] For example, access data may be at least one of the following, but not limited to: access volume, waiting time, and response time, wherein the waiting time is the time interval between the time the request is sent and the time the request begins to be processed, the response time is the time interval between the time the request is received and the time the request processing ends, and the access volume may be the number of requests sent.
[0056] In some possible implementations, before the above-mentioned S220, it may also include: obtaining the traffic value within the current time period, the traffic value being used to characterize the processing time of the request in the current time period, and determining whether the traffic value is greater than a second value. Accordingly, the above-mentioned S220 may include: when the traffic value is greater than the second value, sorting the multiple traffic sources according to the access data to obtain the sorting result.
[0057] For example, an electronic device may determine a second value as the average, maximum, median, or minimum of the traffic flow values over multiple historical time periods.
[0058] For example, an electronic device can determine the traffic value based on the access data from multiple traffic sources within the current time period. For instance, when the access data is the number of visits, the electronic device can determine the traffic value for the current time period by summing the visits from multiple traffic sources, or by determining the largest or smallest visits from multiple traffic sources. When the access data is the waiting time, the electronic device can determine the traffic value for the current time period by summing the waiting times from multiple traffic sources, or by determining the largest or smallest waiting time from multiple traffic sources. When the access data is the response time, the electronic device can determine the traffic value for the current time period by summing the response times from multiple traffic sources, or by determining the largest or smallest response time from multiple traffic sources.
[0059] It is understandable that the higher the traffic volume in the current time period, the greater the service pressure on the electronic device. Therefore, the electronic device can limit the traffic source in the next time period to protect the electronic device from being overwhelmed by a sudden increase in traffic and causing system paralysis.
[0060] Optionally, for any target traffic source among multiple traffic sources, the electronic device can determine the average access volume of each target traffic source over multiple historical time periods as the target traffic source's regular access volume. Then, the electronic device can send an inquiry message to the target traffic source to determine the number of requests the target traffic source needs to send to the electronic device within the current time period. Upon receiving the inquiry message, the target traffic source can estimate the number of requests it needs to send to the electronic device within the current time period and send this estimated number to the electronic device. After receiving the estimated number from the target traffic source, the electronic device can determine whether the difference between the estimated number and the regular number is less than an abnormal difference. If the difference is less than the abnormal difference, the electronic device can determine that the target traffic source is a regular traffic source; if the difference is greater than or equal to the abnormal difference, the electronic device can determine that the target traffic source is an unregular traffic source. Subsequently, if the electronic device determines that multiple traffic sources are all regular traffic sources, then when determining the traffic value based on the access data of each traffic source within the current time period, the electronic device can determine the traffic value for the current time period based on the largest access volume among the multiple traffic sources, or the largest waiting time among the multiple traffic sources, or the largest response time among the multiple traffic sources. If the electronic device determines that multiple traffic sources are not all regular traffic sources, then when determining the traffic value based on the access data of each traffic source within the current time period, the electronic device can determine the traffic value for the current time period based on the smallest access volume among the multiple traffic sources, or the smallest waiting time among the multiple traffic sources, or the smallest response time among the multiple traffic sources.
[0061] Understandably, if the electronic device determines that multiple traffic sources are all regular traffic sources, then the electronic device can estimate that the number of requests sent by multiple traffic sources to the electronic device in the current time period is close to or equal to the regular number. That is, the electronic device can estimate that the access volume of multiple traffic sources in the current time period will not cause excessive service pressure on the electronic device. Then, the electronic device only needs to determine whether the largest access volume, the largest waiting time, or the largest response time among the multiple traffic sources is greater than the second value. If the largest access volume, the largest waiting time, or the largest response time among the multiple traffic sources is greater than the second value, then the electronic device can determine that the requests sent by the data source corresponding to the largest access volume, the largest response time, or the largest waiting time in the current time period will cause increased service pressure on the electronic device, thereby determining that rate limiting is necessary, and thus the above S220 can be executed. If the largest access volume among multiple traffic sources, or the largest waiting time among multiple traffic sources, or the largest response time among multiple traffic sources, is less than or equal to the second value, then the electronic device can determine that the requests sent by the data source corresponding to the largest access volume, or the largest response time, or the largest waiting time within the current time period will not increase the service pressure on the electronic device. Thus, it can be determined that the requests sent by multiple traffic sources within the current time period will not cause excessive service pressure on the electronic device. Therefore, the electronic device can choose not to perform rate limiting, i.e., it does not need to execute the above S220.
[0062] If an electronic device determines that multiple traffic sources are not all regular traffic sources, it can predict that at least one of these sources is an unconventional one, and the number of requests it needs to send to the device within the current time frame is greater than the regular number. In other words, the electronic device can predict that at least one unconventional source will cause excessive service pressure on the device during the current time period. Therefore, the electronic device can then determine whether the minimum access volume, minimum waiting time, or minimum response time among the multiple traffic sources is greater than the minimum access volume or response time. Regarding the second value, if the minimum access volume among the multiple traffic sources, or the minimum waiting time among the multiple traffic sources, or the minimum response time among the multiple traffic sources is greater than the second value, then the electronic device can determine that the requests sent by the data source corresponding to the minimum access volume, or the minimum response time, or the minimum waiting time will also cause an increase in the service pressure of the electronic device within the current time period. Therefore, the electronic device can determine that the requests sent by multiple traffic sources within the current time period all cause an increase in the service pressure of the electronic device, and thus the electronic device can determine that rate limiting is required, i.e., it can execute the above S220. If the minimum access volume among multiple traffic sources, or the minimum waiting time among multiple traffic sources, or the minimum response time among multiple traffic sources, is less than or equal to the second value, then the electronic device can determine that the request sent by the data source corresponding to the minimum access volume, or the minimum response time, or the minimum waiting time within the current time period will not cause an increase in the service pressure of the electronic device. Therefore, the electronic device can determine that at least one data source among the multiple traffic sources will not cause an increase in the service pressure of the electronic device within the current time period. Thus, it can be determined that the service capacity within the current time period is stable, and rate limiting can be omitted, i.e., the above S220 is not executed.
[0063] In some possible implementations, when the access data includes at least one of the following: access volume, waiting time, and response time, the above-mentioned S220 may include: sorting multiple traffic sources according to the order of their respective access volumes from largest to smallest, and obtaining a sorting result; or, sorting multiple traffic sources according to the order of their respective waiting times from largest to smallest, and obtaining a sorting result; or, sorting multiple traffic sources according to the order of their respective response times from largest to smallest, and obtaining a sorting result.
[0064] For example, suppose there are multiple traffic sources including: traffic source 1, traffic source 2 and traffic source 3, and the number of visits to these three traffic sources are 10, 20 and 15 respectively. Then the electronic device can sort the above three traffic sources in descending order of the number of visits, and the sorting result is: traffic source 2, traffic source 3 and traffic source 1.
[0065] In other possible implementations, electronic devices can also sort multiple traffic sources according to the order of access volume from smallest to largest, the order of waiting time from smallest to largest, or the order of response time from smallest to largest.
[0066] Optionally, referring to the above embodiments, the electronic device can first determine whether multiple traffic sources are all regular traffic sources. If it is determined that multiple traffic sources are all regular traffic sources, the electronic device can sort the multiple traffic sources according to the order of their respective access volume from largest to smallest, waiting time from largest to smallest, or response time from largest to smallest. If it is determined that multiple traffic sources are not all regular traffic sources, the electronic device can sort the multiple traffic sources according to the order of their respective access volume from smallest to largest, waiting time from smallest to largest, or response time from smallest to largest.
[0067] Understandably, if an electronic device determines that multiple traffic sources are not all regular traffic sources, it can predict that at least one of these sources is an unconventional one that needs to send more requests to the device within the current time period than the regular ones. In other words, the electronic device can predict that at least one unconventional source will cause excessive service pressure on the device during the current time period. Therefore, the electronic device can prioritize triggering rate limiting policies for traffic sources with lower access volumes, shorter waiting times, or shorter response times, and determine their rate limiting thresholds. This allows the electronic device to prioritize processing requests from at least one unconventional source, enabling these sources to obtain services from the electronic device more efficiently and thus satisfying their needs more effectively.
[0068] If an electronic device determines that multiple traffic sources are all regular traffic sources, it can estimate that the number of requests sent by these traffic sources to the device within the current time period will be close to or equal to the regular number. In other words, the electronic device can estimate that the access volume from these traffic sources within the current time period will not cause excessive pressure on its service. Therefore, the electronic device can prioritize triggering rate limiting policies for traffic sources with higher access volumes, longer waiting times, or longer response times, and determine their rate limiting thresholds. This allows for faster determination of rate limiting thresholds, ensuring that other traffic sources can access the electronic device normally and quickly.
[0069] In the above embodiments, using access volume, waiting time, or response time as statistical measures can be applied to various rate limiting scenarios. It can not only accurately describe the service pressure of electronic devices in the current time period, but also accurately sort multiple traffic sources, and then determine the rate limiting threshold based on the accurate sorting results, thereby further improving rate limiting efficiency.
[0070] It should be noted that this application does not impose any restrictions on the specific content and determination method of access data, traffic values, second values, and sorting results.
[0071] In some possible implementations, S230 above may include: obtaining the total number of visits from multiple traffic sources and the number of visits from each of the multiple traffic sources within the current time period; calculating the rate limiting threshold for the first traffic source in the ranking result to obtain a first rate limiting threshold; calculating the difference between the number of visits from the first traffic source and the first rate limiting threshold to obtain a first difference; calculating the difference between the total number of visits and the first difference to obtain a second difference; if the second difference is less than or equal to a preset rate limiting threshold, then determining that the rate limiting thresholds for the remaining traffic sources in the ranking result other than the first traffic source are infinite; if the second difference is greater than the preset rate limiting threshold, then removing the first traffic source from the ranking result to obtain an updated ranking result, updating the preset rate limiting threshold using the difference between the preset rate limiting threshold and the first rate limiting threshold, updating the total number of visits using the difference between the total number of visits and the number of visits from the first traffic source, and continuing to calculate the rate limiting threshold for the first traffic source in the ranking result until the second difference is less than or equal to the preset rate limiting threshold, and obtaining the rate limiting thresholds for each of the multiple traffic sources. The preset rate limiting threshold can refer to the maximum total number of visits from multiple traffic sources when the electronic device implements rate limiting in the next time period.
[0072] For example, the preset rate limit can be the same as or different from the second value mentioned above, and this application does not impose any restrictions on this.
[0073] For example, suppose the preset rate limiting threshold is 40, and multiple traffic sources include: Traffic Source 1, Traffic Source 2, and Traffic Source 3. In the current time period, the access volumes of these three traffic sources are 10, 20, and 15 respectively, and the total access volume in the current time period is 10 + 20 + 15 = 45. The three traffic sources are sorted according to their access volumes from largest to smallest, resulting in the sorted order: Traffic Source 2, Traffic Source 3, Traffic Source 1. In this sorted order, the first traffic source is Traffic Source 2. The electronic device calculates the rate limiting threshold for Traffic Source 2, i.e., the first rate limiting threshold is 18. The difference between the access volume of Traffic Source 2 and this first rate limiting threshold is calculated, resulting in the first difference value of 20 - 18 = 2. The difference between the total access volume and the first difference value is calculated, i.e., the second difference value of 45 - 2. =43. This second difference can be understood as: the expected total number of visits after limiting the first traffic source in the ranking results in the next time period. If the expected total number of visits is less than or equal to the preset limiting threshold, it means that in the next time period, the electronic device only needs to limit the first traffic source in the ranking results to ensure that the total number of visits is likely to be less than or equal to the preset limiting threshold, thus effectively ensuring the limiting effect. If the expected total number of visits is greater than the preset limiting threshold, the electronic device also needs to limit the other traffic sources in the ranking results to ensure that the total number of visits is likely to be less than or equal to the preset limiting threshold in the next time period, thus effectively ensuring the limiting effect. Therefore, after calculating the second difference, the electronic device needs to compare the second difference with the preset limiting threshold. Obviously, the second difference at this time is greater than the preset traffic limiting threshold: 43 > 40. Therefore, the electronic device can remove the first traffic source from the sorting results, that is, remove traffic source 2 from the sorting results: traffic source 2, traffic source 3, traffic source 1, and get the updated sorting results as: traffic source 3, traffic source 1. Then, update the preset traffic limiting threshold using the difference between the preset traffic threshold and the first traffic limiting threshold, that is, update the preset traffic limiting threshold 40 using 40-18=22, and get the updated preset traffic limiting threshold as 22. Finally, update the total number of visits using the difference between the total number of visits and the number of visits from the first traffic source, that is, update the total number of visits 45 using 45-20=25, and get the updated total number of visits as 25.Understandably, since the second difference mentioned above is greater than the preset rate limiting threshold, the electronic device needs to rate limit other traffic sources in the original ranking results. When determining the rate limiting threshold for other traffic sources, the electronic device can remove the traffic source with the already determined rate limiting threshold, i.e., traffic source 2, from the original ranking results to obtain the updated ranking results. This allows the rate limiting threshold for the first traffic source in the updated ranking results to be determined according to the method used to determine the rate limiting threshold for traffic source 2. Moreover, after removing the first traffic source from the original ranking results, the total number of visits and the preset rate limiting threshold corresponding to the updated ranking results will also change. Therefore, the total number of visits and the preset rate limiting threshold need to be updated accordingly. After determining the updated sorting results, the updated total visits, and the updated preset rate limiting threshold, the electronic device can continue to perform the above-mentioned "calculation of the rate limiting threshold of the first traffic source in the sorting results" until the second difference is less than or equal to the preset rate limiting threshold: After removing traffic source 2, the electronic device can determine that the first traffic source in the current sorting results is traffic source 3. Assuming that the rate limiting threshold of traffic source 3, i.e., the first rate limiting threshold at this time, is 10, the electronic device can calculate the difference between the visits of traffic source 3 and the first rate limiting threshold, and obtain the first difference at this time as 15-10=5. Calculate the difference between the total visits and the first difference, i.e., the second difference as 25-5=20. Then, the electronic device can determine that the second difference is less than or equal to the preset rate limiting threshold: 20≤22. Therefore, it can be determined that the rate limiting threshold of each of the other traffic sources in the sorting results, except for the first traffic source, is infinite. That is, the rate limiting threshold of traffic source 1 is determined to be infinite. In other words, the electronic device can not rate limit traffic source 1.
[0074] For example, an electronic device can determine the first rate limiting threshold by: determining the rate limiting weight of the first traffic source, calculating the product of the access volume of the first traffic source and the rate limiting weight to obtain the first product, and determining the first rate limiting threshold based on the access volume of the first traffic source and the first product. Specifically, the electronic device can first determine the importance level and business scenario corresponding to the first traffic source, and then determine the rate limiting weight based on the importance level and business scenario.
[0075] Optionally, the electronic device can determine the importance level of the traffic source based on the request type sent by the traffic source. Different request types can correspond to different importance levels, and different importance levels can correspond to different numerical values. Similarly, different business scenarios can also correspond to different numerical values. Then, the electronic device can determine the rate limiting weight based on the numerical value corresponding to the importance level (value 1) and the numerical value corresponding to the business scenario (value 2). For example, the electronic device can determine the rate limiting weight by the sum of numerical values 1 and 2, or by the difference between 1 and the sum of numerical values 1 and 2, or by the maximum, minimum, or average value of numerical values 1 and 2. For instance, suppose the request type from traffic source 2 is request data 1, the importance level corresponding to this request type is level 1, and the numerical value 1 corresponding to level 1 is 0.03. Traffic source 2 sends this request type to the electronic device under business scenario 1, and the numerical value 2 corresponding to business scenario 1 is 0.07. The electronic device can determine the rate limiting weight for traffic source 2 by the sum of numerical values 1 and 2: 0.03 + 0.07 = 0.1.
[0076] Optionally, the rate limiting weight can be a value between 0 and 1.
[0077] Optionally, the electronic device can determine whether the importance level of the first traffic source is greater than a preset level. If the importance level of the first traffic source is greater than the preset level, the electronic device may not limit the flow of the first traffic source, thus determining the flow limit threshold for the first traffic source to be infinite. If the importance level of the first traffic source is less than or equal to the preset level, the electronic device can determine the flow limit threshold for the first traffic source using the method described above. It is understandable that when the importance level of the first traffic source is high, the electronic device can determine that the first traffic source is a relatively important traffic source, and thus the electronic device can limit the flow of other traffic sources but not that of this traffic source, ensuring that the traffic source can access the electronic device normally.
[0078] Optionally, determining the first rate-limiting threshold based on the access volume of the first traffic source and the first product can include: calculating the difference between the total access volume and the preset rate-limiting threshold to obtain a third difference; calculating the minimum value between the first product and the third difference to obtain a first value; and calculating the difference between the access volume of the first traffic source and the first value to obtain the first rate-limiting threshold. For example, assuming the total access volume is 45, the preset rate-limiting threshold is 40, the first traffic source is traffic source 2, the access volume of traffic source 2 is 20, and the rate-limiting weight of traffic source 2 is 0.1, then the third difference is 45-40=5, the first product is 20*0.1=2, the minimum value between the first product and the third difference, i.e., the first value, is 2, and the difference between the access volume of traffic source 3 and the first value, i.e., the first rate-limiting threshold, is 20-2=18.
[0079] Understandably, the difference between the total number of visits and the preset rate limiting threshold, i.e., the third difference, can represent: taking the total number of visits in the current time period as a reference, in order to ensure the rate limiting effect in the next time period, the electronic device should reduce the number of visits at least in the next time period. The product of the rate limiting weight and the number of visits from the first traffic source, i.e., the first product, can represent: when rate limiting is applied to the traffic source, the appropriate number of visits that can be reduced is. Therefore, by comparing the size of the third difference and the first product, the minimum value between the first product and the third difference is determined, i.e., the first value. Then, based on the difference between the number of visits from the first traffic source and the first value, the first rate limiting threshold is determined. This can avoid setting the rate limiting threshold too high or too low, that is, a more reasonable rate limiting threshold can be determined to ensure a better rate limiting effect.
[0080] For example, such as Figure 3As shown, assuming the total number of visits in the current time period is Q, and there are n traffic sources, where n is a positive integer and Q(limit) is the second value, and the preset rate limiting threshold is Q0(limit), after sorting the visits of the n traffic sources in descending order, the visits of the first to the nth traffic sources in the sorted result are Q1, Q2, ..., Qn, respectively. The rate limiting thresholds of the first to the nth traffic sources in the sorted result are Q1(limit), Q2(limit), ..., Qn(limit), respectively. The electronic device can first determine whether Q is greater than Q(limit). If Q is less than or equal to Q(limit), the electronic device can choose not to rate limit the above n traffic sources in the next time period. In other words, the electronic device can determine that the rate limiting thresholds of the n traffic sources in the sorted result are infinite, that is, Q1(limit), Q2(limit), ..., Qn(limit) are all infinite. If Q is greater than Q(limit), the electronic device can calculate the flow limiting threshold Q1(limit) of the first flow source in the sorting result according to formula (1).
[0081] Q1(limit)=Q1-min[Q-Q0(limit), Q1*(1-factor)] formula (1)
[0082] In formula (1), factor is an influence factor, which represents the importance level of the traffic source. The value range of factor is [0, 1]. When factor is 0, it means that the traffic source is a relatively ordinary traffic source, and its traffic limiting threshold can be set to 0. When factor is 1, it means that the traffic source is a relatively important traffic source, and its traffic limiting threshold can be set to the number of visits in the current time period. Alternatively, it can be left unlimited, that is, Q1(limit) can be set to infinity.
[0083] Next, the electronic device can calculate the total number of accesses after the above-mentioned rate limiting, i.e., the second difference Q0, according to Formula 2.
[0084] Q0=Q-(Q1-Q1(limit)) formula (2)
[0085] In formula (2), if Q1(limit) is determined to be infinite in the above process, then the value of Q1(limit) in formula (2) is Q1.
[0086] Next, the electronic device can determine whether Q0 is greater than Q0(limit). If Q0 is less than or equal to Q0(limit), the electronic device can choose not to limit the flow of the other n flow sources except the first flow source in the next time period. In other words, the electronic device can determine that the flow limit threshold of the first flow source in the sorting result is Q1(limit) determined by the above method, and the flow limit threshold of the other flow sources except the first flow source is infinity. That is, Q1(limit) is determined to be the value determined by the above method, and Q2(limit), ..., Qn(limit) are all infinity. If Q0 is greater than Q0(limit), the electronic device can remove the first traffic source from the sorting result, obtain the updated sorting result, and update Q and Q0(limit). It continues to execute the step of "the electronic device can calculate the flow limit threshold Q1(limit) of the first traffic source in the sorting result according to formula (1)" until Q0 is less than or equal to Q0(limit). It outputs Q1(limit), Q2(limit), ..., Qn(limit) and, based on Q1(limit), Q2(limit), ..., Qn(limit) determined by the above method, it limits the flow of n traffic sources in the next time period.
[0087] In each subsequent time period, the electronic device can repeat the above calculation process to dynamically update the rate limiting thresholds for multiple traffic sources. Of course, the rate limiting thresholds for multiple traffic sources in the current time period can be determined by the electronic device based on the access data in the previous time period, according to the method described above.
[0088] In the above embodiments, since the access data in the current time period can accurately and in real time reflect the rate limiting demand in the next time period, determining the rate limiting threshold in the next time period based on the access data in the current time period, i.e., predicting the rate limiting threshold in the next time period, can not only ensure the accuracy of the rate limiting threshold determination, but also ensure the real-time performance of the rate limiting threshold. In other words, through the above method, the electronic device can dynamically adjust the rate limiting threshold in the next time period, ensuring the service stability of the electronic device, reducing the manpower cost of rate limiting configuration, making the entire rate limiting process more automated and easier to maintain, and improving the flexibility, accuracy, and efficiency of determining the rate limiting threshold.
[0089] Furthermore, electronic devices can prioritize triggering rate limiting strategies for top-ranked traffic sources based on the ranking results, determining their rate limiting thresholds. This ensures that the total traffic in the next time period can be kept within the rate limiting threshold more quickly during the calculation process, improving the speed of determining the rate limiting threshold. For example, when the ranking results are determined in descending order of access volume, waiting time, or response time, electronic devices can prioritize determining the rate limiting threshold for traffic sources that take longer to process, thus completing the rate limiting threshold determination more quickly and improving the speed of rate limiting threshold determination.
[0090] In some possible implementations, S240 may include: acquiring access data from multiple traffic sources within a historical time period; and determining the next time period based on the access data from multiple traffic sources within the historical time period and the current time period.
[0091] For example, an electronic device can analyze access data from multiple traffic sources over a historical time period to determine a target duration. The target duration represents the time interval between traffic peaks and low traffic periods. Then, the electronic device calculates the difference between the target duration and the duration of the current time period. If the difference between the target duration and the duration of the current time period is less than a first duration, the difference between the duration of the current time period and a second duration is determined as the duration of the next time period. If the difference between the target duration and the duration of the current time period is greater than or equal to the first duration, the duration of the current time period is determined as the duration of the next time period.
[0092] Understandably, when the time period is short, electronic devices can respond more sensitively to traffic peaks, meaning they can quickly determine the rate-limiting threshold for the traffic source corresponding to larger access data and apply rate limiting accordingly. However, this involves relatively high computational costs. When the time period is long, the electronic devices are less sensitive to rate limiting the traffic source corresponding to larger access data, resulting in poor rate limiting effectiveness. Setting the duration of each time period to the same short duration increases computational costs; setting the duration of each time period to the same long duration reduces rate limiting sensitivity and affects rate limiting effectiveness. Therefore, electronic devices can dynamically adjust the rate limiting window according to the method provided in this application, i.e., dynamically adjust the duration of each time period. This not only reduces computational costs and improves rate limiting efficiency but also ensures rate limiting sensitivity and effectiveness.
[0093] In reality, data traffic generally exhibits fluctuation patterns. The time interval between traffic peaks (i.e., peak periods) and troughs (i.e., low periods) typically falls within a fixed range. In other words, access data from multiple traffic sources follows a fluctuation pattern, with the time interval between the maximum access data and its adjacent minimum access data corresponding to a fixed range. The maximum access data can be the maximum total access volume, maximum total response time, or maximum total waiting time, while the minimum access data can be the minimum total access volume, minimum total response time, or minimum total waiting time. Therefore, electronic devices can analyze access data from multiple traffic sources over historical time periods to determine the fluctuation patterns of access data from these sources. Specifically, taking access data as an example, the electronic device can first obtain the total access volume of each historical time period in multiple historical time periods. The total access volume that is greater than a first preset access volume is determined as the maximum access volume, and the total access volume that is less than a second preset access volume is determined as the minimum access volume. Then, the electronic device can determine the time interval corresponding to each maximum access data and its adjacent minimum access data, and determine multiple time intervals. Finally, the electronic device can determine the maximum value, minimum value, median value, average value, etc. of the above time intervals as the target duration.
[0094] Assuming the time interval between traffic peaks and troughs is ten minutes, and the current time period is also ten minutes long, if the duration of the next time period is also set to ten minutes, then when the current time period is during a traffic peak, the electronic device will calculate the flow-limiting threshold for the next time period and trigger flow-limiting in that period. However, according to the traffic fluctuation rules—the time interval between traffic peaks and troughs is ten minutes—it can be determined that the next time period is during a traffic trough. Obviously, there is no need to limit flow in the next time period, resulting in false flow-limiting. Therefore, determining the duration of the next time period has a significant impact on the actual flow-limiting effect.
[0095] Therefore, in the method provided in this application, the electronic device can first analyze the pattern of accessed data and determine the target duration. If the difference between the current time period and the target duration is small, that is, the difference between the current time period and the target duration is less than the first duration, the electronic device can appropriately reduce the duration of the current time period and determine the duration of the next time period after the reduction. In other words, the difference between the current time period and the second duration is determined as the duration of the next time period, thereby improving the sensitivity of rate limiting and quickly determining the rate limiting threshold of the next time period, so as to quickly implement rate limiting in the next time period and ensure the rate limiting effect. If the difference between the current time period and the target duration is large, that is, the difference between the current time period and the target duration is greater than or equal to the first duration, the electronic device can keep the duration of the two consecutive time periods consistent, that is, determine the duration of the current time period as the duration of the next time period.
[0096] Figure 4 This is a schematic diagram of a dynamic current limiting device 400 provided in an embodiment of this application. Figure 4 As shown, the dynamic rate limiting device 400 includes: a first acquisition module 410, a sorting module 420, a first determination module 430, a second determination module 440, and a rate limiting module 450. The first acquisition module 410 is used to acquire access data from multiple traffic sources within the current time period; the sorting module 420 is used to sort the multiple traffic sources according to the access data to obtain a sorting result; the first determination module 430 is used to determine the rate limiting threshold for each of the multiple traffic sources based on the sorting result; the second determination module 440 is used to determine the next time period; and the rate limiting module 450 is used to rate limit the multiple traffic sources in the next time period according to the rate limiting threshold.
[0097] In some possible implementations, the first determining module 430 is specifically used to: obtain the total number of visits from multiple traffic sources and the number of visits from each of the multiple traffic sources within the current time period; calculate the rate limiting threshold for the first traffic source in the ranking result to obtain a first rate limiting threshold; calculate the difference between the number of visits from the first traffic source and the first rate limiting threshold to obtain a first difference; calculate the difference between the total number of visits and the first difference to obtain a second difference; if the second difference is less than or equal to a preset rate limiting threshold, then determine that the rate limiting thresholds for the remaining traffic sources in the ranking result, excluding the first traffic source, are infinity; if the second difference is greater than the preset rate limiting threshold, then remove the first traffic source from the ranking result to obtain an updated ranking result, update the preset rate limiting threshold using the difference between the preset rate limiting threshold and the first rate limiting threshold, update the total number of visits using the difference between the total number of visits and the number of visits from the first traffic source, and continue to calculate the rate limiting threshold for the first traffic source in the ranking result until the second difference is less than or equal to the preset rate limiting threshold, and obtain the rate limiting thresholds for each of the multiple traffic sources.
[0098] In some possible implementations, the first determining module 430 is specifically used to: determine the rate limiting weight of the first traffic source; calculate the product of the access volume of the first traffic source and the rate limiting weight to obtain a first product; and determine a first rate limiting threshold based on the access volume of the first traffic source and the first product.
[0099] In some possible implementations, the first determining module 430 is specifically used to: calculate the difference between the total number of visits and the preset rate limiting threshold to obtain a third difference; calculate the minimum value between the first product and the third difference to obtain a first value; and calculate the difference between the number of visits from the first traffic source and the first value to obtain a first rate limiting threshold.
[0100] In some implementation methods, the first determining module 430 is specifically used to: determine the importance level and business scenario corresponding to the first traffic source; and determine the traffic limiting weight based on the importance level and business scenario.
[0101] In some possible implementations, the access data includes at least one of the following: access volume, waiting time, and response time; wherein, the waiting time is the time interval between the time the request is sent and the time the request begins to be processed, and the response time is the time interval between the time the request is received and the time the request processing ends; the sorting module 420 is specifically used to: sort multiple traffic sources according to the order of their respective access volumes from largest to smallest, and obtain a sorting result; or, sort multiple traffic sources according to the order of their respective waiting times from largest to smallest, and obtain a sorting result; or, sort multiple traffic sources according to the order of their respective response times from largest to smallest, and obtain a sorting result.
[0102] In some implementations, the second determining module 440 is specifically used to: obtain access data from multiple traffic sources within a historical time period; and determine the next time period based on the access data from multiple traffic sources within the historical time period and the current time period.
[0103] In some possible implementations, the second determining module 440 is specifically used to: analyze access data from multiple traffic sources within a historical time period to determine a target duration, where the target duration represents the time interval between traffic peaks and traffic troughs; if the difference between the target duration and the duration of the current time period is less than a first duration, then the difference between the duration of the current time period and the second duration is determined as the duration of the next time period; if the difference between the target duration and the duration of the current time period is greater than or equal to the first duration, then the duration of the current time period is determined as the duration of the next time period.
[0104] In some implementation methods, the dynamic rate limiting device further includes: a second acquisition module 460 and a judgment module 470, wherein the second acquisition module 460 is used to: acquire the traffic value within the current time period, the traffic value being used to characterize the processing time of the request in the current time period; the judgment module 470 is used to: judge whether the traffic value is greater than a second value; and the sorting module 420 is specifically used to: sort multiple traffic sources according to the access data when the traffic value is greater than the second value, and obtain a sorting result.
[0105] It should be understood that the device embodiments and method embodiments can correspond to each other, and similar descriptions can be referred to the method embodiments. To avoid repetition, further details will not be provided here. Specifically, Figure 4 The apparatus 400 shown can execute the above-described method embodiments, and the aforementioned and other operations and / or functions of each module in the apparatus 400 are respectively for implementing the corresponding processes in the above-described methods. For the sake of brevity, they will not be described in detail here.
[0106] The apparatus 400 of this application embodiment has been described above from the perspective of functional modules in conjunction with the accompanying drawings. It should be understood that this functional module can be implemented in hardware, in software instructions, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in this application can be completed by integrated logic circuits in the processor's hardware and / or by software instructions. The steps of the method disclosed in this application embodiment can be directly embodied as being executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. Optionally, the software module can be located in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps in the above method embodiments.
[0107] Figure 5 This is a schematic block diagram of an electronic device 500 provided in an embodiment of this application.
[0108] like Figure 5 As shown, the electronic device 500 may include:
[0109] The system includes a memory 510 and a processor 520. The memory 510 stores computer programs and transfers the program code to the processor 520. In other words, the processor 520 can retrieve and run the computer program from the memory 510 to implement the methods described in the embodiments of this application.
[0110] For example, the processor 520 can be used to execute the above-described method embodiments according to instructions in the computer program.
[0111] In some embodiments of this application, the processor 520 may include, but is not limited to:
[0112] General-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0113] In some embodiments of this application, the memory 510 includes, but is not limited to:
[0114] Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).
[0115] In some embodiments of this application, the computer program may be divided into one or more modules, which are stored in the memory 510 and executed by the processor 520 to perform the method provided in this application. The one or more modules may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the electronic device.
[0116] likeFigure 5 As shown, the electronic device may also include:
[0117] Transceiver 530, which can be connected to processor 520 or memory 510.
[0118] The processor 520 can control the transceiver 530 to communicate with other devices; specifically, it can send information or data to other devices or receive information or data sent by other devices. The transceiver 530 may include a transmitter and a receiver. The transceiver 530 may further include antennas, and the number of antennas may be one or more.
[0119] It should be understood that the various components in the electronic device are connected through a bus system, which includes a data bus, a power bus, a control bus, and a status signal bus.
[0120] This application also provides a computer storage medium storing a computer program thereon, which, when executed by a computer, enables the computer to perform the methods of the above-described method embodiments. Alternatively, embodiments of this application also provide a computer program product containing instructions that, when executed by a computer, cause the computer to perform the methods of the above-described method embodiments.
[0121] When implemented using software, it can be implemented entirely or partially as a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., Digital Video Disc (DVD)), or a semiconductor medium (e.g., Solid State Disk (SSD)).
[0122] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0123] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.
[0124] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. For example, the functional modules in the various embodiments of this application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0125] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A dynamic current limiting method, characterized in that, include: Retrieve access data from multiple traffic sources within the current time period; Based on the access data, the multiple traffic sources are sorted to obtain a sorting result; Based on the sorting results, the respective traffic limiting thresholds for the multiple traffic sources are determined; Determine the next time period; In the next time period, the traffic from the multiple traffic sources is limited according to the traffic limiting threshold. The step of determining the rate limiting threshold for each of the multiple traffic sources based on the ranking result includes: obtaining the total number of visits from the multiple traffic sources and the number of visits from each of the multiple traffic sources within the current time period; calculating the rate limiting threshold for the first traffic source in the ranking result to obtain a first rate limiting threshold; calculating the difference between the number of visits from the first traffic source and the first rate limiting threshold to obtain a first difference; calculating the difference between the total number of visits and the first difference to obtain a second difference; if the second difference is less than or equal to a preset rate limiting threshold, then determining the traffic sources other than the first traffic source in the ranking result. The rate limiting thresholds for the remaining traffic sources are all infinite. If the second difference is greater than the preset rate limiting threshold, the first traffic source is removed from the sorting results to obtain an updated sorting result. The preset rate limiting threshold is updated using the difference between the preset rate limiting threshold and the first rate limiting threshold. The total number of visits is updated using the difference between the total number of visits and the number of visits from the first traffic source. The calculation of the rate limiting threshold for the first traffic source in the sorting results continues until the second difference is less than or equal to the preset rate limiting threshold, thus obtaining the rate limiting thresholds for each of the multiple traffic sources.
2. The method according to claim 1, characterized in that, The calculation of the first traffic source's rate limiting threshold in the sorting results to obtain the first rate limiting threshold includes: Determine the rate limiting weight for the first traffic source; Calculate the product of the number of visits from the first traffic source and the rate limiting weight to obtain the first product; The first rate limiting threshold is determined based on the access volume of the first traffic source and the first product.
3. The method according to claim 2, characterized in that, Determining the first rate limiting threshold based on the access volume of the first traffic source and the first product includes: Calculate the difference between the total number of visits and the preset rate limiting threshold to obtain a third difference value; Calculate the minimum value between the first product and the third difference to obtain the first numerical value; The difference between the access volume of the first traffic source and the first value is calculated to obtain the first traffic limiting threshold.
4. The method according to claim 2, characterized in that, Determining the rate limiting weight for the first traffic source includes: Determine the importance level and business scenario corresponding to the first traffic source; The rate limiting weight is determined based on the importance level and the business scenario.
5. The method according to any one of claims 1-4, characterized in that, The access data includes at least one of the following: access volume, waiting time, and response time; Wherein, the waiting time is the time interval between the time the request is sent and the time the request begins to be processed, and the response time is the time interval between the time the request is received and the time the request processing ends; The step of sorting the multiple traffic sources based on the access data to obtain a sorting result includes: The traffic sources are sorted according to their respective visit volumes from largest to smallest to obtain the sorting result; or... The multiple traffic sources are sorted according to their respective waiting times from longest to shortest to obtain the sorting result; or... The traffic sources are sorted in descending order of their response times to obtain the sorting result.
6. The method according to any one of claims 1-4, characterized in that, Determining the next time period includes: Obtain access data from the multiple traffic sources within a historical time period; The next time period is determined based on the access data of the multiple traffic sources in the historical time period and the current time period.
7. The method according to claim 6, characterized in that, The step of determining the next time period based on the access data of the multiple traffic sources in historical time periods and the current time period includes: Analyze the access data of the multiple traffic sources within a historical time period to determine the target duration, which represents the time interval between traffic peaks and traffic troughs. If the difference between the target duration and the duration of the current time period is less than the first duration, then the difference between the duration of the current time period and the second duration is determined as the duration of the next time period. If the difference between the target duration and the duration of the current time period is greater than or equal to the first duration, then the duration of the current time period is determined as the duration of the next time period.
8. The method according to any one of claims 1-4, characterized in that, Before sorting the multiple traffic sources based on the access data to obtain the sorting result, the method further includes: Obtain the traffic value within the current time period, whereby the traffic value is used to characterize the processing time of requests within the current time period; Determine whether the flow rate value is greater than the second value; The step of sorting the multiple traffic sources based on the access data to obtain a sorting result includes: When the traffic volume value is greater than the second value, the multiple traffic sources are sorted according to the access data to obtain the sorting result.
9. A dynamic current limiting device, characterized in that, The dynamic rate limiting device includes: a first acquisition module, a sorting module, a first determination module, a second determination module, and a rate limiting module, wherein, The first acquisition module is used to acquire access data from multiple traffic sources within the current time period. The sorting module is used to sort the multiple traffic sources according to the access data to obtain a sorting result; The first determining module is used to determine the flow limiting threshold for each of the multiple traffic sources based on the sorting result; The second determining module is used to determine the next time period; The rate limiting module is used to limit the rate of the multiple traffic sources according to the rate limiting threshold during the next time period. The first determining module is specifically configured to: obtain the total number of visits from the multiple traffic sources and the number of visits from each of the multiple traffic sources within the current time period; calculate the rate limiting threshold of the first traffic source in the ranking result to obtain a first rate limiting threshold; calculate the difference between the number of visits from the first traffic source and the first rate limiting threshold to obtain a first difference; calculate the difference between the total number of visits and the first difference to obtain a second difference; if the second difference is less than or equal to a preset rate limiting threshold, then determine that the rate limiting thresholds of the remaining traffic sources in the ranking result other than the first traffic source are infinity; if the second difference is greater than the preset rate limiting threshold, then remove the first traffic source from the ranking result to obtain an updated ranking result, update the preset rate limiting threshold using the difference between the preset rate limiting threshold and the first rate limiting threshold, update the total number of visits using the difference between the total number of visits and the number of visits from the first traffic source, and continue to calculate the rate limiting threshold of the first traffic source in the ranking result until the second difference is less than or equal to the preset rate limiting threshold, and obtain the rate limiting thresholds of each of the multiple traffic sources.
10. The apparatus according to claim 9, characterized in that, The first determining module is specifically used for: Determine the rate limiting weight for the first traffic source; Calculate the product of the number of visits from the first traffic source and the rate limiting weight to obtain the first product; The first rate limiting threshold is determined based on the access volume of the first traffic source and the first product.
11. The apparatus according to claim 10, characterized in that, The first determining module is specifically used for: Calculate the difference between the total number of visits and the preset rate limiting threshold to obtain a third difference value; Calculate the minimum value between the first product and the third difference to obtain the first numerical value; The difference between the access volume of the first traffic source and the first value is calculated to obtain the first traffic limiting threshold.
12. The apparatus according to claim 10, characterized in that, The first determining module is specifically used for: Determine the importance level and business scenario corresponding to the first traffic source; The rate limiting weight is determined based on the importance level and the business scenario.
13. The apparatus according to any one of claims 9-12, characterized in that, The access data includes at least one of the following: access volume, waiting time, and response time; Wherein, the waiting time is the time interval between the time the request is sent and the time the request begins to be processed, and the response time is the time interval between the time the request is received and the time the request processing ends; The sorting module is specifically used for: The traffic sources are sorted according to their respective visit volumes from largest to smallest to obtain the sorting result; or... The multiple traffic sources are sorted according to their respective waiting times from longest to shortest to obtain the sorting result; or... The traffic sources are sorted in descending order of their response times to obtain the sorting result.
14. The apparatus according to any one of claims 9-12, characterized in that, The second determining module is specifically used for: Obtain access data from the multiple traffic sources within a historical time period; The next time period is determined based on the access data of the multiple traffic sources in the historical time period and the current time period.
15. The apparatus according to claim 14, characterized in that, The second determining module is specifically used for: Analyze the access data of the multiple traffic sources within a historical time period to determine the target duration, which represents the time interval between traffic peaks and traffic troughs. If the difference between the target duration and the duration of the current time period is less than the first duration, then the difference between the duration of the current time period and the second duration is determined as the duration of the next time period. If the difference between the target duration and the duration of the current time period is greater than or equal to the first duration, then the duration of the current time period is determined as the duration of the next time period.
16. The apparatus according to any one of claims 10-12, characterized in that, The dynamic current limiting device further includes: a second acquisition module and a judgment module, wherein... The second acquisition module is used to: acquire the traffic value within the current time period, wherein the traffic value is used to characterize the processing time of the request in the current time period; The judgment module is used to: determine whether the flow rate value is greater than the second value; The sorting module is specifically used for: When the traffic volume value is greater than the second value, the multiple traffic sources are sorted according to the access data to obtain the sorting result.
17. An electronic device, characterized in that, include: processor; as well as Memory for storing the executable instructions of the processor; The processor is configured to execute the method of any one of claims 1-8 by executing the executable instructions.
18. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-8.
19. A computer program product containing instructions, characterized in that, When the computer program product is run on an electronic device, the electronic device performs the method of any one of claims 1-8.