Multifunctional serverless function cold start delay optimization method and system

By optimizing the function cutting and code of multi -function -free functions, the problem of cold starting delay in the multi -functional function in the server -free computing platform is solved, and a faster loading and initialization process is achieved.

CN118227137BActive Publication Date: 2025-01-28UNIV OF SCI & TECH OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410329650.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-21
Publication Date
2025-01-28
Estimated Expiration
2044-03-21

AI Technical Summary

Technical Problem

The existing serverless computing platform has significant delay problems during the cold start of multi-function serverless functions, resulting in increased response time.

Method used

By analyzing the application code of multi -function -free server functions, build an abstract syntax tree and function calling relationship diagram, search for the dependent code collection of each function, and cut the multi -function -free function into multiple single function without server functions. This function contains only the necessary code and module package to reduce the volume of the function and accelerate the loading and initialization process.

Benefits of technology

The volume and loading time of the server -free function is reduced, and the initialization logic simplifies the logic of initialization, thereby significantly reduced the cold startup delay, and creates the possibility for the application of the serverless computing technology in more scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118227137B_ABST
    Figure CN118227137B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for optimizing the cold start delay of a multifunctional serverless function, which divides a multifunctional serverless function into multiple single-function serverless functions and removes irrelevant codes that are not in a dependent code set, so that each single-function serverless function contains all dependent codes of the corresponding function, thereby ensuring that the function can be executed normally while reducing the volume of the application code and reducing the loading and initialization delay of the serverless function; and, analyzing the module packages that the single-function serverless function depends on, retaining the dependent module packages, and removing useless module packages, thereby further reducing the volume of the serverless function; the module packages are external code packages introduced by the application code, and these external code packages are also part of the serverless function, which increases the volume of the serverless function; the above two aspects jointly reduce the cold start delay of the serverless function, creating possibilities for the application of serverless computing technology in more scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer software technology, and in particular to a multifunctional serverless function cold start delay optimization method and system. Background Art

[0002] Serverless computing is an emerging computing paradigm for cloud applications. Serverless computing helps software developers focus on application development and deployment without having to manage the underlying infrastructure. In principle, serverless computing provides the ability to automatically scale resources up or down based on actual request loads, while its pay-per-use model provides the possibility of reducing costs and increasing efficiency. The mainstream implementation of serverless computing is Function-as-a-Service (FaaS), in which the basic deployment unit of an application is a serverless computing function, or serverless function for short. Many existing platforms use the Function-as-a-Service model, such as AWS Lambda and AzureFunctions in the commercial field, and Apache OpenWhisk, OpenFaaS, and KNIX MicroFunctions in the open source field.

[0003] Due to the advantages of serverless computing, more and more applications are beginning to adopt the serverless computing architecture. In addition to directly designing and constructing new applications based on the serverless computing paradigm, many applications that were not originally developed based on the serverless architecture can also be adjusted and migrated to the serverless architecture. This migration of existing applications only requires partial changes to the application code, which not only avoids the high cost of complete reconstruction, but also brings the automatic elastic expansion capability of serverless computing, eliminating the burden of managing the underlying infrastructure. However, while serverless computing brings automatic elastic expansion capabilities, it also introduces the cold-start problem. According to the on-demand resource use strategy of serverless computing, function resources will be released when they are idle. Therefore, when calling a function that is currently in an idle state, the serverless computing platform needs to perform the following steps: 1. Initialize the execution instance; 2. Load the function code; 3. Execute the function initialization logic; 4. Execute the event processing logic of the function. The cold start problem is that when restarting an idle function, three additional steps are introduced before the event processing logic is executed, which significantly increases the total response delay.

[0004] Existing non-serverless computing applications often use a monolithic architecture or a microservice architecture. The former is designed to package all components and functions in a unified code base, and the corresponding serverless computing functions after migration are large in size and have a long cold start initialization time. Although the latter considers functional splitting, in practice, many microservice applications still combine a series of logically related functions into one service, which also leads to a large single serverless function after migration and faces serious cold start problems. However, existing applications are usually not optimized for the cold start problem, so it is necessary to conduct in-depth research to solve the significant cold start delay problem of multi-functional serverless functions.

[0005] In view of this, the present invention is proposed. Summary of the invention

[0006] The purpose of the present invention is to provide a method and system for optimizing the cold start delay of a multifunctional serverless function. On the premise that the existing functions of the application can be completed normally, a single multifunctional serverless function is divided into multiple single-function serverless functions, each of which only contains the code and module packages necessary to execute a corresponding function, so as to reduce the size of the serverless function, speed up the loading and initialization speed of the serverless function, and reduce the cold start delay.

[0007] The objective of the present invention is achieved through the following technical solutions:

[0008] A multifunctional serverless function cold start latency optimization method, comprising:

[0009] For a multi-functional serverless function, analyze its application code and build an abstract syntax tree and function call relationship graph;

