Container expansion and contraction determination method, device, and storage medium

CN118760708BActive Publication Date: 2026-10-27BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410984473.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2026-10-27
Estimated Expiration
2044-07-22

AI Technical Summary

Technical Problem

[0004]本申请实施例提供一种容器扩缩容确定方法、设备及介质,以解决传统缩容带来的资源浪费和容器超负荷运行导致的服务不可用的技术问题

Benefits of technology

[0015]本申请的有益效果是:区别于现有技术的情况,本申请通过获取服务器历史记录的多个历史每秒查询率以及每个历史每秒查询率的变化速率;基于多个所述历史每秒查询率确定每秒查询率与容器数量的线性对应关系,以及,基于多个所述每秒查询率对应的变化速率,确定每秒查询率与容器数量的非线性对应关系;检测所述服务器的当前每秒查询率,若所述当前每秒查询率大于等于预设临界值,则利用所述非线性对应关系确定所述服务器上扩缩容的、与所述当前每秒查询率对应的第一目标扩缩容容器数量;若所述当前每秒查询率小于预设临界值,则利用所述线性对应关系确定所述服务器上扩缩容的、与所述当前每秒查询率对应的第二目标扩缩容容器数量。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118760708B_ABST
    Figure CN118760708B_ABST
Patent Text Reader

Abstract

The application discloses a container expansion and contraction determination method, device and storage medium. The method comprises the following steps: obtaining a plurality of historical query rates per second of server historical records and a change rate of each historical query rate per second; determining a linear corresponding relationship between the query rate per second and the container quantity based on the plurality of historical query rates per second, and determining a nonlinear corresponding relationship between the query rate per second and the container quantity based on the change rate corresponding to the plurality of query rates per second; detecting the current query rate per second of the server, and if the current query rate per second is greater than or equal to a preset critical value, determining a first target expansion and contraction container quantity corresponding to the current query rate per second by using the nonlinear corresponding relationship; and if the current query rate per second is less than the preset critical value, determining a second target expansion and contraction container quantity corresponding to the current query rate per second by using the linear corresponding relationship. The application can flexibly expand and contract the container according to the query rate per second, thereby improving the resource utilization rate of the container.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, specifically to a method, device, and storage medium for determining container expansion and contraction. Background Technology

[0002] In the internet industry, server scaling is a critical task, essential for ensuring high availability and improving service quality. Server scaling is typically affected by queries per second (QPS), meaning that an increase or decrease in user requests necessitates dynamically increasing or decreasing server resources to meet demand.

[0003] In the process of researching and practicing related technologies, the inventors of this application discovered that server scaling is currently typically achieved using automated tools or cloud computing platforms. However, traditional linear scaling methods may have some inefficiencies and performance limitations when dealing with sudden high loads. Linear scaling cannot quickly adapt to increased demand, leading to a waste of server resources. Furthermore, when QPS suddenly increases, linear scaling cannot adjust server capacity in a timely manner, causing the server to operate under overload and resulting in service unavailability. Summary of the Invention

[0004] This application provides a method, device, and medium for determining container expansion / contraction, in order to solve the technical problems of resource waste caused by traditional capacity reduction and service unavailability caused by container overload.

[0005] In a first aspect, embodiments of this application provide a method for expanding or shrinking a container, the method comprising: Obtain multiple historical query rates per second from the server's historical records, as well as the rate of change of each historical query rate per second. A linear relationship between query rate per second and the number of containers is determined based on multiple historical query rates per second, and a non-linear relationship between query rate per second and the number of containers is determined based on the rate of change corresponding to multiple query rates per second. The current query rate per second of the server is detected. If the current query rate per second is greater than or equal to a preset threshold, the first target number of scaling containers corresponding to the current query rate per second is determined using the nonlinear correspondence. If the current query rate per second is less than a preset threshold, the second target number of scaling containers corresponding to the current query rate per second is determined using the linear correspondence.

[0006] Optionally, determining a linear relationship between the query rate per second and the number of containers based on multiple historical query rates per second includes: Obtain the query time of the plurality of historical query rates per second, wherein: the plurality of query rates per second includes: an initial query rate per second and a reference query rate per second, and the reference query rate per second is adjacent to the query time of the current query rate per second; Calculate the third query rate difference between the initial query rate per second and the reference query rate per second; Obtain the maximum number of queries for the server's containers, calculate the number of third containers corresponding to the difference between the third query rate and the third query rate, and calculate the number of fourth containers corresponding to the initial query rate per second. The quotient of the number of the third container and the reference query rate per second is used as the slope coefficient; and the number of the third container is used as a constant to obtain the target linear function as the linear correspondence.

[0007] Optionally, determining the number of first target scaling containers on the server corresponding to the current query rate per second using the linear correspondence includes: The current query rate per second is input as a variable into the target linear function to obtain the first target number of expansion and contraction containers.

