Container cold start optimization method based on server-free function workflow branch prediction

By using function runtime indicators and historical access data for branch prediction in a serverless computing architecture, combined with the adaptive two-level predictor and exponential moving average method, the container warm-up time is optimized, the container cold start problem is solved, and resource savings are achieved. and latency reduction, suitable for multi-platform environments.

CN118689592APending Publication Date: 2024-09-24ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410736315.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

In a serverless computing architecture, container cold start takes a long time, resulting in increased request processing delays. The existing preheating strategy relies on user configuration and is not flexible enough. It cannot effectively utilize the correlation between functions, resulting in resource waste and performance loss.

Method used

A container cold start optimization method based on serverless function workflow branch prediction is designed. By calculating the function's runtime indicators and historical access data, it predicts the branches that may be selected in the next stage and performs appropriate warm-up when the request arrives. , combined with the adaptive two-level predictor and exponential moving average method, real-time adjustment of the warm-up time point to avoid cold start.

Benefits of technology

It significantly reduces the end-to-end delay of request processing, improves the efficiency of workflow, supports multi-platform expansion and migration, and provides resource saving and performance optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118689592A
    Figure CN118689592A
Patent Text Reader

Abstract

The invention discloses a container cold start optimization method based on server-free function workflow branch prediction, which is characterized in that a global Serverless function container scheduler is designed in combination with the characteristics of Serverless workflow, the execution time and preheating time of each function are obtained through workflow historical access data, and the service life of each function is prolonged. On the basis of the historical access data and the execution condition of the function in the workflow, possibly selected branches in the next stage are predicted; according to the method, historical data and prediction data are combined, when the function is requested to be called, the function possibly called in the workflow is appropriately preheated in advance, and then the cold start problem is relieved. Meanwhile, according to the method, the moment when the container is preheated is close to the moment when the request just enters the container as much as possible, and therefore the purposes of saving resources and reducing end-to-end delay are achieved. According to the method, a brand new solution is provided for optimization of the cold start problem on the Serverless workflow, and the efficiency of the workflow can be remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of serverless computing architecture, and specifically relates to a container cold start optimization method based on serverless function workflow branch prediction. Background Art

[0002] With the development of the Internet, the architecture of service deployment has gradually evolved from the initial single service to microservices, and then to the serverless architecture. Serverless technology is a cloud computing execution model that aims to allow developers to only focus on the implementation of business logic, while the operation, maintenance and configuration of the server are all implemented by the cloud service provider. Compared with the previous microservice architecture, Serverless uses functions as the smallest deployment unit, so that the system can be split into finer granularity, reducing the cost of starting function instances, so that the on-demand startup strategy of function instances can be applied, thereby improving resource utilization.

[0003] Obviously, a single Serverless function cannot meet complex business needs. When there is a calling relationship between functions, a workflow is constructed, which is a directed acyclic graph. This calling relationship can be specified implicitly or explicitly. Implicit specification means that in each Serverless function logic, calls to other functions are implemented; while explicit specification is the corresponding management tool provided by the cloud service provider to developers. Developers draw the entire Serverless workflow in the tool in advance, and define the request and return values ​​of each stage respectively, and determine which function to access next based on the return value. The biggest difference between the two is that explicit specification directly tells the scheduler the workflow mode, while implicit specification requires the scheduler to collect historical access data and analyze it to derive the workflow mode. Currently, both of these two types of specifications have corresponding applications. Implicitly specified workflows are mostly migrated from traditional microservices. They simply split microservices into smaller functions, while retaining the calls to downstream functions. Many microservice vendors also provide corresponding capabilities for explicitly specified workflows, such as Lambda Step Function provided by Amazon Web Service (AWS) or Durable Functions provided by Microsoft Azure.

[0004] After fine-grained splitting, on-demand scheduling and on-demand allocation of resources for each function can be achieved. In the Serverless model, for a function, when a request comes, if there is no available container at the moment, resources will be allocated and scheduled for the function. This startup mode is also called cold start. After the function is used, if it is idle for a long time, the instance of the function will be killed to release resources. For the traditional microservice architecture, if each service is frequently started and stopped, the cost of restarting is unacceptable.