[0010] Search for the dependent code set of each function on the function call relationship graph;

[0011] Preliminarily split the multifunctional serverless function into multiple single-functional serverless functions, and remove irrelevant codes of the single-functional serverless functions corresponding to the preliminary split according to the dependent code set of the corresponding function, so as to obtain multiple refined single-functional serverless functions;

[0012] For each refined single-function serverless function, the abstract syntax tree of the application code is combined to preliminarily analyze the dependent module package set, parse the module package, obtain the dependent module package list, and thus analyze the complete dependent module package set of each refined single-function serverless function, remove the module packages that are not in the dependent module package set, and obtain the corresponding completely segmented single-function serverless function.

[0013] A multifunctional serverless function cold start latency optimization system, including:

[0014] Application code analyzer, used to analyze the application code of a multi-functional serverless function and build an abstract syntax tree and function call relationship graph;

[0015] Dependency code analyzer, used to search for the dependency code set of each function on the function call relationship graph;

[0016] The module package information parser is used to parse the module package information file of the module package specified by the dependent module package analyzer to obtain the dependent module package list;

[0017] The dependency module package analyzer is used to analyze the dependency module package set of each finely segmented single-function serverless function in combination with the abstract syntax tree of the application code, and analyze all the module packages that the finely segmented single-function serverless function depends on with the help of the dependency module package list obtained by parsing the module package information parser;

[0018] The executor is modified to read the analysis results of the dependency code analyzer and the dependency module package analyzer to complete the cold start delay optimization of the multi-functional serverless function, including: preliminarily dividing the multi-functional serverless function into multiple single-function serverless functions; for each single-function serverless function, removing irrelevant code of the single-function serverless function corresponding to the preliminary segmentation in combination with the dependency code set of the corresponding function, to obtain multiple refined segmentation single-function serverless functions; and according to the dependency module package set of each refined segmentation single-function serverless function, removing module packages that are not in the dependency module package set, to obtain the corresponding completely segmented single-function serverless function.

[0019] A processing device, comprising: one or more processors; a memory for storing one or more programs;

[0020] When the one or more programs are executed by the one or more processors, the one or more processors implement the aforementioned method.

[0021] A readable storage medium stores a computer program, which implements the above method when the computer program is executed by a processor.

[0022] It can be seen from the technical solution provided by the present invention described above that the present invention uses a serverless function function segmentation method to disperse multiple different functions in a single serverless function into multiple single-function serverless functions. Since the present invention does not split the processing logic of a single function, the number of serverless function calls required to complete a certain function will not increase. In terms of application code and module package level, a multifunctional serverless function needs to include all application codes and module packages for all these functions, while a single-function serverless function only needs the necessary application code and module package related to a specific function. Therefore, the present invention reduces the size of the serverless function, thereby reducing the network transmission and hard disk read data volume loaded by the serverless function, speeding up the loading process of the serverless function, and the present invention also simplifies the serverless function initialization logic and speeds up the execution process of the serverless function initialization code. These two aspects together reduce the cold start delay of the serverless function and create possibilities for the application of serverless computing technology in more scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0024] Figure 1 A flowchart of a multifunctional serverless function cold start delay optimization method provided by an embodiment of the present invention;

[0025] Figure 2 A flowchart of constructing a function call relationship diagram provided by an embodiment of the present invention;

[0026] Figure 3 A schematic diagram of the function call relationship of the overleaf.docstore application for obtaining a document provided in an embodiment of the present invention;

[0027] Figure 4 A flowchart of parsing and analyzing dependent module packages provided by an embodiment of the present invention;

[0028] Figure 5 A schematic diagram of a multifunctional serverless function cold start delay optimization system provided by an embodiment of the present invention;

[0029] Figure 6 A schematic diagram of a processing device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0030] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of the present invention.

[0031] First, the terms that may be used in this article are explained as follows:

[0032] The terms "include", "comprises", "contains", "has" or other descriptions with similar semantics should be interpreted as non-exclusive inclusion. For example, including certain technical feature elements (such as raw materials, components, ingredients, carriers, dosage forms, materials, dimensions, parts, components, mechanisms, devices, steps, procedures, methods, reaction conditions, processing conditions, parameters, algorithms, signals, data, products or products, etc.) should be interpreted as including not only certain technical feature elements explicitly listed, but also other technical feature elements known in the art that are not explicitly listed.

[0033] The term "consisting of..." means excluding any technical feature elements not explicitly listed. If this term is used in a claim, it will make the claim closed, so that it does not contain technical feature elements other than the technical feature elements explicitly listed, except for the conventional impurities related to them. If this term only appears in a clause of a claim, it only limits the elements explicitly listed in the clause, and the elements recorded in other clauses are not excluded from the overall claim.

[0034] The term "function" should be interpreted as a function at the computer programming language level, which is different from a serverless function.