[0008] Optionally, determining the non-linear relationship between the query rate per second and the number of containers based on the change rates corresponding to the multiple query rates per second includes: The query times of the plurality of historical query rates per second are obtained, wherein the plurality of query rates per second include: a first query rate per second, a second query rate per second, and a third query rate per second; Calculate the first query rate difference between the first query rate per second and the second query rate per second, and the first query time difference, respectively; calculate the second query rate difference between the second query rate and the third query rate per second, and the first query time difference, respectively; The first rate of change is determined based on the first query rate difference and the first query time difference; the second rate of change is determined based on the second query rate difference and the first query time difference. Obtain the maximum number of queries for the server's containers, calculate the number of fifth containers corresponding to the first rate of change, and calculate the number of sixth containers corresponding to the second rate of change. Using the first rate of change and the number of fifth containers, and the second rate of change and the number of sixth containers, the slope factor and scaling factor of the preset inverse hyperbolic tangent function are calculated to obtain the target inverse hyperbolic tangent function as the nonlinear correspondence. The target inverse hyperbolic tangent function includes the slope factor and scaling factor.

[0009] Optionally, determining the number of second target scaling containers on the server corresponding to the current query rate per second using the nonlinear correspondence includes: Calculate the current rate of change corresponding to the current query rate; The current rate of change is input as a variable into the target inverse hyperbolic tangent function to obtain the second target number of expansion and contraction containers.

[0010] Optionally, the method further includes: Determine the default application programming interfaces (APIs) related to scaling up and down; The preset application programming interface is used to call the preset scaling program, and the containers in the server are scaled up or down according to the first target number of scaling containers or the second target number of scaling containers.

[0011] Optionally, obtaining the server's query rate per second and the rate of change of the query rate per second includes: Obtain the raw query data, which includes the total number of query requests and the query request processing time; The average rate of the original query data is calculated to obtain the query rate per second of the server. The average rate of the query rate per second within a preset time period is calculated to obtain the rate of change of the query rate per second within the preset time period.

[0012] Optionally, the step of calculating the average rate of the original query data to obtain the server's query rate per second includes: The unit format of the request processing time is converted into a unified target format to obtain the processed request processing time; The query rate per second of the server is obtained by determining the quotient of the processed request processing time and the number of seconds the request was processed.

[0013] In a second aspect, embodiments of this application provide a computer device, characterized in that the computer device includes a memory and a processor, the memory stores a computer program, and the processor executes the computer program to implement the method as described in any of the first aspects.

[0014] Thirdly, embodiments of this application provide a computer-readable storage medium, characterized in that the storage medium stores a computer program, which, when executed by a processor, can implement the method described in any of the first aspects.

[0015] The beneficial effects of this application are as follows: Unlike the prior art, this application obtains multiple historical query rates per second (SPS) from the server's historical records and the rate of change of each historical SPS; determines a linear correspondence between the SPS and the number of containers based on the multiple historical SPS, and determines a non-linear correspondence between the SPS and the number of containers based on the rate of change corresponding to the multiple SPS; detects the current SPS of the server; if the current SPS is greater than or equal to a preset threshold, the non-linear correspondence is used to determine the first target number of containers on the server that can be scaled up or down, corresponding to the current SPS; if the current SPS is less than the preset threshold, the linear correspondence is used to determine the second target number of containers on the server that can be scaled up or down, corresponding to the current SPS.

[0016] This application embodiment can distinguish the system load by using multiple historical query rates per second and the rate of change of each historical query rate per second. When the current query rate per second is less than a preset threshold, it indicates that the system load is relatively light. At this time, by using a linear correspondence to expand or shrink the containers in the server in the future, the containers in the system can maintain a relatively stable growth rate, which can avoid resource waste or system performance degradation caused by the system containers shrinking too fast or too slow.

[0017] In addition, when the query rate per second changes drastically, using a linear correspondence to scale up or down may lead to performance bottlenecks and latency issues due to excessive load. Therefore, when the current query rate per second is greater than or equal to the preset threshold, it indicates that the system load is heavy. In this case, a non-linear correspondence is chosen to scale up or down the containers in the server, which can guide the scaling up and down operation more quickly and avoid waste of container resources and overload operation. Attached Figure Description

[0018] 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 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. Wherein: Figure 1 This is a flowchart illustrating the first embodiment of the container expansion / shrinkage method provided in this application; Figure 2 This is a schematic diagram of the expansion and contraction diagram of the linear function provided in this application; Figure 3 This is a schematic diagram of the expansion and contraction diagram of the inverse hyperbolic tangent function provided in this application; Figure 4 This is a flowchart illustrating the second embodiment of the container scaling method provided in this application; Figure 5 This is a schematic diagram of the internal interactions of the container scaling method provided in this application. Figure 6 This is a schematic diagram of an embodiment of the computer-readable storage medium provided in this application. Detailed Implementation