[0005] Although the on-demand scheduling strategy of the Serverless model saves resources to a certain extent, the cold start of the container is a relatively time-consuming operation. The steps of the cold start generally include container image pulling, runtime initialization, and function initialization. The existence of the cold start will lead to a longer end-to-end execution time for the request that hits the cold start. The functions in the workflow are distributed in a cascade, and each level of functions needs to be cold started, which means that the absolute value of the cold start time will increase as the call chain lengthens. In particular, for some functions with a shorter execution time, their cold start time may even be longer than the execution time, and such overhead is obviously too heavy.

[0006] In academia, Nilanjan et al. also touched on this issue in a 2020 paper. The paper proposed a set of methods to obtain implicit Serverless workflow call relationships and use a probability-based prediction method to predict Serverless workflow branches, so as to perform corresponding warm-up operations and alleviate the Serverless cold start problem. However, the probability-based prediction model used in this work is relatively simple, and the prediction results are relatively inaccurate for access sequences with a certain periodicity.

[0007] In the industry, mainstream cloud service providers have taken some measures to alleviate the cold start problem. For example, AWS and Azure allow users to configure the number of preheated instances. This configuration specifies the minimum number of instances that the Serverless function should retain. When the number of concurrent requests is less than the preset number of concurrent requests, all requests can hit the preheated function container, thus avoiding the cold start problem. However, the configured preset number of concurrent requests is a fixed value and is manually specified by the user. It is not flexible enough and highly dependent on user experience. If the configuration is inaccurate, too many idle containers will cause waste of resources, and too few idle containers will still cause the cold start problem. On the other hand, for the workflow scenario, the functions at each level are often associated with their upper and lower level functions, and this association also affects the reasonable planning of the number of concurrent requests. However, the strategies of AWS and others do not take advantage of this association, resulting in additional performance waste. Summary of the invention

[0008] In view of the defects in the above technical background, the present invention provides a container cold start optimization method based on serverless function workflow branch prediction. In combination with the characteristics of Serverless workflow, the present invention designs a global Serverless function container scheduler, obtains the execution time and preheating time of each function through the historical access data of the workflow, and predicts the branches that may be selected in the next stage based on the historical access data and the execution of the function in the workflow. By combining historical data and predicted data, the algorithm preheats the functions that may be called in the workflow in advance when requesting to call the function, thereby alleviating the cold start problem. At the same time, the algorithm makes the moment when the container is preheated as close as possible to the moment when the request just enters the container, so as to achieve the purpose of resource saving and reducing end-to-end latency.

[0009] The present invention is implemented by the following technical solutions:

[0010] A container cold start optimization method based on serverless function workflow branch prediction includes the following steps:

[0011] Function runtime indicator calculation: Calculate the average running time and average initialization time of each function in the workflow, and use the average running time and average initialization time as the function runtime indicators;

[0012] Branch prediction: predicts the functions that may be executed in the workflow and the calling relationships between functions through the workflow's historical access data and the access data of the current request;

[0013] Container preheating time point calculation: based on the function runtime indicators and branch prediction results, calculate and predict the preheating time point of each function in the workflow;

[0014] Container scheduling: preheat the function based on the preheating time point; at the same time, according to the actual situation of the request, call the corresponding function, and compare the actual workflow currently being executed with the predicted workflow in real time. When there is a deviation between the predicted workflow and the actual workflow, terminate the subsequent preheating of the current predicted workflow, and recalculate the branch prediction and container preheating time point.

[0015] In the above technical solution, further, the initialization time includes the image pulling time, the function running environment initialization time and the time of the initialization operation of the function itself; the function runtime index is calculated using the exponential moving average method.

[0016] Further, the branch prediction is implemented based on an adaptive two-level predictor, which uses a two-bit local history counter to record each global history record pattern of each branch to form a pattern history record table PHT; the strong selection, weak selection, weak non-selection, and strong non-selection in the access mode are encoded as 11, 10, 01, and 00 respectively, and when the high bit is 1, it is selected, and when the high bit is 0, it is not selected. Each time it is selected or not selected, the local history counter will move one step in the direction of selection or non-selection, and record the global history record pattern of the current branch; using the adaptive two-level predictor to predict the direction of each branch, specifically including the following steps:

[0017] (1) Request to trigger a function;

[0018] (2) Based on the history records of the currently accessed function, the adaptive two-level predictor traverses the lower-level functions that have a calling relationship with the current function, queries the PHT of each function to see whether the high bit of the counter corresponding to the access mode of the current function is 1. If the high bit is 1, it means that the function may be accessed and the calling relationship between functions is recorded;

[0019] (3) Add the functions that may be accessed to the global function history and repeat the operation in (2) until the entire workflow is traversed.

[0020] Furthermore, the container preheating time point calculation specifically includes the following steps:

[0021] (1) Based on the predicted workflow, record the predecessor nodes preNodes and successor nodes succNodes of each node; traverse the nodes at each level in sequence until the traversal ends the workflow, and record the exit node of the workflow;

[0022] (2) Each node in the workflow is queued in order to form a queue, and the initial position of the queue stores the entry node of the workflow;

[0023] (3) Get the head node of the queue and dequeue it; traverse the preNodes of the head and calculate the completion time node of each predecessor node i of the head. The calculation formula is as follows:

[0024]

[0025] in, Represents the time point when node i starts executing, and Represents the time required for node i to initialize and run;

[0026] The current sequence node After all calculations are completed, the latest end time T among the previous nodes is calculated. preLatest :

[0027] T preLatest =max(T preFinish )

[0028] According to T preLatest Then further calculate the warm-up time T that the current node should start prewarmstart :

[0029] T prewarmStart =max(0, T preLatest -t init )

[0030] Among them, t init is the initialization time of the current node, based on the scheduled start execution time point T of the current node preLatest Advance t init , which is the warm-up time T of the current node prewarmStart ;

[0031] (4) Repeat step (3) until the queue is empty.

[0032] The present invention also provides a container cold start optimization system based on serverless function workflow branch prediction, comprising

[0033] The function runtime indicator calculation module is used to calculate the average running time and average initialization time of each function in the workflow, and use the average running time and average initialization time as the function runtime indicator;

[0034] The branch prediction module is used to predict the functions that may be executed in the workflow and the calling relationship between functions through the workflow history access data and the current request access data;

[0035] A container preheating time point calculation module, used to calculate the preheating time point of each function in the prediction workflow based on the function runtime indicator and the prediction result of the branch prediction module;

[0036] The container scheduling module is used to preheat the function based on the preheating time point; at the same time, according to the actual situation of the request, the corresponding function is called, and the actual workflow currently being executed and the predicted workflow are compared in real time. When there is a deviation between the predicted workflow and the actual workflow, the subsequent preheating of the current predicted workflow is terminated, and the branch prediction module and the container preheating time point calculation module are controlled to re-predict the branch and recalculate the container preheating time point.

[0037] The beneficial effects of the present invention are:

[0038] The present invention proposes a container cold start optimization method based on branch prediction on a Serverless workflow, which combines the global access history and local access history of the Serverless workflow, and simultaneously cooperates with the acquired historical access data and current access data to calculate the runtime indicators of the function in real time, and then predicts the warm-up time of each function in the workflow, and preheats the function with the help of the predicted value to avoid triggering a container cold start when a request enters the function, thereby reducing the end-to-end delay of request processing. In addition, the method supports docking with multiple external platforms, making it easier to expand and migrate the method between different environments and platforms. Overall, the invention provides a new solution for optimizing the cold start problem on Serverless workflows, which can significantly improve the efficiency of the workflow, reduce response delays, and provide certain scalability and compatibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 This is the overall architecture diagram of this method;

[0040] Figure 2 It is a Serverless workflow diagram;

[0041] Figure 3 is the state machine of the local history counter;

[0042] Figure 4 It is the architecture of an adaptive two-level predictor. DETAILED DESCRIPTION

[0043] The technical solution of the invention is further described below in conjunction with the accompanying drawings and embodiments.