[0035] The following is a detailed description of a multifunctional serverless function cold start delay optimization method and system provided by the present invention. The contents not described in detail in the embodiments of the present invention belong to the prior art known to professional and technical personnel in the field. If no specific conditions are specified in the embodiments of the present invention, they shall be carried out in accordance with the conventional conditions in the field or the conditions recommended by the manufacturer.

[0036] Embodiment 1

[0037] An embodiment of the present invention provides a method for optimizing the cold start delay of a multifunctional serverless function, which mainly includes: for a multifunctional serverless function, analyzing its application code, constructing an abstract syntax tree and a function call relationship graph; searching for a dependent code set for each function on the function call relationship graph; preliminarily dividing the multifunctional serverless function into multiple single-function serverless functions, and removing irrelevant codes of the single-function serverless function corresponding to the preliminary division in combination with the dependent code set of the corresponding function, to obtain multiple refined single-function serverless functions; for each refined single-function serverless function, preliminarily analyzing a dependent module package set in combination with the abstract syntax tree of the corresponding application code, parsing the module package to obtain a dependent module package list, and thereby analyzing a complete dependent module package set of each refined single-function serverless function, removing module packages that are not in the dependent module package set, to obtain the corresponding completely divided single-function serverless function.

[0038] The above method provided by the embodiment of the present invention establishes a function call relationship graph to express the association between codes, and obtains the dependency code and module package required for each function through dependency code analysis and dependency module package analysis. On the premise of ensuring the normal execution of existing functions of the serverless application, a single multi-functional serverless function is divided into multiple single-function serverless functions, where each single-function serverless function only contains the application code and module package necessary for the function, so as to reduce the size of the serverless function, speed up the loading and initialization speed of the serverless function, and thereby improve the cold start response capability of the serverless function, helping cloud applications to meet service quality requirements.

[0039] In order to more clearly demonstrate the technical solution and technical effects provided by the present invention, the method provided by the embodiment of the present invention is described in detail with reference to specific embodiments below.

[0040] like Figure 1 As shown, it is a flowchart of a multifunctional serverless function cold start delay optimization method based on function segmentation provided in an embodiment of the present invention. Figure 1 The rectangular circle in the middle represents a serverless function, the letter "E" marked in the hexagon represents an entry point node (Entry Point Node), the letter "F" marked in the circle represents a function node (Function Node), and the missing rectangle marked with the letter "M" represents a module package (Module). Different filled graphics are used to mark different entry point nodes and their dependent code sets. Solid arrows represent function call relationships, and dotted arrows represent steps. Function nodes and module packages connected by dotted lines indicate that a reference to the module package is found in the function node.

[0041] Step 1: For a multifunctional serverless function code, create a function call relationship graph.

[0042] In an embodiment of the present invention, the function call relationship graph includes directed edges between nodes. The directed edges represent the call relationship between nodes, from the caller node to the callee node. Node types include: entry point nodes and function nodes; the entry point node represents a code snippet, the serverless function receives external events from the snippet and starts to execute the event processing logic, and each entry point node corresponds to a function; the function refers to a function in the sense of a programming language.

[0043] In the embodiment of the present invention, the entry point nodes are numbered 1, 2, 3, ..., N, where N is the total number of entry point nodes. Special comments are added before and after the entry point code snippet corresponding to each entry point node to mark the starting position, ending position and entry point node number of the entry point code snippet.

[0044] In the embodiment of the present invention, the function refers to: the process of receiving, processing and responding to a class of external events. These external events are handed over to the same code fragment to start their processing flow due to some similar attributes. Common examples of similar attributes include: Hypertext Transfer Protocol (HTTP) requests with the same method (Method) and Uniform Resource Locators (Uniform Resource Locators) that meet the same matching rules are routed to the same processing function, message queue messages come from the same queue, and Remote Procedure Call (RPC) calls the same remote procedure.

[0045] Figure 2 A flowchart of constructing an abstract syntax tree and a function call relationship graph in an embodiment of the present invention is provided. The implementation method of establishing the function call relationship graph includes:

[0046] Step A1, create two new empty queues, one as the queue to be analyzed and the other as the queue to be analyzed; according to the specific abstract syntax tree structure of each type of event receiving code, find the code snippet corresponding to the entry point in the abstract syntax tree of the application code, mark it as the entry point node and add it to the queue to be analyzed, that is, Figure 2 Operation ① in .

[0047] Exemplarily, the types of event receiving codes include: Hypertext Transfer Protocol (HTTP) request receiver, message queue consumer, Remote Procedure Call (RPC) service registrar.