[0019] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It is understood that the specific embodiments described herein are only for explaining this application and not for limiting it. Furthermore, it should be noted that, for ease of description, only the parts related to this application are shown in the accompanying drawings, not all structures. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0020] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0021] In the internet industry, server scaling is a critical task, essential for ensuring high availability and improving service quality. Server scaling is typically affected by queries per second (QPS), meaning that increases or decreases in user requests require dynamically adjusting server resources to meet demand.

[0022] In the process of researching and practicing related technologies, the inventors of this application discovered that server scaling is currently typically achieved using automated tools or cloud computing platforms. However, traditional linear scaling methods may have some inefficiencies and performance limitations when dealing with sudden high loads. Linear scaling cannot quickly adapt to increased demand, leading to a waste of server resources. Furthermore, when QPS suddenly increases, linear scaling cannot adjust server capacity in a timely manner, causing the server to operate under overload and resulting in service unavailability.

[0023] Therefore, to address the resource waste and service unavailability caused by container overload resulting from traditional linear scaling, this application provides a container scaling method, wherein the container in this application is a server. See the following embodiments for details.

[0024] The container expansion / reduction method provided in this application is described in detail below. Please refer to [link / reference] for details. Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the container scaling method provided in this application. The method includes: Step 101: Obtain multiple historical query rates per second from the server's historical records and the rate of change of each historical query rate per second.

[0025] Among these, multiple queries per second (QPS) can be collected from different time periods on the same day. QPS refers to the number of data queries that the system can process per second. It is commonly used to measure a system's performance and throughput. Typically, the number of request queries can be obtained using the operating system's built-in performance monitor, third-party performance monitoring tools, logging systems, or performance testing tools, which can be used to collect server QPS data at different points in time.

[0026] The rate of change of queries per second (QPS) refers to the trend or speed at which the QPS changes over a period of time. It represents the rate at which the QPS increases or decreases and can be used to monitor changes in system performance and predict future system load and demand. In specific embodiments, the rate of change can be calculated per second, for example: T a T b and T c For three consecutive moments, T a T b One second earlier, T c T b One second later, T a The corresponding query rate per second is Q a T b The corresponding query rate per second is Q b T c The corresponding query rate per second is Q c Query rate Q per second c The corresponding rate of change is: (Q) c -Q b ) / (T c -T b ); Queries per second Q b The corresponding rate of change is: (Q) b -Q a ) / (T b -T c ), and correspondingly the rate of change of other query rates per second Qn is: (Q n -Q n-1 ) / (T n -T n-1In other embodiments, the interval for the query rate per second can be set to other time intervals as needed, such as a rate of change every 2 seconds with a time interval of 2 seconds, or a rate of change every 5 seconds with a time interval of 5 seconds. In principle, the smaller the time interval, the more detailed the change in the query rate per second; conversely, the larger the time interval, the coarser the change in the query rate per second. The specific settings are determined by the technicians according to their needs.

[0027] S102, determine a linear correspondence between the query rate per second and the number of containers based on multiple historical query rates per second, and determine a non-linear correspondence between the query rate per second and the number of containers based on the rate of change corresponding to multiple query rates per second.

[0028] In this embodiment, the linear correspondence can be a linear function, and the key factor of the linear function is the slope coefficient. Determining the linear correspondence between the query rate per second and the number of containers based on multiple historical query rates per second primarily involves determining the slope function and its slope coefficient.

[0029] Specifically, this can be done by finding the query rate per second at two different query times in the historical query rate per second. Since the maximum number of queries per second for each container in the service is fixed, the initial number of containers M1 required to achieve the previous query rate per second can be calculated. In addition, the query rate difference ΔQ between the two query rates per second is calculated, and the container increment M2 corresponding to this query rate difference is calculated based on the initial number of containers. In this embodiment, the linear function corresponding to the linear correspondence is f(x) = M1 + (M2 / ΔQ). x is the query rate per second, and f(x) is the target number of containers to scale up or down corresponding to the query rate per second x.

[0030] In this embodiment, the nonlinear correspondence can be an inverse hyperbolic tangent function. In specific applications, the query rate per second at three different query times can be found in the historical query rate per second. Using the rate of change of the query rate per second at the three different query times, as described in step S101 above, the rate of change refers to the difference between the query rate per second and the previous query rate per second, and the ratio of the query time interval between these two query rates. By calculating the number of containers corresponding to each rate of change and then substituting it into the preset inverse hyperbolic function, the slope factor and scaling factor of the preset inverse hyperbolic function can be calculated to obtain the target inverse hyperbolic function.

[0031] S103, detect the current query rate per second of the server. If the current query rate per second is greater than or equal to a preset threshold, then use the nonlinear correspondence to determine the first target number of scaling containers corresponding to the current query rate per second.

[0032] The query rate represents the demand for data queries. A lower query rate per second places a lower load on the server, while a higher query rate per second places a higher load on the server. To ensure that the increase or decrease of server containers aligns with the query rate per second, a preset threshold can be set in this embodiment. This threshold can be determined based on historical data of container increases or decreases on the server. For example, if the increase or decrease of containers after a change in the query rate per second fails to meet the data query demand for each query, such as when the response time for a data query request exceeds the preset value after the query rate per second increases, or when the utilization rate of the server's containers handling data query requests falls below the preset value after the query rate per second decreases. In specific applications, the preset threshold can also be set by technicians based on the response time of data query requests or the utilization rate of the server's containers handling data query requests; this is not limited here.

[0033] Therefore, in this step of the embodiment of this application, when the current query rate per second is greater than a preset threshold, the number of first target expansion / contraction containers corresponding to the current query rate per second is directly calculated according to the aforementioned determined nonlinear correspondence.

[0034] S104, if the current query rate per second is less than a preset threshold, then the linear correspondence is used to determine the number of second target scaling containers on the server that correspond to the current query rate per second.

[0035] In this step of the embodiment of this application, when the current query rate per second is less than a preset threshold, the second target number of expansion and contraction containers corresponding to the current query rate per second is calculated directly according to the aforementioned determined linear correspondence.

[0036] This application embodiment can distinguish the system load by using multiple historical query rates per second and the rate of change of each historical query rate per second. When the current query rate per second is less than a preset threshold, it indicates that the system load is relatively light. At this time, by using a linear correspondence to expand or shrink the containers in the server in the future, the containers in the system can maintain a relatively stable growth rate, which can avoid resource waste or system performance degradation caused by the system containers shrinking too fast or too slow.

[0037] Furthermore, when the query rate per second changes drastically, using a linear scaling relationship may lead to performance bottlenecks and latency issues due to excessive load. Therefore, when the current query rate per second is greater than or equal to a preset threshold, indicating a heavy system load, a non-linear scaling relationship should be chosen to scale containers on the server. This allows for faster scaling operations, avoiding wasted container resources and overload. In one embodiment of this application, calculating the rate of change of the query rate per second requires query rate data within a certain time range. For example, the rate of change of the query rate per second can be calculated using the following method: 1) Obtain the query rate per second within a time period. For example, obtain the query data corresponding to the query rate per second and record the timestamp corresponding to each query data.

