Container capacity expansion and shrinkage determination method and device and storage medium
By analyzing the historical data of the server, we determine the linear and non-linear relationship between the query rate per second and the number of containers, and select the appropriate expansion and contraction strategy according to the current load situation, which solves the problem of efficiency and performance of the traditional linear expansion and contraction method under high load. problem, achieving efficient utilization of resources and stable operation of the system.
Patent Information
- Application Number
- CN202410984473.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-07-22
AI Technical Summary
The traditional linear expansion and contraction method has insufficient efficiency and performance when dealing with sudden high load situations, resulting in a waste of server resources, overload operation, and service unavailability.
By obtaining the server's historical query rate per second and change rate, determine the linear and nonlinear correspondence between the query rate per second and the number of containers, and select the appropriate relationship based on the current query rate per second to perform expansion and contraction operations to avoid resource waste and overage. load.
It achieves faster and more efficient container expansion and contraction, avoids resource waste and performance bottlenecks, and ensures stable operation of the system.
Smart Images

Figure CN118760708A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device and storage medium for determining container expansion and contraction. Background Art
[0002] In the Internet industry, server expansion and contraction is one of the key tasks, which is crucial to ensure high availability of business and improve service quality. Server expansion and contraction is usually affected by the query rate per second (QPS), which means that the increase or decrease of user requests requires dynamic increase or decrease of server resources to meet the demand.
[0003] In the process of researching and practicing related technologies, the inventors of this application found that the current expansion and contraction of servers is usually achieved using automated tools or cloud computing platforms. However, the traditional linear expansion method may have some efficiency and performance deficiencies when dealing with sudden high load situations. Linear expansion cannot quickly adapt to the increase in demand, resulting in a waste of server resources. In addition, when the QPS suddenly increases, linear expansion cannot adjust the server capacity in time, causing the server to be overloaded, resulting in service unavailability. Summary of the invention
[0004] The embodiments of the present application provide a method, device and medium for determining container expansion and contraction to solve the technical problems of resource waste caused by traditional capacity reduction and service unavailability caused by container overload operation.
[0005] In a first aspect, an embodiment of the present application provides a method for expanding and contracting a container, the method comprising:
[0006] Get multiple historical query rates per second of the server history records and the change rate of each historical query rate per second;
[0007] Determine a linear correspondence between a query rate per second and a number of containers based on the plurality of historical query rates per second, and determine a nonlinear correspondence between a query rate per second and a number of containers based on the change rates corresponding to the plurality of query rates per second;
[0008] Detecting a 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 number of scaling containers corresponding to the current query rate per second by using the linear correspondence;
[0009] If the current query rate per second is less than a preset critical value, the nonlinear correspondence is used to determine a second target number of scaling containers corresponding to the current query rate per second.
[0010] Optionally, determining a linear correspondence between a query rate per second and a number of containers based on a plurality of the historical query rates per second includes:
[0011] Obtaining query moments of the 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 moment of the current query rate per second;
[0012] Calculating a third query rate difference between the initial query rate per second and a reference query rate per second;
[0013] Obtaining a maximum query quantity of containers of the server, and calculating a third container quantity corresponding to the third query rate difference, and calculating a fourth container quantity corresponding to the initial query rate per second;
[0014] The quotient of the third container quantity and the reference query rate per second is used as a slope coefficient; and the third container quantity is used as a constant to obtain a target linear function as the linear correspondence.
[0015] Optionally, determining a first target number of scaling containers on the server corresponding to the current query rate per second by using the linear correspondence includes:
[0016] 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.
[0017] Optionally, determining the nonlinear correspondence between the query rate per second and the number of containers based on the change rates corresponding to the plurality of query rates per second includes:
[0018] Obtain query times of the multiple historical query rates per second, 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;
[0019] Calculate the first query rate difference and the first query time difference between the first query rate per second and the second query rate per second respectively; calculate the second query rate difference and the first query time difference between the second query rate per second and the third query rate per second;
[0020] Determine a first change rate according to the first query rate difference and the first query time difference; determine a second change rate according to the second query rate difference and the first query time difference;
[0021] Obtaining a maximum query quantity of containers of the server, and calculating a fifth quantity of containers corresponding to the first change rate, and calculating a sixth quantity of containers corresponding to the second change rate;
[0022] The first change rate and the fifth container quantity, as well as the second change rate and the sixth container quantity, are used to calculate the slope factor and the proportional factor of the preset inverse hyperbolic tangent function to obtain a target inverse hyperbolic tangent function as the nonlinear correspondence, and the target inverse hyperbolic tangent function includes the slope factor and the proportional factor.
[0023] Optionally, the determining, by using the nonlinear correspondence, a second target number of scaling containers on the server corresponding to the current query rate per second includes:
[0024] Calculating a current change rate corresponding to the current query rate;
[0025] The current change rate is input as a variable into the target inverse hyperbolic tangent function to obtain the second target expansion and contraction container quantity.
[0026] Optionally, the method further comprises:
[0027] Determine the default application programming interface associated with scaling;
[0028] The preset expansion and contraction program is called by using the preset application program interface, and the containers in the server are expanded or contracted according to the first target expansion and contraction container quantity or the second target expansion and contraction container quantity.
[0029] Optionally, obtaining the query rate per second of the server and the query rate per second change rate includes:
[0030] Acquire original query data, where the original query data includes the total number of query requests and query request processing time;
[0031] Calculating the average rate of the original query data to obtain the query rate per second of the server;
[0032] An average rate calculation is performed on the query rate per second within a preset period of time to obtain a change rate of the query rate per second within the preset period of time.
[0033] Optionally, the performing average rate calculation on the original query data to obtain the query rate per second of the server includes:
[0034] Convert the unit format of the request processing time into a unified target format to obtain the processed request processing time;
[0035] The quotient of the processed request processing time and the request processing seconds is determined to obtain the query rate per second of the server.
[0036] In a second aspect, an embodiment of the present application provides a computer device, characterized in that the computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the method described in any one of the first aspects when executing the computer program.
[0037] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, characterized in that the storage medium stores a computer program, and when the computer program is executed by a processor, it can implement the method described in any one of the first aspects.
[0038] The beneficial effects of the present application are as follows: different from the prior art, the present application obtains multiple historical query rates per second of the server history records and the change rate of each historical query rate per second; determines the linear correspondence between the query rate per second and the number of containers based on the multiple historical query rates per second, and determines the nonlinear correspondence between the query rate per second and the number of containers based on the change rates corresponding to the multiple query rates per second; detects 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, determines the first target number of scaling containers on the server corresponding to the current query rate per second by using the linear correspondence; if the current query rate per second is less than the preset critical value, determines the second target number of scaling containers on the server corresponding to the current query rate per second by using the nonlinear correspondence.
[0039] The embodiment of the present application can distinguish the system load conditions through multiple historical query rates per second and the change rate of each historical query rate per second. When the current query rate per second is less than the preset critical value, it means that the system load is relatively light. At this time, the linear correspondence can be used to expand and shrink the containers in the server in the future, so that the containers in the system can maintain a relatively stable growth rate, and can avoid the waste of resources or degradation of system performance caused by too fast or too slow shrinkage of the system containers.
[0040] In addition, if the query rate per second changes dramatically, using a linear relationship to scale capacity may cause performance bottlenecks and delays due to excessive load. Therefore, when the current query rate per second is greater than or equal to the preset critical value, it means that the system load is heavy. In this case, a nonlinear relationship is selected to scale the containers in the server. This can guide the scaling operations more quickly and avoid wasting container resources and overloading. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0042] Figure 1 It is a schematic flow chart of the first embodiment of the container expansion and contraction method provided by the present application;
[0043] Figure 2 It is a schematic diagram of the linear function expansion and contraction diagram provided by this application;
[0044] Figure 3 It is a schematic diagram of the expansion and contraction diagram of the inverse hyperbolic tangent function provided by the present application;
[0045] Figure 4 It is a flow chart of a second embodiment of the container expansion and contraction method provided by the present application;
[0046] Figure 5 It is a schematic diagram of the interaction within the system in the container expansion and contraction method provided by the present application;
[0047] Figure 6 It is a structural schematic diagram of an embodiment of a computer-readable storage medium provided by the present application. DETAILED DESCRIPTION
[0048] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It will be understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only some but not all structures related to the present application are shown in the drawings. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0049] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0050] In the Internet industry, server expansion and contraction is one of the key tasks, which is essential to ensure high availability of business and improve service quality. Server expansion and contraction is usually affected by the query rate per second (qps), which means that the increase or decrease of user requests requires dynamic increase or decrease of server resources to meet the demand.
[0051] In the process of researching and practicing related technologies, the inventors of this application found that the current expansion and contraction of servers is usually achieved using automated tools or cloud computing platforms. However, the traditional linear expansion method may have some efficiency and performance deficiencies when dealing with sudden high load situations. Linear expansion cannot quickly adapt to the increase in demand, resulting in a waste of server resources. In addition, when the QPS suddenly increases, linear expansion cannot adjust the server capacity in time, causing the server to be overloaded, resulting in service unavailability.
[0052] Therefore, in order to solve the technical problems of resource waste caused by traditional linear expansion and contraction and service unavailability caused by container overload operation, the present application provides a container expansion and contraction method, wherein the container in the present application is a server. Please refer to the following embodiments for details.
[0053] The following is a detailed introduction to the container expansion and contraction method provided by this application. Figure 1 , Figure 1 It is a flow chart of the first embodiment of the container expansion and contraction method provided in the present application.
[0054] Methods include:
[0055] Step 101: Obtain multiple historical query rates per second of server history records and a change rate of each historical query rate per second.
[0056] Among them, multiple query rates per second and multiple query rates per second can be collected at different time periods of the day. The query rate per second (qps) refers to the number of data queries that the system can process per second. It is usually used to measure the performance and throughput of a system. Usually, the query request count can be obtained by using the operating system's own performance monitor, third-party performance monitoring tools, logging systems, etc., or performance testing tools can be used to collect the query rate per second data of the server at different time points.
[0057] The rate of change of the query rate per second refers to the trend or speed of change of the query rate per second over a period of time. It indicates the speed of increase or decrease of the query rate per second and can be used to monitor the change of system performance and predict the future load and demand of the system. In a specific embodiment, the rate of change can be calculated per second, for example: T a , T b and T c For three adjacent moments, Ta 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 per second Q c The corresponding rate of change is: (Q c -Q b ) / (T c -T b ) ; Query rate per second Q b The corresponding rate of change is: (Q b -Q a ) / (T b -T c ), correspondingly, the change rate of other query rates per second Qn is: (Q n -Q n-1 ) / (T n -T n-1 ). In other embodiments, the interval of the query rate per second can be set to other time intervals as needed, for example: the change rate every 2 seconds, the time interval is 2 seconds, and the change rate every 5 seconds is 5 seconds. In principle, the smaller the time interval, the more detailed the change of the query rate per second, on the contrary, the larger the time interval, the more extensive the change of the query rate per second, and the specific setting is set by the technician according to the needs.
[0058] S102, determining a linear correspondence between a query rate per second and a number of containers based on the plurality of historical query rates per second, and determining a nonlinear correspondence between a query rate per second and a number of containers based on a plurality of change rates corresponding to the query rates per second.
[0059] In the embodiment of the present application, the linear correspondence may be a linear function, and the key factor of the linear function is the slope coefficient. The linear correspondence between the query rate per second and the number of containers is determined based on the multiple historical query rates per second, and the most important thing is to determine the slope function and the slope coefficient of the slope function.
[0060] Specifically, it can be as follows: find the query rate per second at two different query times before and after in the historical query rate per second. Since the maximum number of queries for each container in the service is fixed, for the previous query rate per second, 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 before and after is calculated, and based on the initial number of containers, the container increment M2 corresponding to the query rate difference is calculated. Then, in this embodiment of the application, the linear function corresponding to the linear correspondence is f(x)=M1+(M2 / △Q)*x, where x is the query rate per second, and f(x) is the target number of scaling containers corresponding to the query rate per second x.
[0061] In an embodiment of the present application, the nonlinear corresponding relationship can be an inverse hyperbolic tangent function. In a specific application, the query rates per second at three different query moments can be found in the historical query rates per second. The change rates of the query rates per second at the three different query moments are used. Referring to the description in the aforementioned step S101, the change rate refers to the difference between the latter 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 change rate and then substituting it into the preset inverse hyperbolic function, the slope factor and scale factor of the preset inverse hyperbolic function can be calculated to obtain the target inverse hyperbolic function.
[0062] S103, detecting a 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 number of scaling containers corresponding to the current query rate per second by using the linear correspondence.
[0063] Each query rate represents the demand for data query. When the query rate per second is small, the system load requirement for the server is small. When the query rate per second is large, the system load requirement for the server is large. In order to make the increase or decrease of the server's container consistent with the value of each query rate, in the embodiment of the present application. A preset critical value can be set, and the preset critical value can be determined according to the increase or decrease of the container in the server history. For example: after the query rate per second changes, the increase or decrease of the container cannot meet the data query demand of each query rate, for example: after the query rate per second increases, the response time of the data query request is greater than the preset value, or, after the query rate per second decreases, the utilization rate of the container of the server processing the data query request is lower than the preset value. In specific applications, the preset critical value can also be set by the technician according to the response time of the data query request or the utilization rate of the container of the server processing the data query request, which is not limited here.
[0064] To this end, in this step of the embodiment of the present application, when the current query rate per second is less than the preset critical value, the first target number of scaling containers corresponding to the current query rate per second is directly calculated according to the aforementioned determined linear correspondence.
[0065] S104: If the current query rate per second is less than a preset critical value, determine the second target number of scaling containers on the server corresponding to the current query rate per second by using the nonlinear correspondence.
[0066] In this step of the embodiment of the present application, when the current query rate per second is less than the preset critical value, the second target number of scaling containers corresponding to the current query rate per second is directly calculated according to the nonlinear correspondence relationship determined above.
[0067] The embodiment of the present application can distinguish the system load conditions through multiple historical query rates per second and the change rate of each historical query rate per second. When the current query rate per second is less than the preset critical value, it means that the system load is relatively light. At this time, the linear correspondence can be used to expand and shrink the containers in the server in the future, so that the containers in the system can maintain a relatively stable growth rate, and can avoid the waste of resources or degradation of system performance caused by too fast or too slow shrinkage of the system containers.
[0068] In addition, if the query rate per second changes dramatically, using a linear relationship to scale the capacity may cause performance bottlenecks and delays due to excessive load. Therefore, when the current query rate per second is greater than or equal to the preset critical value, it means that the system load is heavy. In this case, a nonlinear relationship is selected to scale the containers in the server. This can guide the scaling operation more quickly and avoid waste of container resources and overload operation.
[0069] In one embodiment of the present application, to calculate the change rate of the query rate per second, it is necessary to use the query rate data within a certain time range. For example, the change rate of the query rate per second can be calculated using the following method:
[0070] 1) Obtain the query rate data per second within the time period. For example, obtain the query data corresponding to the query rate per second, and record the timestamp corresponding to each query data.
[0071] 2) For each query data, calculate the change between it and the previous query data (such as the difference in the data volume of the query data or the increment of the data volume), 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.
[0072] 3) Divide the increment of each query data by the time interval (usually seconds) to obtain the change rate of the query rate per second, that is, divide each increment by the time difference to obtain the change rate per second.
[0073] For example, assuming that 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:
[0074] qps change rate = (Qe-Qd) / ΔT.
[0075] That is, the rate of change of qps can be calculated based on the number of queries at two time points.
[0076] In order to collect data more conveniently, and to perform complex statistics, calculations and screening on the collected data. Therefore, in some embodiments, a server monitoring system (e.g., Prometheus) is used to collect query data. Among them, Prometheus is an open source server monitoring and alarm system based on a time series database. Since Prometheus provides a simple and easy-to-use data model and query language, data collection and monitoring configuration become relatively simple. Secondly, Prometheus provides flexible and powerful query and aggregation functions. Through the PromQL query language in Prometheus, you can easily calculate the summary, average, percentage, etc. of various indicators, and support customized alarm conditions and alarm rules.
[0077] The process of collecting query data using the server monitoring system can be specifically referred to the following sub-steps:
[0078] Step 1011: Obtain original query data, which includes the total number of requests and request processing time.
[0079] In this step, the original query data can be obtained from the preset indicator interface. In Prometheus, the indicator collection task can be configured first to regularly obtain the required data from the server's indicator interface. The preset indicator interface can be an HTTP interface exposed to Prometheus, a data interface provided by the Exporter plug-in, or an interface of other supported data sources.
[0080] Step 1012: Calculate the average rate of the original query data to obtain the query rate per second of the server.
[0081] In this step, you can use the preset query statement to calculate the average rate of the original query data. In Prometheus, the preset query statement can be: PromQL (PrometheusQueryLanguage), and PromQL can be used to query and calculate data. The query rate per second is calculated by using the rate() function.
[0082] The following is a sample PromQL query:
[0083] avg_over_t ime(request_tota l[1m]) / avg_over_t ime(request_processing_t ime_seconds_sum[1m]).
[0084] This query statement uses the avg_over_time() function to calculate the total number of requests (request_total) within the specified time range. At the same time, the avg_over_time() function can also calculate the average rate of request processing time (request_processing_time_seconds_sum).
[0085] In some embodiments, the request processing time may be converted into corresponding request processing seconds, and the query rate per second of the server may be determined based on the quotient of the total number of requests and the request processing seconds.
[0086] For example, use the PromQL built-in function seconds() to convert the request processing time into the corresponding number of seconds, divide the total number of requests by the request processing seconds, and get the number of queries per second, that is, the query rate per second.
[0087] Specifically, convert the time of a day into seconds. There are 24 hours in a day, 60 minutes in an hour, and 60 seconds in a minute, so there are 24*60*60=86400 seconds in a day.
[0088] Then divide the total number of requests in a day by the request processing time to get the average number of requests processed per second.
[0089] Query rate per second = total number of requests / request processing time.
[0090] Assuming there are 100,000 requests a day and the request processing time is 10 hours, the query rate per second can be calculated as follows:
[0091] There are 24*60*60=86400 seconds in a day. The query rate per second = 100000 / (10*60*60)≈0.2778 queries / second
[0092] That is, the query rate per second is about 0.2778 / second.
[0093] Step 1013: Calculate the average rate of the query rate per second in the preset time period to obtain the query rate per second change rate in the preset time period.
[0094] In Prometheus, you can use a preset query statement to calculate the average rate of the query rate per second in a preset time period, where the preset query statement can be: PromQL query statement, and you can further use the avg_over_time() function to calculate the average rate of the query rate per second in a specified time range, so as to obtain the change rate of the query rate.
[0095] The following is a sample PromQL query:
[0096] rate(avg_over_t ime(request_rate[5m])[10m:1m]).
[0097] This query statement first calculates the query rate per second (request_rate) in the past 5 minutes through the avg_over_time() function, and then uses the rate() function to calculate the rate of change of the query rate from the past 10 minutes to the past minute.
[0098] In one embodiment of the present application, in the aforementioned step S102, determining the linear correspondence between the query rate per second and the number of containers based on the plurality of historical query rates per second may include the following steps:
[0099] S201, obtaining the query times of the multiple historical query rates per second.
[0100] In the embodiment of the present application, two query rates per second are taken as an example for illustration. Specifically, the multiple query rates per second include: an initial query rate per second Q 初 and reference query rate per second Q 参 , and 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 初 The query rate per second Q 参 The query times are adjacent.
[0101] In the embodiment of the present application, adjacent query moments refer to those determined according to the set query interval. For example, when the query interval is 1 second, adjacent query moments refer to two query rates per second that are adjacent to each other for 1 second; when the query interval is 5 seconds, adjacent query moments refer to two query rates per second that are adjacent to each other for 5 seconds.
[0102] S202, calculating the initial query rate per second Q 初 and reference query rate per second Q 参 The third query rate difference △Q3.
[0103] S203, obtaining the number of queries that can be processed by each container of the server, obtaining and calculating the number of third containers M3 corresponding to the third query rate difference ΔQ3, and calculating the number of fourth containers M4 corresponding to the initial query rate per second.
[0104] S204, compare the third container quantity M3 with the reference query rate per second Q 参 The quotient is determined as the slope coefficient K; the number of the third container is taken as a constant a, and a target linear function is obtained as the linear correspondence.
[0105] Among them, 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 the time before the current time. According to the given linear function form y=f(x)=a+k*x, it can be known that 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), that is, y, represents the number of containers.
[0106] Exemplarily, assuming that the reference query rate per second is 300qps, the initial query rate per second is 100qps, and the query rate per second that each container can process is 100qps, then the difference in query rate per second is reference query rate per second - initial query rate per second = 300-100 = 200qps, then the difference in query rate per second 200qps is divided by the number of queries that each container can process 100qps, and the container increment is 2, then the container increment required for the reference query rate per second of 300qps is 2, and in addition, the initial query rate per second is 100gps divided by the number of queries that each container can process 100qps, and the initial number of containers is 1, and then the number of containers corresponding to the initial query rate per second is increased by 2, so the container requirement of the reference query rate per second can be met.
[0107] When the linear function form f(x) = a + k*x is calculated, the constant a and the slope coefficient d are obtained, and then the following is obtained: Figure 2 The linear function scaling graph shown.
[0108] In some embodiments, after the target linear function f(x)=a+k*x is determined in steps S201-S204, the current query rate per second can be directly used as a variable x and substituted into the target linear function, and the obtained value can be used as the first target number of expansion and contraction containers.
[0109] In some embodiments, in the aforementioned step S102, based on the change rates corresponding to the plurality of query rates per second, a nonlinear correspondence between the query rate per second and the number of containers is determined. The determination of the nonlinear correspondence may specifically include the following process:
[0110] S301, obtaining the query times of the multiple historical query rates per second.
[0111] In the embodiment of the present application, three query rates per second are taken as an example for illustration. Specifically, the multiple query rates per second include:
[0112] The query rate change rate per second can be obtained by using step 101, assuming that the first query time of the first query rate per second Q1 is t1, the second query time of the second query rate per second Q2 is t2, and the third query time of the third query rate per second Q3 is t3.
[0113] S302, respectively calculating a first query rate difference and a first query time difference between the first query rate per second and the second query rate per second; calculating a second query rate difference and a first query time difference between the second query rate per second and the third query rate per second.
[0114] The first query rate difference between the first query rate per second Q1 and the second query rate per second Q2 is (Q2-Q1), and the first query time difference is (t2-t1).
[0115] A second query rate difference between the second query rate Q2 and the third query rate Q3 is (Q3-Q2), and a second query time difference is (t3-t2).
[0116] S303, determining a first change rate according to the first query rate difference and the first query time difference; determining a second change rate according to the second query rate difference and the first query time difference.
[0117] The first change rate is rate1, and the second change rate is rate2. The first change rate is rate1 (Q2-Q1) / (t2-t1), and the second change rate is rate2 (Q3-Q2) / (t3-t2).
[0118] S304, obtaining a maximum query quantity of containers of the server, and calculating a fifth quantity of containers corresponding to the first change rate, and calculating a sixth quantity of containers corresponding to the second change rate.
[0119] The number of the fifth container is M5, and the number of the sixth container is M6.
[0120] S305, using the first change rate and the fifth container quantity, as well as the second change rate and the sixth container quantity, calculate the slope factor and the scale factor of the preset inverse hyperbolic tangent function to obtain a target inverse hyperbolic tangent function as the nonlinear correspondence, and the target inverse hyperbolic tangent function includes the slope factor and the scale factor.
[0121] Specifically, for example, the query rate per second at time t1 is 150, the query rate per second at time t2 is 300qps, and the query rate per second at time t3 is 500qps, wherein the difference between time t1 and time t2 is 3 seconds, and the difference between time t2 and time t3 is 5 seconds. The first change rate is (300-150)qps / (t2-t1)=50qps / second, indicating an increase of 50 qps per second. Since the container processing capacity of each container is 100qps, the number of container changes is 50 / 100=0.5, and a point (50qps / second, 0.5) can be obtained; the second change rate is (500-300)qps / 5=40qps / second, indicating an increase of 40 qps per second. Since the container processing capacity of each container is 100qps, the number of container changes is 40 / 100=0.4, and another point (40qps / second, 0.4) can be obtained.
[0122] Based on the corresponding relationship between the change rate and the container of the server, the slope factor and the scale factor of the inverse hyperbolic tangent function are determined; then based on the slope factor and the scale factor, the inverse hyperbolic tangent function is determined.
[0123] For example, using the above method for calculating the number of container changes, two sets of corresponding relationships between the number of container changes and the change rate are obtained, such as point A (x1, y1) and point B (x2, y2). According to the given function form f(x) = a*artanh(b*x), in which x is the change rate, i.e., the qps change rate, and f(x) i.e., y is the number of container changes, the two points can be substituted into the function to obtain the following two equations:
[0124] y1=f(x1)=a*artanh(b*x1);
[0125] y2=f(x2)=a*artanh(b*x2);
[0126] Exemplarily, the values of point A and point B can be substituted by the above-obtained (40 qps / sec, 0.4 unit) and (50 qps / sec, 0.5 unit) to solve for the values of a and b.
[0127] Due to the nature 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 actual business needs.
[0128] Among them, a is the scale factor, that is, the vertical scaling parameter of the function curve. It determines the amplitude of the function's vertical change. When the value of a increases, the vertical change amplitude of the function will also increase; when the value of a decreases, the vertical change amplitude of the function will also decrease. b is the slope factor, that is, the parameter related to the horizontal scaling and slope of the function curve. It controls the slope and horizontal expansion of the function curve. When the value of b increases, the slope of the function curve tends to become steeper and shrink horizontally; when the value of b decreases, the slope of the function curve tends to become slower and expand horizontally.
[0129] Then, according to the slope factor b and the proportional factor a, we can get Figure 3 The inverse hyperbolic tangent function is shown in the expansion and contraction diagram.
[0130] In some embodiments, specifically: for example, the current change rate, that is, the current qps change rate, can be obtained based on the change rate 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*artanh(b*x) in steps 301-305 to obtain the relationship between the current qps change rate and the container change, and then determine the number of the second target expansion and contraction containers.
[0131] In other embodiments of the present application, after the aforementioned step S103 or S104, as Figure 4 As shown, the following steps may also be included:
[0132] Step 105: Determine a default application programming interface associated with scaling.
[0133] Step S106: using a preset application program interface to call a preset scaling deployment program, and using the preset scaling deployment program to scale containers in the server according to the first target scaling container quantity or the second target scaling container quantity.
[0134] The preset application program interface may be an API interface of Kubernetes (K8s for short), and Kubernetes is pre-defined as an interface related to expansion and contraction. The pre-definition can be determined through a corresponding relationship table. For example, the identifier of expansion and contraction may be: Expansion, and the identifier of the preset application program interface may be: Kubernetes. A corresponding relationship table of Expansion-Kubernetes is pre-stored in the server. When it is determined that expansion and contraction are required, Kubernetes can be found by searching for the identifier Expansion. The preset scaling deployment program may be DeploymentScale, and DeploymentScale may be called through the K8s API interface to perform expansion and contraction.
[0135] Among them, DeploymentScale is a scaling deployment program module, which is usually used to automatically adjust the resource configuration of applications or services to adapt to changes in traffic. By using the scaling deployment program module, the number of containers, containers, or virtual machines can be increased or decreased as needed to ensure that the application has good performance and reliability. This automatic scaling capability can improve the elasticity and scalability of applications and adapt them to changing workload requirements.
[0136] Kubernetes is an open source container orchestration platform that can automatically manage the deployment, scaling, and operation of containerized applications. Since Kubernetes provides a powerful set of APIs, you can use APIs to automate scaling operations, reducing the workload and risk of errors in manual operations. In addition, through Kubernetes' APIs, you can dynamically adjust the number of containers based on real-time load conditions and customized policies to adapt to different workloads and traffic requirements.
[0137] In addition, this embodiment uses a preset application interface to trigger a preset scaling deployment module, and uses the preset scaling deployment program module to expand and shrink the containers in the server. It can dynamically adjust the number of containers according to real-time load conditions and customized policies to adapt to different workloads and traffic requirements.
[0138] In combination with the above embodiments, it can be seen that the container expansion and contraction method provided by the present application specifically includes the following process, see Figure 5 .
[0139] 1) Use Prometheus to obtain raw query data, including the total number of requests and request processing time, and calculate qps and qps change rate based on the obtained data;
[0140] 2) Based on the qps and qps change rate calculated by Prometheus, we can get the following results: Figure 3 The inverse hyperbolic tangent function expansion and contraction graph and the linear function expansion and contraction graph shown in the figure are as follows:
[0141] 3) Determine the relationship between the query rate per second and the preset critical value. If the query rate per second is less than the preset critical value, execute step 4); if the query rate per second is greater than or equal to the preset critical value, execute step 5);
[0142] 4) Use linear functions to scale containers in the server;
[0143] 5) Use the inverse hyperbolic tangent function to scale the containers in the server. ArtanhScale can be used to calculate the number of containers that need to be scaled up or down, and DependencyScale can be triggered to scale up or down through the k8s API.
[0144] 6) Use DependencyScale to change the number of containers in the system according to the calculated number of containers that need to be expanded or reduced, that is, DependencyScale is responsible for the actual expansion and reduction work.
[0145] See also Figure 6 , Figure 6 1 is a schematic diagram of a structure of an embodiment of a computer-readable storage medium provided by the present application. The computer-readable storage medium 90 is used to store a computer program 91. When the computer program 91 is executed by a controller, it is used to implement the following method steps:
[0146] Obtain multiple query rates per second and multiple query rate change rates per second of the server; determine a linear function based on the multiple query rates per second, and determine an inverse hyperbolic tangent function based on the multiple query rate change rates per second; if the query rate per second is greater than or equal to a preset critical value, use the inverse hyperbolic tangent function to scale the container in the server; if the query rate per second is less than the preset critical value, use a linear function to scale the container in the server.
[0147] It can be understood that when the computer program 91 is executed by the controller, it is also used to implement the technical solution of any embodiment in the present application.
[0148] 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 implementation described above is only illustrative, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0149] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0150] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0151] If the integrated units in the above other embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application is essentially 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, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a container, or a network device, etc.) or a controller (processor) to perform all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-On l yMemory), a random access memory (RAM, Random Access Memory), a disk or an optical disk.
[0152] The above are only implementation methods of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for determining the expansion and contraction of a container, characterized in that: The method comprises: Get multiple historical query rates per second of the server history records and the change rate of each historical query rate per second; Determine a linear correspondence between a query rate per second and a number of containers based on the plurality of historical query rates per second, and determine a nonlinear correspondence between a query rate per second and a number of containers based on the change rates corresponding to the plurality of query rates per second; Detecting a 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 number of scaling containers corresponding to the current query rate per second by using the linear correspondence; If the current query rate per second is less than a preset critical value, the nonlinear correspondence is used to determine a second target number of scaling containers corresponding to the current query rate per second.
2. The method according to claim 1, characterized in that Determining a linear correspondence between a query rate per second and a number of containers based on the plurality of historical query rates per second includes: Obtaining query moments of the 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 moment of the current query rate per second; Calculating a third query rate difference between the initial query rate per second and the reference query rate per second; Obtaining a maximum query quantity of containers of the server, and calculating a third container quantity corresponding to the third query rate difference, and calculating a fourth container quantity corresponding to the initial query rate per second; The quotient of the third container quantity and the reference query rate per second is used as a slope coefficient; and the third container quantity is used as a constant to obtain a target linear function as the linear correspondence.
3. The method according to claim 2, characterized in that Determining a first target number of scaling containers on the server corresponding to the current query rate per second by 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.
4. The method according to claim 1, characterized in that: The determining, based on the change rates corresponding to the plurality of query rates per second, a nonlinear correspondence between the query rate per second and the number of containers comprises: Obtain query times of the multiple historical query rates per second, 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 and the first query time difference between the first query rate per second and the second query rate per second respectively; calculate the second query rate difference and the first query time difference between the second query rate per second and the third query rate per second; Determine a first change rate according to the first query rate difference and the first query time difference; determine a second change rate according to the second query rate difference and the first query time difference; Obtaining a maximum query quantity of containers of the server, and calculating a fifth quantity of containers corresponding to the first change rate, and calculating a sixth quantity of containers corresponding to the second change rate; The first change rate and the fifth container quantity, as well as the second change rate and the sixth container quantity, are used to calculate the slope factor and the proportional factor of the preset inverse hyperbolic tangent function to obtain a target inverse hyperbolic tangent function as the nonlinear correspondence, and the target inverse hyperbolic tangent function includes the slope factor and the proportional factor.
5. The method according to claim 4, characterized in that The determining, by using the nonlinear correspondence, the second target number of scaling containers on the server corresponding to the current query rate per second, includes: Calculating a current change rate corresponding to the current query rate; The current change rate is input as a variable into the target inverse hyperbolic tangent function to obtain the second target expansion and contraction container quantity.
6. The method according to claim 1, characterized in that The method further comprises: Determine the default application programming interface associated with scaling; The preset expansion and contraction program is called by using the preset application program interface, and the containers in the server are expanded or contracted according to the first target expansion and contraction container quantity or the second target expansion and contraction container quantity.
7. The method according to claim 1, characterized in that The obtaining of the query rate per second of the server and the query rate per second change rate includes: Acquire original query data, where the original query data includes the total number of query requests and query request processing time; Calculating the average rate of the original query data to obtain the query rate per second of the server; An average rate calculation is performed on the query rate per second within a preset period of time to obtain a change rate of the query rate per second within the preset period of time.
8. The method according to claim 7, characterized in that The calculating the average rate of the original query data to obtain the query rate per second of the server includes: Convert the unit format of the request processing time into a unified target format to obtain the processed request processing time; The quotient of the processed request processing time and the request processing seconds is determined to obtain the query rate per second of the server.
9. A computer device, characterized in that: The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 can be implemented.
Citation Information
Patent Citations
Intelligent dynamic capacity expansion method for server
CN110377424A
Per-second query rate adjustment method and device, electronic equipment and a storage medium
CN111291252A
System capacity expansion and contraction method and device and electronic equipment
CN112925607A
Server cluster capacity evaluation method and device, electronic equipment and storage medium
CN113407426A
Automatic capacity expansion and contraction method and system for live broadcast system
CN113507618A