[0048] The most commonly used HTTP request receiver in the node.js language is the express receiver. The identification conditions of the express request receiver are given below as an example. Condition 1: A node R in the abstract syntax tree is of a call expression type; Condition 2: The caller domain of the R node is a member expression node, denoted by C; Condition 3: The C node consists of an object domain and an attribute domain, where the object domain is an identifier node, denoted by O, and the attribute domain type is also an identifier node, and the name of the attribute domain identifier node is one of the methods specified in the hypertext transfer protocol; Condition 4: The actual parameter domain of the R node is an array containing several nodes, the first node type of the actual parameter domain array is a string, and all subsequent node types are identifiers, function expressions, or types with effects similar to function expressions. All nodes of the actual parameter domain array that are of the type of identifiers are collectively denoted as array H; Condition 5: Check the definitions of the identifier O and the identifier nodes in the array H, requiring that the definition of the identifier O comes from the express module package, and the definition of the identifier in the array H comes from nodes of the type of function definition or other types with equivalent effects. Check the above conditions 1 to 5 one by one. If one of them is not met, skip the subsequent checks. The code snippet corresponding to the node R that meets all the conditions is an express request receiver entry point. Only need to modify the recognition logic, similar methods can also identify other hypertext transfer protocol receivers and other types of event receiving codes, and this change in recognition logic has no effect on the method of constructing the function call relationship graph.

[0049] Step A2: Take out the head element of the queue to be analyzed as the current analysis code and add it to the analyzed queue. Figure 2 Operation ② in . Adding the code to the analyzed queue ensures that the code will not be analyzed again in subsequent loop processing.

[0050] Step A3, construct the abstract syntax tree corresponding to the current analysis code, and analyze each identifier that appears in it, that is, Figure 2 Operation ③: Search for the definition statement of the identifier. If the corresponding statement node type is a function definition or other types with the same effect, the identifier corresponds to a function. If an identifier corresponds to a function, go to step A4; otherwise, go to step A5.

[0051] Step A4: For each identified function, add a corresponding function node and a directed edge from the analysis code to the corresponding function in the function call relationship graph. The function node records the definition location of the function, i.e. Figure 2 Operation ④ in ; and if the function is neither in the queue to be analyzed nor in the queue to be analyzed, then add it to the queue to be analyzed, that is Figure 2 Operation ⑤.

[0052] Step A5: if all identifiers have been checked, go to step A6; otherwise, go to step A3 to continue checking;

[0053] Step A6: if the queue to be analyzed is empty, it indicates that all analyses have been completed, and the process goes to step A7; otherwise, the process goes to step A2 to continue the analysis process;

[0054] Step A7, save the function call relationship graph at this time as the function call relationship graph corresponding to the multifunctional serverless function, that is, Figure 2 Operation ⑥.

[0055] In the preliminary stage, the function call relationship graph in step A4 is an empty graph. By continuously executing the above steps, nodes and edges are gradually added, and finally a constructed function call relationship graph is obtained.

[0056] Step 2: Search for the dependent code set of each function on the function call relationship graph.

[0057] In the embodiment of the invention, each node is used as a starting point to execute a depth-first search algorithm, and the function node set accessed by the depth-first search is used as the dependent code set of the corresponding entry point node. The dependent code set is a set of function definition codes, which are executed in the function processing process.

[0058] As mentioned before, each entry point node on the function call relationship graph corresponds to a function. Starting from each entry point node i, the depth-first search algorithm is executed. The set of function nodes accessed by the depth-first search is used as the dependent code set of the entry point node i. The dependent code set of each entry point node i is recorded. The intersection of the dependent code sets of the searched entry point nodes i and j is not necessarily empty.

[0059] In an embodiment of the present invention, the result of the dependent code set of entry point node i is stored as a JSON (JavaScript Object Notation) object, and the result is divided and saved according to the code file name to which it belongs. That is to say, the JSON object of the dependent code set of entry point node i is composed of several file name objects. The name of each file name object is the file name string, and the value is an array. Each object in the array is composed of two values, the start line and the end line, indicating that all the codes from the start line to the end line (including both ends) of the file belong to the dependent code set. If two objects in the same array represent adjacent code lines, they are merged into one object, the start line is set to the smaller of the two, and the end line is set to the larger of the two. End line.

[0060] Step 3: Initially split the multi-functional serverless function into multiple single-functional serverless functions.

[0061] In an embodiment of the present invention, an application code library is copied N times and numbered 1, 2, 3, ..., N as N initial single-function serverless functions, where N is the number of entry point nodes, and each entry point node corresponds to a function; each single-function serverless function is traversed, and for the initial single-function serverless function numbered i, the entry point code snippets corresponding to the remaining N-1 entry point nodes not numbered i are deleted, i = 1, 2, 3, ..., N, and the N initial single-function serverless functions are processed separately to obtain N single-function serverless functions that only contain entry point nodes with corresponding numbers, which are called the N single-function serverless functions that are initially divided.

[0062] It should be noted that after this step is completed, these single-function serverless functions may still contain codes corresponding to other function nodes.

[0063] Step 4: Remove irrelevant code based on the dependent code set.