[0038] 2) For each query data, calculate the change between it and the previous query data (such as the difference in the amount of data in the query data or the increment in the amount of data). For example, the increment can be obtained by subtracting the query rate of the previous query data from the query rate of the current query data.

[0039] 3) Divide the increment of each query data by the time interval (usually seconds) to get the rate of change of the query rate per second, that is, divide each increment by the time difference to get the rate of change per second.

[0040] For example, suppose the number of queries at time point Td is Qd, and the number of queries at time point Te is Qe. If the time interval is ΔT = Te - Td, then the rate of change of qps can be: The rate of change of qps = (Qe - Qd) / ΔT.

[0041] In other words, the rate of change of QPS can be calculated based on the number of queries at two different time points.

[0042] To facilitate data collection and perform complex statistical calculations and filtering on the collected data, some embodiments utilize server monitoring systems (e.g., Prometheus) to collect and query data. Prometheus is an open-source server monitoring and alerting system based on a time-series database. Because Prometheus provides a simple and easy-to-use data model and query language, data collection and monitoring configuration are relatively straightforward. Furthermore, Prometheus offers flexible and powerful query and aggregation capabilities. Using the PromQL query language in Prometheus, it is easy to calculate summaries, averages, percentages, etc., of various metrics, and it supports custom alert conditions and alarm rules.

[0043] For details on the process of collecting and querying data using a server monitoring system, please refer to the following sub-steps: Step 1011: Obtain the raw query data, which includes the total number of requests and the request processing time.

[0044] In this step, raw query data can be obtained from a preset metrics interface. In Prometheus, a metrics collection task can be configured to periodically retrieve the required data from the server's metrics interface. The preset metrics interface can be an HTTP interface exposed to Prometheus, a data interface provided by the Exporter plugin, or an interface from other supported data sources.

[0045] Step 1012: Calculate the average rate of the original query data to obtain the server's query rate per second.

[0046] In this step, a preset query statement can be used to calculate the average rate of the original query data. In Prometheus, the preset query statement can be PromQL (PrometheusQueryLanguage), which can be used to query and calculate data. The query rate per second is calculated using the rate() function.