[0044] Figure 1The overall architecture diagram of the method is presented. The method can be implemented using a container cold start optimization system based on serverless function workflow branch prediction. The container cold start optimization system based on serverless function workflow branch prediction consists of a branch prediction module, a container preheating time point calculation module, a function runtime indicator calculation module, and a Serverless container scheduler (i.e., a container scheduling module). The function runtime indicator calculation module can calculate the average execution time and average initialization time of each function in the workflow, and use the average result as the function runtime indicator; the branch prediction module can predict the functions that may be executed in the workflow and the calling relationship between functions through the workflow historical access data and the current request access data; the container preheating time point calculation module can calculate the preheating time point for each function in the predicted workflow based on the function runtime indicator and the branch prediction results; the serverless container scheduler can preheat the functions involved based on the calculated preheating time point, and at the same time, call the corresponding function according to the actual situation of the request, and compare the actual workflow currently being executed with the predicted workflow in real time. Once the predicted workflow and the actual workflow are found to deviate, the branch prediction module and the container preheating time point calculation module are promptly controlled to re-predict and calculate to avoid further waste of resources. The specific implementation methods of each module are introduced in detail below.

[0045] 1. Branch prediction module

[0046] Figure 2 A possible Serverless workflow diagram is presented. There are often multiple branches in a workflow, and when the request does not execute the corresponding branch, the scheduler is not sure which branch's container should be scheduled. Therefore, the present invention designs a branch prediction module, which uses an adaptive two-level predictor that combines global history records and local history records to predict the direction of each branch. By recording the global branch history experienced by each request in the workflow, as well as the local history of each function being accessed, the branch jump behavior is tracked.

[0047] Figure 4 It is the architecture of the adaptive two-level predictor. The adaptive two-level predictor uses a two-bit local history counter to record each global history pattern of each branch. The local history counter records the selection records of the current branch in the past few times. If the strong selection, weak selection, weak non-selection, and strong non-selection in the access pattern are encoded as 11, 10, 01, and 00 respectively, such as Figure 3As shown in the figure, each selection or non-selection will cause the counter to move one step in the direction of selection or non-selection (selection when the high bit is 1, non-selection when the high bit is 0). In this way, the counter can track the jump history of each function access pattern, so as to determine whether the branch should be selected in the current situation. These jump histories constitute the Pattern History Table (PHT).

[0048] Based on the above adaptive two-level predictor, this method can predict the functions that may be accessed by each request. The specific steps are as follows:

[0049] (1) Request to trigger a function;

[0050] (2) Based on the history of the currently accessed function, the predictor traverses the subordinate functions that have a calling relationship with the current function, and queries the PHT of each function to see whether the high bit of the counter corresponding to the access mode of the current function is 1. If the high bit is 1, it means that the function may be accessed and the calling relationship between functions is recorded;

[0051] (3) Add the functions that may be accessed to the global function history and repeat the operation in (2) until the entire workflow is traversed.

[0052] 2. Function runtime indicator calculation module

[0053] The indicators that the method of the present invention is concerned with are mainly the running time and initialization time of each function. These two time indicators have a direct impact on the subsequent selection of the preheating time point. For the same function, different requests may trigger different internal logic, which may cause the running time to fluctuate. For cold start, the initialization time includes the image pulling time, the function running environment initialization time, and the time for the initialization operation of the function itself. For the same function, the length of the initialization time is basically stable.

[0054] In order to better fit the actual situation of the function, this module introduces the Exponential Moving Average (EMA) to calculate the average running time and average initialization time of the function. EMA gives higher weight to more recent access history and also takes more distant access history into consideration.

[0055]

[0056] Formula (1) is the calculation formula for time, where: is the calculated time after exponential averaging; a is the smoothing coefficient. In this method, a is taken as 0.9, which means that the average calculation is performed using the time of the last 10 function accesses; T t and Tt-1 The time of the current function access and the time of the last function access.

[0057] For each trigger of the function, the module will perform rolling calculations on the function's average running time and average initialization time to ensure real-time updates of the function's runtime indicators.

[0058] 3. Container preheating time calculation module

[0059] Based on the results of the above two modules, namely the branch prediction results and function runtime indicators, this module calculates the warm-up time point of each function in the branch prediction results. When the time point comes, the subsequent scheduler preheats the corresponding function. The calculation steps of the warm-up time point are as follows:

[0060] (1) Through the results of the branch prediction module, a predicted workflow can be obtained. Based on the predicted workflow, the predecessor nodes preNodes and successor nodes succNodes of each node are recorded. The nodes at each level are traversed in sequence until the traversal ends the workflow, and the exit node of the workflow is recorded.

[0061] (2) Use the breadth-first search (BFS) method to calculate the warm-up time of each node in the workflow in order. BFS queues each node in the workflow in order to form a queue, and the initial position of the queue stores the entry node of the workflow.

[0062] (3) Get the head node of the queue and dequeue it. Traverse the preNodes of the head and calculate the completion time of each predecessor node i of the head. The calculation formula is shown in formula (2):

[0063]

[0064] In formula (2), Represents the time point when node i starts executing, and Represents the time required for node i to initialize and run.

[0065] The current sequence node After all calculations are completed, the latest end time T among the previous nodes is calculated. preLatest , as shown in formula (3).

[0066] T preLatest =max(T preFinish ) (3)

[0067] Calculate T preLatestAfter that, the warm-up time T that the current node should start can be calculated. prewarmStart , as shown in formula (4).

[0068] T prewarmStart =max(0, T preLatest -t init ) (4)

[0069] That is, the latest end time T among the previous nodes preLatest That is, the scheduled start execution time of the current node. The initialization time t of the current node is already known. init , based on the scheduled start execution time point T of the current node preLatest Advance t init , you can get the warm-up time T of the current node prewarmstart By preheating the current node at this time point, the function will be preheated when the request enters the current node. At the same time, the preheating time point cannot be earlier than 0.

[0070] (4) Repeat step (3) until the queue is empty.

[0071] 4. Serverless Container Scheduler

[0072] The container scheduling module preheats each function in advance based on the preheating time point calculated by the container preheating time point calculation module. When a request comes in, the container scheduling module is responsible for calling the corresponding function according to the actual situation of the request, and comparing the actual workflow currently being executed with the previously predicted workflow in real time. Once a deviation is found between the actual workflow and the predicted workflow, the subsequent preheating of the current predicted workflow is terminated in time, and the branch prediction and preheating time point calculation are re-performed using the most recent historical access records.

[0073] This module is also responsible for recording function runtime metrics and the global execution history of the workflow, as well as Figure 3 The state machine adds local execution history to the PHT in the branch prediction module. This module can connect to external Serverless platforms such as AWS, Azure, OpenWhisk, etc., and schedule the Serverless containers in the platform according to the above strategy.

[0074] The method of the present invention has the following advantages:

[0075] (1) Adopting the idea of ​​an adaptive two-level predictor, the global access history and local access history of the Serverless workflow are combined to predict the selection of subsequent branches in the workflow;

[0076] (2) Using the exponential moving average method, the runtime indicators of each function in the workflow are calculated;

[0077] (3) Using a preheating time prediction algorithm based on breadth-first traversal, the preheating time of each function in the workflow is calculated, laying the foundation for subsequent preheating;

[0078] (4) The container scheduling module is introduced. When scheduling the corresponding container according to the actual request, it is responsible for recording the necessary historical data and providing data for the normal operation of other modules. At the same time, it supports docking with multiple external platforms, making the scope of application wider.

[0079] Example

[0080] The open source Serverless platform OpenWhisk does not make specific optimizations for Serverless cold starts. When users orchestrate complex workflows, OpenWhisk will spend a lot of time on the cold starts of each container, thus becoming a potential performance bottleneck.

[0081] After OpenWhisk is connected to the container scheduler in the method, the method of the present invention provides OpenWhisk with a workflow-based function preheating capability. Through the comprehensive use of multiple modules, the end-to-end execution delay of the workflow is successfully reduced in the test, thereby improving the user experience.

Claims