[0064] In an embodiment of the present invention, for each of the N single-function serverless functions that are initially segmented, all function nodes in the function call relationship graph are traversed, and the start and end line positions of the function definition are obtained according to the function definition position information recorded in the function node, and the corresponding file name object in the dependency code set of the corresponding function is searched. If the start and end line positions of the function definition are included in the start line and end line of an element in the array of the file name object, then the function is considered to belong to the dependency code set of the corresponding function. Conversely, if all elements in the array of the file name object do not have a start line and an end line that include the start and end lines of the function definition, then the function is considered not to belong to the dependency code set of the corresponding function and will be removed as irrelevant code.

[0065] Through the above method, N finely divided single-function serverless functions can be obtained.

[0066] In the above steps, the embodiment of the present invention completes the functional segmentation of the application code itself, divides it into N single-function serverless functions, and removes irrelevant code that is not in the dependent code set, so that each single-function serverless function contains all dependent codes of the corresponding function, ensuring that the function can be executed normally while reducing the volume of the application code and reducing the loading and initialization delay of the serverless function. The single-function serverless function obtained in the above steps is called a refined and segmented single-function serverless function.

[0067] Figure 3The dependent functions obtained when processing the "Get Document" function in the overleaf.docstore application in an embodiment of the present invention and their call relationship diagram are given. The solid rectangular box in the figure represents the function, the dotted rectangular box represents the code file to which the function belongs, the arrow represents the call relationship, and the symbol "☆" represents the function directly called by the entry point. The function name consisting of two strings connected by the symbol "." in the figure should be understood as an object method (Object Method), the first string represents the object name, and the second string represents the method name. Figure 3 A total of 13 dependent functions required to complete the "Get Document" function were found. In the serverless function of the "Get Document" function, these dependent functions and entry point code snippets were retained in the application code, and other irrelevant functions were deleted.

[0068] Taking into account that in addition to the application code, the module package also affects the volume of the entire serverless function, the embodiment of the present invention also needs to further reduce the volume occupied by the module package. The module package is an external code package introduced by the application code. These external code packages are also part of the serverless function, which increases the volume of the serverless function.

[0069] Step 5: Analyze the dependent module packages of all N finely divided single-function serverless functions, and delete the module packages that are no longer in the dependent module package set in each serverless function.

[0070] In this step, for each refined and segmented single-function serverless function, first, the dependent module package set is preliminarily analyzed according to the abstract syntax tree of the corresponding application code. The dependent module package set obtained by the preliminary analysis only contains module packages directly dependent on the application code. These directly dependent module packages are part of all dependent module packages of the single-function serverless function. After that, the indirectly dependent module packages need to be analyzed. If a module package belongs to the dependent module package set, other module packages that the module package depends on are considered to be indirectly dependent module packages. The indirectly dependent module packages are also added to the dependent module package set for further analysis. The indirect dependent module packages are obtained by parsing the package information file of a module package in the dependent module package set to obtain the dependent module package list of the module package itself. Finally, all directly or indirectly dependent module packages obtained by combining the above-mentioned various methods of analysis constitute the complete dependent module package set of the single-function serverless function.

[0071] Figure 4 The flowchart of parsing and analyzing the dependent module package in an embodiment of the present invention is shown, and the main steps include:

[0072] Step B1, initialize the dependent package set to be empty, the completion queue to be empty, and the waiting queue to be empty; corresponding Figure 4 Middle operation⑴.

[0073] Step B2: for the single-function serverless function currently segmented, read the abstract syntax tree corresponding to the application code, search and parse the require function call expression (the function of the node.js language introducing external code) in the abstract syntax tree, locate the location of the introduced code, and Figure 4 Operation (2); if the introduced code belongs to a module package, go to step B3, otherwise go to step B7; wherein the abstract syntax tree needs to be regenerated because the preliminary segmentation and refined segmentation cause changes in the application code.

[0074] Step B3: Add the module package to which the imported code belongs to the waiting queue, corresponding to Figure 4 Operation ⑶.

[0075] Step B4, take out the head element from the waiting queue, set it as the current analysis module package, add it to the completion queue, and add it to the dependent module package set, corresponding to Figure 4 Operation⑷.

[0076] Step B5, parse the package information file of the current analysis module package (the node.js language module package has a file named package.json, which records the dependent module package information), obtain the dependent module package list, and add the module packages in the list that are neither in the waiting queue nor in the completion queue to the waiting queue, corresponding to Figure 4 Operation ⑸.

[0077] Step B6, if the waiting queue is empty, go to step B7, otherwise go to step B4 to continue processing the waiting queue;

[0078] Step B7: If the require function calls of all application codes have been parsed, go to step B8; otherwise, go to step B2;

[0079] Step B8: Save the dependency module package set at this time as the dependency module package set of the currently refined and segmented single-function serverless function, corresponding to Figure 4 Operation ⑹.