[0047] Here is a sample PromQL query: avg_over_time(request_total[1m]) / avg_over_time(request_processing_time_seconds_sum[1m]).

[0048] This query uses the avg_over_time() function to calculate the total number of requests (request_total) within a specified time range. Additionally, the avg_over_time() function can also calculate the average rate of request processing time (request_processing_time_seconds_sum).

[0049] In some embodiments, the request processing time can be converted into the corresponding request processing seconds, and the query rate per second of the server can be determined based on the quotient of the total number of requests and the request processing seconds.

[0050] For example, you can use the PromQL built-in function seconds() to convert the request processing time into the corresponding number of seconds, and divide the total number of requests by the number of request processing seconds to get the number of queries per second, which is the query rate per second.

[0051] Specifically, let's convert a day into seconds. A day has 24 hours, an hour has 60 minutes, and a minute has 60 seconds, so a day has 24... 60 60 = 86400 seconds.

[0052] Then, divide the total number of requests per day by the request processing time to get the average number of requests processed per second.

[0053] Queries per second = Total number of requests / Request processing time.

[0054] Assuming there are 100,000 requests per day and the request processing time is 10 hours, the queries per second (QPS) can be calculated as follows: There are 24 days 60 60 = 86400 seconds, query rate per second = 100000 / (10 60 60)≈0.2778 queries / second That is, the query rate is approximately 0.2778 queries per second.

[0055] Step 1013: Calculate the average rate of query rate per second within the preset time period to obtain the rate of change of query rate per second within the preset time period.

[0056] In Prometheus, you can use a preset query statement to calculate the average rate of queries per second within a preset time period. The preset query statement can be a PromQL query statement, and you can further use the avg_over_time() function to calculate the average rate of queries per second within a specified time range, thereby obtaining the rate of change of the query rate.

[0057] Here is a sample PromQL query: rate(avg_over_time(request_rate[5m])[10m:1m]).

[0058] This query first uses the avg_over_time() function to calculate the query rate per second (request_rate) over the past 5 minutes, and then uses the rate() function to calculate the rate of change of this query rate from the past 10 minutes to the past 1 minute.

[0059] In one embodiment of this application, the aforementioned step S102, determining the linear correspondence between the query rate per second and the number of containers based on multiple historical query rates per second, may include the following steps: S201, obtain the query time of the multiple historical query rates per second.

[0060] In this embodiment of the application, two query rates per second are used as an example for illustration. Specifically, the plurality of query rates per second includes: an initial query rate per second Q. 初 And reference query rate Q 参Furthermore, the reference query rate per second is adjacent to the query time of the current query rate per second. Initial query rate per second Q 初 It can be compared with the reference query rate Q per second 参 The query times are adjacent.

[0061] In the embodiments of this application, adjacent query times refer to the determination according to the set query interval. For example, when the query interval is 1 second, adjacent query times refer to two query rates per second that are adjacent to each other in 1 second; when the query interval is 5 seconds, adjacent query times refer to two query rates per second that are adjacent to each other in 5 seconds.

[0062] S202, Calculate the initial query rate Q per second. 初 And reference query rate Q 参 The third query rate difference △Q3.

[0063] S203, obtain the number of queries that each container of the server can handle, and calculate the number of third containers M3 corresponding to the difference between the third query rate and ΔQ3, and calculate the number of fourth containers M4 corresponding to the initial query rate per second.

[0064] S204, the number of the third containers M3 is compared with the reference query rate Q per second. 参 The quotient is determined as the slope coefficient K; the number of the third container is taken as a constant a, and the target linear function is obtained as the linear correspondence.

[0065] Here, the initial query time corresponding to the initial query rate per second, and the reference query time corresponding to the reference query rate per second, can be times prior to the current time, based on the given linear function form y=f(x)=a+k. As can be seen from x, the function passes through the point corresponding to the initial query rate per second and the point corresponding to the reference query rate per second. In this embodiment, x represents the query rate per second (qps), and f(x), or y, represents the number of containers.

[0066] For example, assuming a reference query rate of 300 qps per second, an initial query rate of 100 qps per second, and each container can handle 100 qps per second, the difference in query rates is reference query rate - initial query rate = 300 - 100 = 200 qps. Dividing this difference of 200 qps by the number of queries each container can handle (100 qps) gives a container increment of 2. Therefore, the container increment required for a reference query rate of 300 qps per second is 2. Additionally, dividing the initial query rate of 100 qps per second by the number of queries each container can handle (100 qps) gives an initial container count of 1. By increasing the initial container count of 1 corresponding to the initial query rate by 2, the container requirement for the reference query rate can be met.