1. A container cold start optimization method based on serverless function workflow branch prediction, It is characterized in that The following steps are involved: Function runtime indicator calculation: Calculate the average running time and average initialization time of each function in the workflow, and use the average running time and average initialization time as the function runtime indicators; Branch prediction: predicts the functions that may be executed in the workflow and the calling relationships between functions through the workflow's historical access data and the access data of the current request; Container preheating time point calculation: based on the function runtime indicators and branch prediction results, calculate and predict the preheating time point of each function in the workflow; Container scheduling: preheat the function based on the preheating time point; at the same time, according to the actual situation of the request, call the corresponding function, and compare the actual workflow currently being executed with the predicted workflow in real time. When there is a deviation between the predicted workflow and the actual workflow, terminate the subsequent preheating of the current predicted workflow, and recalculate the branch prediction and container preheating time point.

2. According to claim 1, the container cold start optimization method based on serverless function workflow branch prediction, It is characterized in that The initialization time includes the image pulling time, the function running environment initialization time and the time of the initialization operation of the function itself; the function runtime index is calculated using the exponential moving average method.

3. According to claim 1, the container cold start optimization method based on serverless function workflow branch prediction, It is characterized in that The branch prediction is implemented based on an adaptive two-level predictor. The adaptive two-level predictor uses a two-bit local history counter to record each global history record mode of each branch to form a mode history record table PHT; the strong selection, weak selection, weak non-selection, and strong non-selection in the access mode are encoded as 11, 10, 01, and 00 respectively. When the high bit is 1, it is selected, and when the high bit is 0, it is not selected. Each time when it is selected or not selected, the local history counter will move one step in the direction of selection or non-selection, and record the global history record mode of the current branch; the direction of each branch is predicted by using the adaptive two-level predictor, which specifically includes the following steps: (1) Request to trigger a function; (2) Based on the history records of the currently accessed function, the adaptive two-level predictor traverses the lower-level functions that have a calling relationship with the current function, queries the PHT of each function to see whether the high bit of the counter corresponding to the access mode of the current function is 1. If the high bit is 1, it means that the function may be accessed and the calling relationship between functions is recorded; (3) Add the functions that may be accessed to the global function history and repeat the operation in (2) until the entire workflow is traversed.

4. According to claim 1, the container cold start optimization method based on serverless function workflow branch prediction, It is characterized in that The container preheating time point calculation specifically includes the following steps: (1) Based on the predicted workflow, record the predecessor nodes preNodes and successor nodes succNodes of each node; traverse the nodes at each level in sequence until the traversal ends the workflow, and record the exit node of the workflow; (2) Each node in the workflow is queued in order to form a queue, and the initial position of the queue stores the entry node of the workflow; (3) Get the head node of the queue and dequeue it; traverse the preNodes of the head and calculate the completion time node of each predecessor node i of the head. The calculation formula is as follows: in, Represents the time point when node i starts executing, and Represents the time required for node i to initialize and run; The current sequence node After all calculations are completed, the latest end time T among the previous nodes is calculated. preLatest : T preLatest =max(T preFinish ) According to T preLatest Then further calculate the warm-up time T that the current node should start prewarmStart : T reuarmStart =max(0,T preLatest -t init ) Among them, t init is the initialization time of the current node, based on the scheduled start execution time point T of the current node preLatest Advance t init , which is the warm-up time T of the current node prewarmStart ; (4) Repeat step (3) until the queue is empty.

5. A container cold start optimization system based on serverless function workflow branch prediction, It is characterized in that include The function runtime indicator calculation module is used to calculate the average running time and average initialization time of each function in the workflow, and use the average running time and average initialization time as the function runtime indicator; The branch prediction module is used to predict the functions that may be executed in the workflow and the calling relationship between functions through the workflow history access data and the current request access data; A container preheating time point calculation module, used to calculate the preheating time point of each function in the prediction workflow based on the function runtime indicator and the prediction result of the branch prediction module; The container scheduling module is used to preheat the function based on the preheating time point; at the same time, according to the actual situation of the request, the corresponding function is called, and the actual workflow currently being executed and the predicted workflow are compared in real time. When there is a deviation between the predicted workflow and the actual workflow, the subsequent preheating of the current predicted workflow is terminated, and the branch prediction module and the container preheating time point calculation module are controlled to re-predict the branch and recalculate the container preheating time point.