[0080] The above steps B1 to B8 describe the analysis process of the dependent module package set. After completing the analysis of the dependent module package set, it is necessary to remove useless module packages. The specific method is to traverse each module package of the current refined single-function serverless function to check whether the module package belongs to the dependent module package set. If not, delete the module package.

[0081] In the embodiment of the present invention, by analyzing the module packages it depends on, retaining all the module packages that it directly or indirectly depends on, and removing useless module packages, the process of loading the code of the serverless function is accelerated. After the application code is functionally segmented, the irrelevant code in each single-function serverless function is deleted. The deleted code may use module packages that are not used by the remaining code. Such module packages are actually not used in the remaining code, so they can be deleted to reduce the total volume of the module packages.

[0082] After completing the above steps, the embodiment of the present invention analyzes the dependent module package set in each single-function serverless function. At this time, the remaining module packages that are not in the dependent module package set are deleted, thereby completing the removal of useless module packages and finally completing the cold start delay optimization of the multi-functional serverless function.

[0083] The present invention uses a serverless function functional segmentation method to disperse multiple different functions in a single serverless function into multiple single-function serverless functions. Since the present invention does not split the processing logic of a single function, the number of serverless function calls required to complete a certain function will not increase. In terms of application code and module package level, a multifunctional serverless function needs to include all application codes and module packages for all these functions, while a single-function serverless function only needs the necessary application code and module package related to a specific function. Therefore, the present invention reduces the size of the serverless function, thereby reducing the network transmission and hard disk read data volume loaded by the serverless function, speeding up the loading process of the serverless function, and the present invention also simplifies the serverless function initialization logic and speeds up the execution process of the serverless function initialization code. These two aspects together reduce the cold start delay of the serverless function and create possibilities for the application of serverless computing technology in more scenarios.

[0084] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiments can be implemented by software, or by means of software plus necessary general hardware platforms. Based on such understanding, the technical solutions of the above embodiments can be embodied in the form of software products, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0085] Embodiment 2

[0086] The present invention also provides a multifunctional serverless function cold start delay optimization system, which is mainly used to implement the method provided in the above embodiment, such as Figure 5 As shown, the system mainly includes:

[0087] Application code analyzer, used to analyze the application code of a multi-functional serverless function and build an abstract syntax tree and function call relationship graph;

[0088] Dependency code analyzer, used to search for the dependency code set of each function on the function call relationship graph;

[0089] The module package information parser is used to parse the module package information file for the module package specified by the dependent module package analyzer to obtain the list of dependent module packages of the module package;

[0090] The dependency module package analyzer is used to preliminarily analyze the dependency module package set for each finely segmented single-function serverless function in combination with the abstract syntax tree of the application code, and further analyze all the module packages that the finely segmented single-function serverless function depends on with the help of the dependency module package list obtained by parsing the module package information parser;

[0091] The executor is modified to read the analysis results of the dependency code analyzer and the dependency module package analyzer to complete the cold start delay optimization of the multi-functional serverless function, including: preliminarily dividing the multi-functional serverless function into multiple single-function serverless functions; for each single-function serverless function, removing irrelevant code of the single-function serverless function corresponding to the preliminary segmentation in combination with the dependency code set of the corresponding function, to obtain multiple refined segmentation single-function serverless functions; and according to the dependency module package set of each refined segmentation single-function serverless function, removing module packages that are not in the dependency module package set, to obtain the corresponding completely segmented single-function serverless function.

[0092] Figure 5 The relevant steps for analysis and modification are also presented. Figure 5 The arrow in the middle indicates a read or modify operation, which is directed from the implementer of the read or modify operation to the implementation object.

[0093] In the system, those that directly access the application code or module package of the serverless function include: an application code analyzer, which performs syntax analysis on the application code file, generates an abstract syntax tree, and finally generates a function call relationship graph, as well as searches for the definition location of an identifier in the application code; a modification executor, which reads the analysis results of the dependency code analyzer and the dependency module package analyzer, determines the parts that need to be deleted, such as other entry point nodes, function nodes outside the dependency function set, and module packages outside the dependency module package set, finds the corresponding application code snippets and module packages, and deletes them; and a module package information parser, which parses the package information file carried by the module package specified by the dependency module package analyzer to obtain a list of dependency module packages.

[0094] The parts that do not directly access the serverless function itself include: the dependency code analyzer, which identifies the entry point node, builds the function call relationship graph, and finds the dependency code. The workflow includes calling the abstract syntax tree generated by the application code analyzer and locating the identifier definition location; the dependency module package analyzer, which combines the abstract syntax tree of the application code to preliminarily analyze the dependency module package set, and uses the dependency module package list obtained by the module package information parser to build a complete dependency module package set.