[0067] When the linear function form f(x) = a + k is obtained from the calculation... The constant a and slope coefficient d in x are then used to obtain the following... Figure 2 The diagram shows the expansion and contraction of a linear function.

[0068] In some embodiments, when the target linear function f(x) = a + k is determined according to steps S201-S204... After x, the current query rate per second can be directly used as the variable x and substituted into the linear function of the target line. The resulting value can then be used as the number of expansion and contraction containers for the second target.

[0069] In some embodiments, in the aforementioned step S102, a non-linear correspondence between the query rate per second and the number of containers is determined based on the rate of change corresponding to the plurality of query rates per second. The determination of the non-linear correspondence may specifically include the following process: S301, obtain the query time of the multiple historical query rates per second.

[0070] In this embodiment of the application, three query rates per second are used as an example for illustration. Specifically, the plurality of query rates per second include:

[0071] The rate of change of query rate per second can be obtained using step 101. Assume that the first query time of the first query rate Q1 is t1, the second query time of the second query rate Q2 is t2, and the third query time of the third query rate Q3 is t3.

[0072] S302, calculate the first query rate difference between the first query rate per second and the second query rate per second, and the first query time difference, respectively; calculate the second query rate difference between the second query rate per second and the third query rate per second, and the first query time difference, respectively.

[0073] The difference between the first query rate Q1 and the first query rate Q2 is (Q2-Q1), and the difference between the first query times is (t2-t1).

[0074] The difference between the second query rate Q2 and the third query rate Q3 is (Q3-Q2), and the difference between the second query times is (t3-t2).

[0075] S303, determine the first rate of change based on the first query rate difference and the first query time difference; determine the second rate of change based on the second query rate difference and the first query time difference.

[0076] The first rate of change is rate1, and the second rate of change is rate2. The first rate of change, rate1, is (Q2-Q1) / (t2-t1), and the second rate of change, rate2, is (Q3-Q2) / (t3-t2).

[0077] S304, obtain the maximum number of containers that can be queried on the server, calculate the number of fifth containers corresponding to the first rate of change, and calculate the number of sixth containers corresponding to the second rate of change.

[0078] The fifth container has a quantity of M5, and the sixth container has a quantity of M6.

[0079] S305, using the first rate of change and the number of fifth containers, and the second rate of change and the number of sixth containers, calculate the slope factor and scaling factor of the preset inverse hyperbolic tangent function to obtain the target inverse hyperbolic tangent function as the nonlinear correspondence. The target inverse hyperbolic tangent function includes the slope factor and scaling factor.

[0080] Specifically, for example, if the query rate per second (QPS) at time t1 is 150, the query rate per second at time t2 is 300 QPS, and the query rate per second at time t3 is 500 QPS, where the time difference between t1 and t2 is 3 seconds and the time difference between t2 and t3 is 5 seconds, then the first rate of change is (300-150) QPS / (t2-t1) = 50 QPS / second, meaning an increase of 50 QPS per second. Since each container has a processing capacity of 100 QPS, the number of containers changed is 50 / 100 = 0.5, resulting in a point (50 QPS / second, 0.5 containers). The second rate of change is (500-300) QPS / 5 = 40 QPS / second, meaning an increase of 40 QPS per second. Since each container has a processing capacity of 100 QPS, the number of containers changed is 40 / 100 = 0.4, resulting in another point (40 QPS / second, 0.4 containers).

[0081] Based on the correspondence between the rate of change and the server's containers, the slope factor and scaling factor of the inverse hyperbolic tangent function are determined; then, based on the slope factor and scaling factor, the inverse hyperbolic tangent function is determined.

[0082] For example, using the method described above for calculating the number of container changes, we can obtain the corresponding relationship between the number of container changes and the rate of change for two sets of containers, such as point A(x1, y1) and point B(x2, y2). Based on the given function form f(x) = a artanh(b In this embodiment, x is the rate of change, i.e., the rate of change of qps, and f(x) is the number of container changes. Substituting the two points into the function, we obtain the following two equations: y1=f(x1)=a artanh(b x1); y2=f(x2)=a artanh(b x2); For example, the values ​​of points A and B can be obtained by substituting (40 qps / second, 0.4 units) and (50 qps / second, 0.5 units) obtained above into the equation to solve for the values ​​of a and b.

[0083] Due to the properties of the inverse hyperbolic tangent function, this system of equations may have multiple solutions. When using numerical solution methods, the values ​​of a and b need to be adjusted according to the actual business requirements.

[0084] Here, 'a' is the scaling factor, which is the vertical scaling parameter of the function curve. It determines the magnitude of the function's change in the vertical direction. When the value of 'a' increases, the vertical scaling of the function also increases; when the value of 'a' decreases, the vertical scaling of the function also decreases. 'b' is the slope factor, which is the horizontal scaling parameter of the function curve related to its slope. It controls the slope and the degree of horizontal expansion of the function curve. When the value of 'b' increases, the slope of the function curve tends to become steeper, resulting in horizontal contraction; when the value of 'b' decreases, the slope of the function curve tends to become gentler, resulting in horizontal expansion.

[0085] Furthermore, based on the determined slope factor b and scaling factor a, the following can be obtained: Figure 3 The diagram shows the expansion and contraction of the inverse hyperbolic tangent function.

[0086] In some embodiments, specifically: for example, the current rate of change, i.e., the current QPS change rate, can be obtained first based on the rate of change between the current query rate per second and the previous query rate per second, and then substituted into the inverse hyperbolic tangent function y=f(x)=a in steps 301-305. artanh(b In x), the relationship between the current QPS change rate and container changes is determined, thereby determining the number of containers to be expanded or shrunk for the first target.

[0087] In other embodiments of this application, after the aforementioned step S103 or S104, such as Figure 4 As shown, it may also include the following steps: Step 105: Determine the default application programming interface associated with scaling up and down.

[0088] Step S106: Use the preset application programming interface to call the preset scaling deployment program, and use the preset scaling deployment program to scale the containers in the server according to the first target number of scaling containers or the second target number of scaling containers.

[0089] The default application programming interface (API) can be the Kubernetes (K8s) API. Kubernetes is predefined as the interface for scaling and scaling. This predefined mapping can be determined using a mapping table. For example, the scaling identifier can be "Expansion," and the default API identifier can be "Kubernetes." A pre-stored mapping table of "Expansion" and "Kubernetes" is maintained on the server. When scaling or scaling is needed, the identifier "Expansion" is looked up to find the corresponding Kubernetes instance. The default scaling deployment program can be "DeploymentScale," which can be called via the K8s API to perform scaling.

[0090] DeploymentScale is a scaling deployment module typically used to automatically adjust the resource configuration of applications or services to adapt to changes in traffic. By using this module, the number of containers, virtual machines, or virtual machines can be increased or decreased as needed, ensuring good application performance and reliability. This auto-scaling capability improves the resilience and scalability of applications, enabling them to adapt to ever-changing workload demands.

[0091] Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and operation of containerized applications. Because Kubernetes provides a powerful set of APIs, automated scaling operations can be achieved through these APIs, reducing the workload and risk of errors associated with manual operations. Furthermore, the Kubernetes APIs allow for dynamic adjustment of the number of containers based on real-time load conditions and custom policies to adapt to different workloads and traffic demands.

[0092] In addition, this embodiment utilizes a preset application programming interface to trigger a preset scaling deployment module, which in turn scales up and down containers on the server. This allows for dynamic adjustment of the number of containers based on real-time load conditions and customized strategies to adapt to different workloads and traffic requirements.

[0093] Based on the above embodiments, it can be seen that the container expansion / shrinkage method provided in this application specifically includes the following process, which can be referred to in detail below. Figure 5 .

[0094] 1) Use Prometheus to obtain raw query data, which includes the total number of requests and the request processing time. Calculate the QPS and QPS change rate based on the obtained data. 2) Based on the qps and qps change rate calculated by Prometheus, we obtain the following: 2 and Figure 3 The expansion / contraction plots of the inverse hyperbolic tangent function and the linear function are shown below. 3) Determine the relationship between the query rate per second and the preset threshold. If the query rate per second is less than the preset threshold, proceed to step 4); if the query rate per second is greater than or equal to the preset threshold, proceed to step 5). 4) Use linear functions to scale containers in the server; 5) Use the inverse hyperbolic tangent function to scale up and down containers in the server. ArtanhScale can be used to calculate the number of containers that need to be scaled up or down, and DeploymentScale can be triggered through the Kubernetes API to perform the scaling up and down. 6) DeploymentScale is used to change the number of containers in the system based on the calculated number of containers that need to be scaled up or down. In other words, DeploymentScale is responsible for the actual scaling up and down work.

[0095] Please see Figure 6 , Figure 6 This is a schematic diagram of an embodiment of the computer-readable storage medium provided in this application. The computer-readable storage medium 90 is used to store a computer program 91. When the computer program 91 is executed by the controller, it is used to implement the following method steps: Obtain multiple queries per second (SPS) rates and multiple SPS change rates for the server; determine a linear function based on the multiple SPS rates and an inverse hyperbolic tangent function based on the multiple SPS change rates; if the SPS rate is greater than or equal to a preset threshold, use the inverse hyperbolic tangent function to scale up or down the containers in the server; if the SPS rate is less than the preset threshold, use the linear function to scale up or down the containers in the server.

[0096] Understandably, when the computer program 91 is executed by the controller, it is also used to implement the technical solutions of any embodiment of this application.