[0095] In the above scheme, different functions are distinguished by different entry points; a function call relationship graph is established by analyzing the application code; the dependency code of the function corresponding to each entry point node is obtained by performing a search on the function call relationship graph; based on the dependency code information, a single-function serverless function is constructed from the original multi-function serverless function, and unnecessary application code is removed; based on the analysis, a set of dependent module packages is obtained, and unnecessary module packages in the single-function serverless function are removed; ultimately, the purpose of reducing the size of the serverless function is achieved.

[0096] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example for illustration. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the system can be divided into different functional modules to complete all or part of the above-mentioned functions.

[0097] Embodiment 3

[0098] The present invention also provides a processing device, such as Figure 6 As shown, it mainly includes: one or more processors; a memory for storing one or more programs; wherein, when the one or more programs are executed by the one or more processors, the one or more processors implement the methods provided in the aforementioned embodiments.

[0099] Furthermore, the processing device also includes at least one input device and at least one output device; in the processing device, the processor, memory, input device, and output device are connected via a bus.

[0100] In the embodiment of the present invention, the specific types of the memory, input device and output device are not limited; for example:

[0101] The input device may be a touch screen, an image acquisition device, a physical button or a mouse, etc.;

[0102] The output device may be a display terminal;

[0103] The memory may be a random access memory (RAM) or a non-volatile memory, such as a disk memory.

[0104] Embodiment 4

[0105] The present invention also provides a readable storage medium storing a computer program, which implements the method provided in the above embodiment when the computer program is executed by a processor.

[0106] In the embodiment of the present invention, the readable storage medium is a computer-readable storage medium and can be set in the aforementioned processing device, for example, as a memory in the processing device. In addition, the readable storage medium can also be a U disk, a mobile hard disk, a read-only memory (ROM), a disk or an optical disk, etc., which can store program codes.

[0107] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A multifunctional serverless function cold start delay optimization method, characterized in that: include: For a multi-functional serverless function, analyze its application code and build an abstract syntax tree and function call relationship graph; Search for the dependent code set of each function on the function call relationship graph; Preliminarily split the multifunctional serverless function into multiple single-functional serverless functions, and remove irrelevant codes of the single-functional serverless functions corresponding to the preliminary split according to the dependent code set of the corresponding function, so as to obtain multiple refined single-functional serverless functions; For each finely segmented single-function serverless function, a preliminarily dependent module package set is analyzed in combination with the abstract syntax tree of the application code, the module package is parsed to obtain a list of dependent module packages, and thereby a complete dependent module package set of each finely segmented single-function serverless function is analyzed, and module packages that are not in the dependent module package set are removed to obtain the corresponding fully segmented single-function serverless function; Among them, the method of removing irrelevant codes of the single-function serverless function corresponding to the preliminary segmentation in combination with the dependent code set of the corresponding function includes: for each of the N single-function serverless functions that are initially segmented, traversing all function nodes in the function call relationship graph, obtaining the start and end line positions of the function definition according to the function definition position information recorded in the function node, and searching for the corresponding file name object in the dependent code set of the corresponding function; if the start and end line positions of the function definition are contained by the start and end lines of an element in the array of the file name object, then it is considered that the function belongs to the dependent code set of the corresponding function; conversely, if all elements in the array of the file name object do not have the start and end lines containing the start and end lines of the function definition, then it is considered that the function does not belong to the dependent code set of the corresponding function and will be removed as irrelevant code.

2. According to claim 1, a multifunctional serverless function cold start delay optimization method is characterized in that: The function call relationship graph includes directed edges between nodes, wherein the directed edges represent the call relationship between the nodes; Node types include: entry point nodes and function nodes; the entry point node represents a code snippet, the serverless function receives external events from the snippet and starts to execute the event processing logic. Each entry point node corresponds to a function; the function refers to the function in the sense of the programming language.

3. A multifunctional serverless function cold start delay optimization method according to claim 1 or 2, characterized in that: The steps of analyzing the application code of a multifunctional serverless function and constructing an abstract syntax tree and a function call relationship graph include: Step A1, create two new empty queues, one of which is used as the queue to be analyzed and the other as the queue that has been analyzed; according to the specific abstract syntax tree structure of each type of event receiving code, find the code fragment corresponding to the entry point in the abstract syntax tree of the application code, mark it as the entry point node and add it to the queue to be analyzed; Step A2, taking out the head element of the queue to be analyzed, taking it as the current analysis code, and adding it to the analyzed queue; Step A3, construct an abstract syntax tree corresponding to the current analysis code, analyze each identifier that appears therein, and search for the definition statement of the identifier. If the corresponding statement node type is a function definition or other types with equivalent effects, the identifier corresponds to a function; if an identifier corresponds to a function, proceed to step A4, otherwise proceed to step A5; Step A4: for each identified function, a corresponding function node and a directed edge from the analysis code to the corresponding function are added to the function call relationship graph. The function node records the definition location of the function. If the function is neither in the queue to be analyzed nor in the queue to be analyzed, it is added to the queue to be analyzed. Step A5: if all identifiers have been checked, go to step A6; otherwise, go to step A3 to continue checking; Step A6: if the queue to be analyzed is empty, it indicates that all analyses have been completed, and the process goes to step A7; otherwise, the process goes to step A2 to continue the analysis process; Step A7, saving the function call relationship graph at this time as the function call relationship graph corresponding to the multi-functional serverless function.