[0097] In the several embodiments provided in this application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.

[0098] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.

[0099] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0100] If the integrated units in the other embodiments described above are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, container, or network device, etc.) or controller (processor) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0101] The above are merely embodiments of this application and do not limit the scope of this patent application. Any equivalent structural or procedural changes made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of this application.

Claims

1. A method for determining the expansion and contraction capacity of a container, characterized in that, The method includes: Obtain multiple historical query rates per second from the server's historical records, as well as the rate of change of each historical query rate per second. A linear relationship between query rate per second and the number of containers is determined based on multiple historical query rates per second, and a non-linear relationship between query rate per second and the number of containers is determined based on the rate of change corresponding to multiple query rates per second. The current query rate per second of the server is detected. If the current query rate per second is greater than or equal to a preset threshold, the first target number of scaling containers corresponding to the current query rate per second is determined using the nonlinear correspondence. If the current query rate per second is less than a preset threshold, the second target number of scaling containers corresponding to the current query rate per second is determined using the linear correspondence.

2. The method according to claim 1, characterized in that, Determining a linear relationship between query rate per second and the number of containers based on multiple historical query rates per second includes: Obtain the query times of multiple historical query rates per second, wherein: the multiple query rates per second include: an initial query rate per second and a reference query rate per second, and the reference query rate per second is adjacent to the query time of the current query rate per second; Calculate the third query rate difference between the initial query rate per second and the reference query rate per second; Obtain the maximum number of queries for the containers of the server, calculate the number of third containers corresponding to the difference between the third query rate and the third query rate, and calculate the number of fourth containers corresponding to the initial query rate per second. The quotient of the number of the third container and the reference query rate per second is used as the slope coefficient; and the number of the third container is used as a constant to obtain the target linear function as the linear correspondence.

3. The method according to claim 2, characterized in that, Determining the second target number of scaling containers corresponding to the current query rate per second using the linear correspondence includes: The current query rate per second is input as a variable into the target linear function to obtain the second target number of expansion and contraction containers.

4. The method according to claim 1, characterized in that, The determination of the non-linear relationship between the query rate per second and the number of containers based on the rate of change corresponding to multiple query rates per second includes: The query times of multiple historical query rates per second are obtained, wherein the multiple query rates per second include: a first query rate per second, a second query rate per second, and a third query rate per second. Calculate the first query rate difference between the first query rate per second and the second query rate per second, and the first query time difference, respectively; calculate the second query rate difference between the second query rate and the third query rate per second, and the first query time difference, respectively; The first rate of change is determined based on the first query rate difference and the first query time difference; the second rate of change is determined based on the second query rate difference and the first query time difference. Obtain the maximum number of queries for the server's containers, calculate the number of fifth containers corresponding to the first rate of change, and calculate the number of sixth containers corresponding to the second rate of change. Using the first rate of change and the number of fifth containers, and the second rate of change and the number of sixth containers, the slope factor and scaling factor of the preset inverse hyperbolic tangent function are calculated to obtain the target inverse hyperbolic tangent function, which serves as the nonlinear correspondence. The target inverse hyperbolic tangent function includes the slope factor and scaling factor.

5. The method according to claim 4, characterized in that, Determining the first target number of scaling containers corresponding to the current query rate per second using the nonlinear correspondence includes: Calculate the current rate of change corresponding to the current query rate per second; The current rate of change is input as a variable into the target inverse hyperbolic tangent function to obtain the number of the first target expansion / contraction containers.

6. The method according to claim 1, characterized in that, The method further includes: Determine the default application programming interfaces (APIs) related to scaling up and down; The preset application programming interface is used to call the preset scaling program, and the containers in the server are scaled up or down according to the first target number of scaling containers or the second target number of scaling containers.

7. The method according to claim 1, characterized in that, The process of obtaining multiple historical query rates per second from server history records and the rate of change of each historical query rate per second includes: Obtain the raw query data, which includes the total number of query requests and the query request processing time; The historical query rate per second of the server is obtained by calculating the average rate of the original query data. The average rate of the historical query rate per second within a preset time period is calculated to obtain the rate of change of the historical query rate per second within the preset time period.

8. The method according to claim 7, characterized in that, The step of calculating the average rate of the original query data to obtain the historical query rate per second of the server includes: The unit format of the request processing time is converted into a unified target format to obtain the processed request processing time; The historical query rate per second of the server is obtained by determining the quotient of the total number of query requests and the processing time of the processed requests.

9. A computer device, characterized in that, The computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method as described in any one of claims 1-8.

10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, can implement the method as described in any one of claims 1-8.

Citation Information

Patent Citations

  • System capacity expansion and contraction method and device and electronic equipment

    CN112925607A

  • Method and device for expanding and shrinking capacity based on Knative

    CN116401048A