4. A multifunctional serverless function cold start delay optimization method according to claim 1, 2 or 3, characterized in that: The step of searching for the dependent code set of each function on the function call relationship graph includes: Each entry point node on the function call relationship diagram corresponds to a function; each node is used as a starting point to execute a depth-first search algorithm, and the set of function nodes accessed by the depth-first search is used as the dependent code set of the corresponding entry point node.

5. A multifunctional serverless function cold start delay optimization method according to claim 1, characterized in that: The preliminary division of the multifunctional serverless function into a plurality of single-functional serverless functions includes: Duplicate the application code base N times, numbered 1, 2, 3, ..., N, as N initial single-function serverless functions, where N is the number of entry point nodes, and each entry point node corresponds to one function; For the initial single-function serverless function numbered i, delete the entry point code snippets corresponding to the remaining N-1 entry point nodes not numbered i, i = 1, 2, 3, ..., N, and process the N initial single-function serverless functions separately to obtain N single-function serverless functions that only contain entry point nodes with corresponding numbers, which are called the initially divided N single-function serverless functions.

6. A multifunctional serverless function cold start delay optimization method according to claim 1, characterized in that: The steps of preliminarily analyzing a set of dependent module packages in combination with an abstract syntax tree of the application code for each finely segmented single-function serverless function, parsing the module packages to obtain a list of dependent module packages, and thereby analyzing a complete set of dependent module packages for each finely segmented single-function serverless function include: Step B1, initialize the dependent package set to be empty, the completion queue to be empty, and the waiting queue to be empty; Step B2: for the single-function serverless function currently segmented, read the abstract syntax tree corresponding to the application code, search and parse the require function call expression in the abstract syntax tree, and locate the position of the introduced code; if the introduced code belongs to the module package, go to step B3, otherwise go to step B7; Step B3, adding the module package to which the imported code belongs to a waiting queue; Step B4, taking out the head element from the waiting queue, setting it as the current analysis module package, adding it to the completion queue, and adding it to the dependent module package set; Step B5, parsing the package information file of the current analysis module package, obtaining a list of dependent module packages, and adding module packages in the list that are neither in the waiting queue nor in the completion queue to the waiting queue; Step B6, if the waiting queue is empty, go to step B7, otherwise go to step B4 to continue processing the waiting queue; Step B7: If the require function calls of all application codes have been parsed, go to step B8; otherwise, go to step B2; Step B8, save the dependency module package set at this time as the dependency module package set of the current refined and segmented single-function serverless function.

7. A multifunctional serverless function cold start delay optimization system, characterized in that: include: Application code analyzer, used to analyze the application code of a multi-functional serverless function and build an abstract syntax tree and function call relationship graph; Dependency code analyzer, used to search for the dependency code set of each function on the function call relationship graph; The module package information parser is used to parse the module package information file of the module package specified by the dependent module package analyzer to obtain the dependent module package list; The dependency module package analyzer is used to analyze the dependency module package set of each finely segmented single-function serverless function in combination with the abstract syntax tree of the application code, and analyze all the module packages that the finely segmented single-function serverless function depends on with the help of the dependency module package list obtained by parsing the module package information parser; Modify the executor to read the analysis results of the dependency code analyzer and the dependency module package analyzer to complete the cold start delay optimization of the multifunctional serverless function, including: preliminarily splitting the multifunctional serverless function into multiple single-function serverless functions; for each single-function serverless function, remove the irrelevant code of the single-function serverless function corresponding to the preliminarily split according to the dependency code set of the corresponding function, and obtain multiple refined split single-function serverless functions; and according to the dependency module package set of each refined split single-function serverless function, remove the module package that is not in the dependency module package set, and obtain the corresponding fully split single-function serverless function; Among them, the method of removing irrelevant codes of the single-function serverless function corresponding to the preliminary segmentation in combination with the dependent code set of the corresponding function includes: for each of the N single-function serverless functions that are initially segmented, traversing all function nodes in the function call relationship graph, obtaining the start and end line positions of the function definition according to the function definition position information recorded in the function node, and searching for the corresponding file name object in the dependent code set of the corresponding function; if the start and end line positions of the function definition are contained by the start and end lines of an element in the array of the file name object, then it is considered that the function belongs to the dependent code set of the corresponding function; conversely, if all elements in the array of the file name object do not have the start and end lines containing the start and end lines of the function definition, then it is considered that the function does not belong to the dependent code set of the corresponding function and will be removed as irrelevant code.

8. A processing device, characterized in that: include: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.

9. A readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Portable predictable execution of serverless functions

    US20220357994A1