Predictive class loading and code caching-based Java Serverless function cold start optimization system and method

Through a system based on predictive class loading and code caching, the problem of long cold start time of Java Serverless function is solved, efficient class loading and code execution is achieved, responsiveness and resource utilization efficiency are significantly improved, and Java dynamics are maintained Features and security.

CN119201285AInactive Publication Date: 2024-12-27刘宇
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411387520.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-04
Publication Date
2024-12-27
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The Java Serverless function is cold-started in the Serverless environment for a long time. The existing technology warms up instances to increase resource costs, optimizes dependencies to limit functions or increase development complexity. The lightweight JVM sacrifices dynamic features and lacks a comprehensive optimization strategy, resulting in Inconsistent performance.

Method used

Adopt a system based on predictive class loading and code cache, including intelligent class analysis and prediction module, hierarchical class loading system, fine-grained code cache module, asynchronous preheating mechanism, state saving and recovery module and adaptive optimization module to achieve high Precision class load prediction, hierarchical loading, fine-grained cache and asynchronous preheating, combining state saving and rapid recovery, dynamically adjusting optimization strategies.

Benefits of technology

It significantly reduces the cold start time of Java Serverless functions, improves response speed and resource utilization efficiency, ensures optimal performance in different scenarios, while maintaining Java's dynamic characteristics and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure FT_2
    Figure FT_2
  • Figure FT_3
    Figure FT_3
Patent Text Reader

Abstract

The invention provides a Java Serverless function cold start optimization system and a Java Serverless function cold start optimization method based on predictive class loading and code caching. The system comprises an intelligent class analysis and prediction module, a hierarchical class loading system, a fine-grained code caching module, an asynchronous preheating mechanism, a state storage and recovery module and a self-adaptive optimization module. The system predicts a required class set through static analysis and dynamic tracking, optimizes a class loading process by utilizing a hierarchical loading strategy, improves code execution efficiency by adopting fine-grained cache, and reduces starting delay through asynchronous preheating and rapid state recovery. Meanwhile, the system continuously monitors performance indexes and dynamically adjusts strategies to achieve self-adaptive optimization. According to the method, the function cold start time is remarkably shortened, the function response speed and the resource utilization efficiency are improved, meanwhile, the dynamic characteristics and safety of Java are kept, and an efficient performance optimization solution is provided for Java application in the Serverless computing environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cloud computing technology, and in particular to a Java application performance optimization technology in a Serverless computing environment, and specifically to a Java Serverless function cold start optimization system and method based on predictive class loading and code caching. Background Art

[0002] As a widely used programming language, Java has important applications in the field of serverless computing. The serverless architecture allows developers to focus on code logic without having to manage the underlying infrastructure, greatly improving development efficiency and resource utilization. However, a major challenge facing Java applications in a serverless environment is the long cold start time, which directly affects the function's response speed and user experience. Therefore, optimizing the cold start performance of Java serverless functions is of great significance in the field of cloud computing technology.

[0003] At present, the main solutions used to improve the cold start performance of Java Serverless functions include preheating instances, optimizing dependencies, and using lightweight JVMs. Preheating instances reduces the probability of cold starts by maintaining a certain number of hot instances; optimizing dependencies reduces loading time by streamlining and optimizing project dependencies; and using lightweight JVMs such as GraalVM's Native Image technology can compile Java applications into local executable files, significantly reducing startup time. These methods have improved the cold start performance of Java Serverless functions to a certain extent.

[0004] However, these solutions still have some problems. Preheating instance technology will increase resource costs and cannot completely eliminate cold starts; optimizing dependencies may limit application functions or increase development complexity; and using lightweight JVM technology may sacrifice some dynamic features of Java, such as reflection and dynamic class loading. In addition, these methods are often static and cannot dynamically adjust optimization strategies according to actual operating conditions, resulting in inconsistent performance in different scenarios.

[0005] To solve the above problems, some studies have proposed optimization methods based on dynamic analysis and caching. For example, by analyzing the function call pattern to predict the class that needs to be loaded, or caching the compiled code to speed up subsequent execution. Although these methods have improved the cold start performance to a certain extent, there are still problems such as low prediction accuracy, coarse cache granularity, and inability to fully utilize the characteristics of the Serverless environment. At the same time, these methods often lack comprehensive optimization strategies, making it difficult to achieve collaborative optimization in multiple links such as class loading, code execution, and state recovery.

[0006] Therefore, there is an urgent need for a Java Serverless function cold start optimization system that can comprehensively consider the characteristics of the Java language and the Serverless environment, integrate multiple optimization technologies, and can adaptively adjust. This system should be able to significantly reduce the cold start time while maintaining the dynamic characteristics of Java, improve function response speed and resource utilization efficiency, and thus better meet the performance requirements in the Serverless computing environment. Summary of the invention

[0007] The purpose of the present invention is to solve the problems existing in the existing Java Serverless function cold start optimization technology, such as low prediction accuracy, coarse cache granularity, inability to fully utilize the characteristics of the Serverless environment, and lack of comprehensive optimization strategies. In addition, the present invention also aims to provide an optimization system that can significantly reduce the cold start time, improve function response speed and resource utilization efficiency while maintaining the dynamic characteristics of Java.

[0008] To achieve the above objectives, the present invention provides a Java Serverless function cold start optimization system based on predictive class loading and code caching, which is characterized by: including an intelligent class analysis and prediction module, a hierarchical class loading system, a fine-grained code cache module, an asynchronous preheating mechanism, a state preservation and recovery module, and an adaptive optimization module. In some embodiments, the present invention also provides a Java Serverless function cold start optimization method based on the system.

[0009] Specifically, the intelligent class analysis and prediction module is used to perform static analysis and dynamic tracking of function codes, and train machine learning models based on historical data to predict the most likely class sets required in different call scenarios. This module includes a static analysis unit, a dynamic tracking unit, and a machine learning unit, achieving high-precision class loading prediction.

[0010] Furthermore, the hierarchical class loading system includes core layer, function layer, library layer and dynamic layer, and loads classes at different levels according to the prediction results. The core layer contains the core classes required by the Java runtime, which are always preloaded; the function layer contains the classes defined by the function and direct dependencies, which are loaded first; the library layer contains the classes of commonly used third-party libraries, which are loaded on demand according to the prediction; the dynamic layer dynamically loads classes according to the actual call.

[0011] Preferably, the fine-grained code cache module is used to cache the compiled machine code of hotspot methods, the inline information of commonly used method calls, and the structure information of classes. The module includes a method-level cache unit, an inline cache unit, and a type information cache unit, realizing a more refined code cache strategy.

[0012] Optionally, the asynchronous preheating mechanism is used to start a background thread for class loading and just-in-time (JIT) preheating after the function instance is created. This mechanism includes a background preheating unit and a staged preheating unit, allowing requests to be processed after partial preheating, effectively balancing startup speed and performance optimization.

[0013] In one embodiment, the state saving and recovery module is used to serialize and save the loaded class information and the machine code of the compiled method, and quickly restore these states in the new JVM instance. The module includes a class loading state serialization unit, a JIT compilation state saving unit and a fast recovery unit, which significantly reduces the time to restart the function.

[0014] In some embodiments, the adaptive optimization module is used to continuously monitor system performance indicators and dynamically adjust preloading strategies and cache strategies. The module includes a performance monitoring unit, a strategy adjustment unit, and a resource balancing unit to ensure that the system can maintain optimal performance in different scenarios.

[0015] In addition, the present invention may also include a security isolation module for ensuring that class loading and code caching between different function instances do not affect each other, and maintaining version information of classes and code caches, thereby ensuring the security and stability of the system.

[0016] In other embodiments, the present invention further provides an API module for allowing developers to manually specify classes that need to be preloaded, and integrate with a common Java serverless platform, thereby enhancing the flexibility and applicability of the system.

[0017] In a preferred embodiment, the system of the present invention performs static code analysis during the function deployment phase to identify classes that may be used; dynamically tracks the classes actually loaded and their order when the function is running; trains a machine learning model based on these data to predict class loading requirements; then optimizes the loading process through a hierarchical class loading system, while using fine-grained code caching to improve execution efficiency; starts asynchronous preheating immediately after the function instance is created; and finally maintains optimal system performance through continuous monitoring and adaptive optimization.

[0018] In another preferred embodiment, the method of the present invention includes static analysis and dynamic tracking of function codes to predict the set of classes that may be needed; based on the prediction results, loading classes at different levels according to priority through a hierarchical class loading system; using a fine-grained code cache module to cache hot methods, inline information and class structure information; after the function instance is created, starting an asynchronous preheating mechanism to perform class loading and JIT compilation preheating; serializing and saving the loaded class information and the machine code of the compiled method, and quickly restoring it when needed; continuously monitoring system performance indicators, dynamically adjusting preloading strategies and caching strategies, and achieving adaptive optimization.

[0019] By adopting the above scheme, the present invention has the following beneficial effects: (1) Significantly reduces the cold start time of Java Serverless functions and improves function response speed; (2) Through intelligent prediction and hierarchical loading, the class loading process is optimized and resource utilization efficiency is improved; (3) Fine-grained code caching and asynchronous preheating mechanisms effectively improve code execution efficiency; (4) The state saving and quick recovery functions greatly shorten the time it takes to restart a function; (5) Adaptive optimization ensures that the system maintains optimal performance in different scenarios.

[0020] In summary, the present invention provides a comprehensive, efficient and flexible Java Serverless function cold start optimization solution, which not only significantly improves function performance, but also maintains the dynamic characteristics and security of Java, providing strong support for Java applications in Serverless computing environments. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work.

[0022] Figure 1 It is the overall system architecture diagram. It shows the main modules of the present invention and their interrelationships, including intelligent class analysis and prediction module, hierarchical class loading system, fine-grained code cache module, asynchronous preheating mechanism, state preservation and recovery module and adaptive optimization module.

[0023] Figure 2 This is the structure diagram of the intelligent class analysis and prediction module. It shows in detail the three main components of the module: static analysis unit, dynamic tracking unit and machine learning unit.

[0024] Figure 3 It is a diagram of the hierarchical class loading system. It describes the four loading layers of the system: core layer, function layer, library layer and dynamic layer.

[0025] Figure 4 This is a structural diagram of the fine-grained code cache module. It shows the three main units of the module: method-level cache unit, inline cache unit, and type information cache unit.

[0026] Figure 5 It is a structural diagram of the asynchronous preheating mechanism. It illustrates the two main units contained in the mechanism: the background preheating unit and the staged preheating unit.

[0027] Figure 6 This is the structure diagram of the state preservation and recovery module. It shows the three key components of the module: class loading state serialization unit, JIT compilation state preservation unit and fast recovery unit.

[0028] Figure 7 It is the structure diagram of the adaptive optimization module. It describes the three main units of the module: performance monitoring unit, policy adjustment unit and resource balancing unit.

[0029] Figure 8 This is the structure diagram of the security isolation and API module. It shows the two main components of the module: the security isolation unit and the API interface unit.

[0030] Fig. 9 This is a flowchart of the full-process optimization example. It describes the entire process from function deployment to continuous optimization, including initialization optimization, cold start, request processing, runtime optimization, multi-instance collaboration, state preservation, and developer interaction. DETAILED DESCRIPTION

[0031] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions 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 scope of protection of the present invention.

[0032] In the description of the present invention, it should be noted that the terms "center", "up", "down", "left", "right", "vertical", "horizontal", "inside", "outside" and the like indicate directions or positional relationships based on the directions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore should not be understood as a limitation on the present invention.

[0033] Example 1: Overall system architecture.

[0034] Reference Figure 1 The overall architecture of the Java Serverless function cold start optimization system based on predictive class loading and code caching provided by the present invention is as follows. The system includes an intelligent class analysis and prediction module 100, a hierarchical class loading system 200, a fine-grained code cache module 300, an asynchronous preheating mechanism 400, a state preservation and recovery module 500, and an adaptive optimization module 600. These modules work together to form a complete optimization cycle, which significantly improves the cold start performance of Java Serverless functions.

[0035] The intelligent class analysis and prediction module 100 is one of the core innovations of this system. It realizes high-precision class loading demand prediction through static analysis, dynamic tracing and machine learning technology. The module includes a static analysis unit 110, a dynamic tracing unit 120 and a machine learning unit 130. The static analysis unit 110 performs in-depth analysis of the code during the function deployment phase to identify all classes that may be used. The dynamic tracing unit 120 records the actual loaded classes and their loading order when the function is running. The machine learning unit 130 trains a prediction model based on these data. The model uses an improved long short-term memory network (LSTM) algorithm, which can predict the class set that may be required for the next call based on the function call context and historical data.

[0036] The hierarchical class loading system 200 is another innovative point of the present invention. It implements an efficient class loading strategy based on the output of the intelligent class analysis and prediction module 100. The system includes a core layer 210, a function layer 220, a library layer 230 and a dynamic layer 240. The core layer 210 contains the core classes required for the Java runtime, which are preloaded into the memory when the system starts. The function layer 220 contains the classes and direct dependencies defined by the function, which are loaded first when the function instance is created. The library layer 230 contains the classes of commonly used third-party libraries, which are loaded on demand according to the prediction results. The dynamic layer 240 is responsible for processing the classes dynamically loaded at runtime. This hierarchical structure not only improves the efficiency of class loading, but also optimizes memory usage.

[0037] The fine-grained code cache module 300 is a key component of the system to improve code execution efficiency. It includes a method-level cache unit 310, an inline cache unit 320, and a type information cache unit 330. The method-level cache unit 310 uses an improved LRU (Least Recently Used) algorithm to cache the compiled machine code of hot methods, greatly reducing the overhead of JIT compilation. The inline cache unit 320 saves the inline information of commonly used method calls, speeding up the method calling process. The type information cache unit 330 caches the structural information of the class, significantly improving the performance of reflection operations. This fine-grained cache strategy enables the system to maximize the cache effect within a limited memory space.

[0038] The asynchronous preheating mechanism 400 is an important innovation of the present invention to improve the function response speed. It includes a background preheating unit 410 and a staged preheating unit 420. The background preheating unit 410 immediately starts a background thread to perform class loading and JIT compilation preheating after the function instance is created. The staged preheating unit 420 divides the preheating process into multiple stages, allowing the request to be processed after partial preheating, thereby realizing the parallel execution of preheating and request processing. This mechanism significantly reduces the response delay perceived by users.

[0039] The state preservation and recovery module 500 is the core component of the system for quickly restoring the function execution state. It includes a class loading state serialization unit 510, a JIT compilation state preservation unit 520 and a fast recovery unit 530. The class loading state serialization unit 510 uses an improved serialization algorithm to efficiently save the loaded class information. The JIT compilation state preservation unit 520 saves the machine code and related metadata of the compiled method. The fast recovery unit 530 can restore the saved state to a new JVM instance in a very short time. This mechanism greatly shortens the time it takes to restart a function.

[0040] The adaptive optimization module 600 is the key to ensure the long-term efficient operation of the system. It includes a performance monitoring unit 610, a policy adjustment unit 620 and a resource balancing unit 630. The performance monitoring unit 610 continuously monitors the performance indicators of class loading, JIT compilation and function execution. The policy adjustment unit 620 dynamically adjusts the preloading strategy and cache strategy according to the monitoring data. The resource balancing unit 630 finds the best balance between performance improvement and resource consumption. This adaptive mechanism enables the system to always maintain the best performance under different loads and environments.

[0041] The workflow of this system is as follows: (1) When the function is deployed, the intelligent class analysis and prediction module 100 performs static analysis on the code; (2) When the function is run for the first time, the hierarchical class loading system 200 loads the necessary classes based on the prediction results; (3) The fine-grained code cache module 300 starts caching hotspot methods and related information; (4) The asynchronous preheating mechanism 400 performs preheating in the background while allowing requests to be processed; (5) The state saving and recovery module 500 saves the state after the function execution ends; (6) The adaptive optimization module 600 continuously monitors and adjusts system performance; (7) When the function is run again, the previously saved state is quickly restored, significantly reducing the startup time.

[0042] It should be noted that the present invention is not limited to the above specific implementations. Those skilled in the art can make appropriate adjustments to the system architecture according to actual needs, such as adding a security isolation module or an API module, or optimizing the implementation of certain modules for specific application scenarios. These changes should all be considered as the protection scope of the present invention.

[0043] The innovation of this embodiment lies in: 1) realizing high-precision class loading demand prediction through intelligent class analysis and prediction; 2) adopting multi-level, fine-grained class loading and code caching strategies; 3) introducing an optimization method combining asynchronous preheating and staged loading; 4) developing a JVM state fast saving and recovery mechanism adapted to the Serverless environment; 5) realizing a comprehensive adaptive optimization system. The organic combination of these innovations, rather than a simple combination, enables this system to significantly improve the performance of Serverless functions while maintaining the dynamic characteristics of Java.

[0044] Embodiment 2: Intelligent class analysis and prediction module.

[0045] Reference Figure 2The intelligent class analysis and prediction module 100 of the present invention is a core component of system performance optimization. It realizes high-precision class loading demand prediction through an innovative combination of static analysis, dynamic tracing and machine learning technologies. The module includes a static analysis unit 110, a dynamic tracing unit 120 and a machine learning unit 130.

[0046] The static analysis unit 110 performs in-depth analysis of the code during the function deployment phase. It uses improved control flow graph (CFG) and data flow analysis techniques to not only identify directly referenced classes, but also infer classes that may be used through reflection or dynamic loading. The specific steps are as follows: (1) Build the abstract syntax tree (AST) of the function; (2) Generate a control flow graph based on AST; (3) Conduct arrival definition analysis and active variable analysis; (4) Identify explicit and implicit class references; (5) Generate a set of classes that may be used.

[0047] In order to improve the accuracy of the analysis, we introduced a class usage probability scoring mechanism. For each identified class C, its usage probability P(C) is calculated as follows: P(C) = α * Ds(C) + β * Di(C) + γ * Dr(C) Among them, Ds(C) represents the static direct citation degree, Di(C) represents the indirect citation degree, and Dr(C) represents the possibility of reflective use. α, β, and γ are weight coefficients, satisfying α + β + γ = 1. This innovative probability model makes the static analysis results more accurate and provides a reliable basis for subsequent predictions.

[0048] The dynamic tracking unit 120 records the classes actually loaded and their loading order when the function is running. It uses lightweight bytecode instrumentation technology to insert tracking code at the time of class loading and collect the following information: fully qualified name of the class, loading timestamp, loading trigger point (method call, reflection, etc.), and class loader information.

[0049] To minimize the impact of tracking on performance, we designed an adaptive sampling algorithm. The sampling rate R is dynamically adjusted as follows: R = min(Rbase * (1 + log(N)), Rmax) Among them, Rbase is the base sampling rate, N is the number of function calls, and Rmax is the maximum sampling rate. This algorithm ensures that more valuable data can be obtained as the number of function calls increases while keeping the overhead low.

[0050] The machine learning unit 130 is the core innovation of this module. It trains an improved long short-term memory network (LSTM) model to predict class loading requirements based on static analysis and dynamic tracking data. The input of the model includes: function call context (such as request parameter type, call time, etc.), historical class loading sequence, and static analysis of class usage probability.

[0051] The output of the model is the set of classes that may be needed for the next call and their loading probability. In order to improve the prediction accuracy, we introduced the attention mechanism and residual connection. The core prediction function of the model can be expressed as: Ct+1 = σ(Wc[ht, at] + bc) Among them, Ct+1 is the set of predicted classes, ht is the hidden state of LSTM, at is the attention vector, Wc and bc are learnable parameters, and σ is the activation function.

[0052] In order to handle the sudden changes in the function call pattern in the Serverless environment, we designed an online learning mechanism. After each function call, the model will be updated in small batches based on the actually loaded classes. The update formula is as follows: θt+1 = θt - η ∇L(θt) Among them, θt is the model parameter, η is the learning rate, and L(θt) is the loss function. The learning rate η adopts an adaptive adjustment strategy to balance the stability and adaptability of the model.

[0053] This innovative prediction model can not only accurately predict regular class loading requirements, but also quickly adapt to changes in function behavior, providing precise guidance for the hierarchical class loading system.

[0054] The workflow of this module is as follows: (1) When the function is deployed, the static analysis unit performs deep code analysis to generate the initial class usage probability distribution; (2) When the function runs for the first time, the dynamic tracing unit starts collecting actual class loading data; (3) The machine learning unit initializes the model based on the static analysis results and uses dynamic tracking data for continuous training; (4) Before each function call, the model predicts the set of classes that may be needed; (5) After the function is called, the model is updated based on the actually loaded class.

[0055] Through this deep combination of static analysis, dynamic tracing, and machine learning, this module can provide more accurate class loading predictions than traditional methods, significantly reducing unnecessary class loading while ensuring the timely availability of required classes. This not only optimizes startup performance, but also improves overall resource utilization efficiency.

[0056] It should be noted that the specific implementation of this module can be adjusted according to the actual application scenario. For example, for applications in specific fields, domain knowledge can be added to static analysis, or specific feature engineering techniques can be introduced into machine learning models. These variants should all be considered as the scope of protection of the present invention.

[0057] Embodiment 3: Hierarchical class loading system.

[0058] Reference Figure 3 The hierarchical class loading system 200 of the present invention is a key innovation for optimizing the Java Serverless function class loading process. The system implements an efficient and flexible class loading strategy based on the output of the intelligent class analysis and prediction module 100. The hierarchical class loading system includes a core layer 210, a function layer 220, a library layer 230, and a dynamic layer 240.

[0059] The core layer 210 contains the core classes required by the Java runtime, which are preloaded into the memory when the system starts. The implementation of the core layer involves technologies such as predefined core class lists, customized class loaders, early loading, and memory optimization. It is particularly worth mentioning that we use the class data sharing (CDS) technology to store the metadata of the core class in the shared memory, effectively reducing the memory usage of each function instance.

[0060] An important innovation of the core layer is its dynamic adjustment mechanism. The system continuously monitors the usage of core classes and dynamically adjusts the core class set according to the following formula: CoreScore(C) = α * F(C) + β * T(C) - γ * S(C) Among them, F(C) is the usage frequency of class C, T(C) is the average loading time, S(C) is the size of the class, and α, β, and γ are weight coefficients. When the CoreScore exceeds the preset threshold, the corresponding class will be promoted to the core layer; otherwise, it will be downgraded. This mechanism ensures that the core layer always contains the most important and most commonly used classes, thereby optimizing startup performance.

[0061] The function layer 220 contains the classes and direct dependencies of the function definition, which are loaded first when the function instance is created. The implementation of the function layer includes technologies such as function dependency analysis, lazy loading optimization, and parallel loading. We have specially designed an improved lazy loading strategy that only loads the class when it is first accessed, but pre-parses the symbolic reference of the class, which greatly speeds up the actual loading speed of the class.

[0062] The main innovation of the function layer is its adaptive preloading mechanism. Based on the output of the intelligent class analysis and prediction module, the system dynamically adjusts the preloading strategy: PreloadPriority(C) = P(C) * I(C) / L(C) Among them, P(C) is the predicted usage probability, I(C) is the importance score of the class, and L(C) is the loading time. The system will give priority to preloading classes with high PreloadPriority. This method significantly improves the accuracy and efficiency of class loading.

[0063] The library layer 230 contains classes of commonly used third-party libraries, which are loaded on demand based on the prediction results. The implementation of the library layer involves technologies such as library dependency analysis, version control, and on-demand loading. We have developed a version-aware class loader that supports the coexistence of different versions of the same library, which solves the common dependency conflict problem in the Serverless environment.

[0064] The innovation of the library layer lies in its incremental loading and caching mechanism. We split large libraries into multiple modules and load them incrementally based on the prediction results. This method effectively reduces unnecessary class loading. In addition, under the premise of ensuring security isolation, we have implemented cross-function instance shared caching of library classes, which significantly improves resource utilization efficiency.

[0065] The dynamic layer 240 is responsible for processing classes dynamically loaded at runtime, mainly dealing with scenarios such as reflection and dynamic proxy. The implementation of the dynamic layer includes technologies such as dynamic class prediction, asynchronous preloading, and fast parsing. We have especially optimized the class parsing process, which greatly reduces the delay of dynamic loading.

[0066] The main innovation of the dynamic layer is its adaptive caching strategy: CacheScore(C) = δ * D(C) + ε * F(C) - ζ * M(C) Among them, D(C) is the dynamic loading frequency of class C, F(C) is the call frequency, M(C) is the memory usage, and δ, ε, ζ are weight coefficients. The system dynamically adjusts the cache strategy according to CacheScore. This method ensures that the most commonly used dynamically loaded classes can be accessed quickly.

[0067] The overall workflow of the hierarchical class loading system is as follows: when the system starts, the core layer preloads the basic class; when the function instance is created, the function layer starts to load the function-related class; during the execution process, the library layer loads the third-party library class according to the demand; when encountering dynamic loading requirements, the dynamic layer handles the corresponding class loading request. During the whole process, the system continuously monitors the performance indicators of each layer and dynamically adjusts the loading strategy.

[0068] The innovation of this embodiment is mainly reflected in the multi-level architecture, adaptive loading strategy, cross-function optimization and dynamic adjustment, etc. This innovative hierarchical class loading system not only significantly improves the class loading efficiency, but also optimizes memory usage, providing Java Serverless functions with faster startup speed and higher operating efficiency.

[0069] Embodiment 4: Fine-grained code cache module.

[0070] Reference Figure 4 The fine-grained code cache module 300 of the present invention is a key component for improving the execution efficiency of Java Serverless functions. The module significantly reduces the overhead of code compilation and execution through a refined cache strategy. The fine-grained code cache module includes a method-level cache unit 310, an inline cache unit 320, and a type information cache unit 330.

[0071] The method-level cache unit 310 is responsible for caching the compiled machine code of hotspot methods. This unit uses an improved LRU (Least Recently Used) algorithm to dynamically manage cache content based on the method's call frequency and execution time. The key to caching is how to accurately identify and predict hotspot methods. To this end, we designed a hotspot prediction model: HotScore(M) = λ * F(M) + μ * T(M) + ν * C(M) Where F(M) is the calling frequency of method M, T(M) is the average execution time, C(M) is the compilation complexity, and λ, μ, ν are weight coefficients. When the HotScore exceeds the preset threshold, the compiled machine code of the method will be cached. This mechanism ensures that the most critical methods are always kept in the cache, greatly reducing the overhead of JIT compilation.

[0072] Another innovation of method-level cache is its adaptive hierarchical mechanism. The cache is divided into three layers: L1, L2, and L3, corresponding to extremely hot, high, and general methods respectively. Each layer uses different cache strategies and update frequencies to balance access speed and memory usage. For example, the L1 cache uses full memory storage, while the L3 cache may use partial disk storage. This hierarchical design greatly improves cache efficiency while optimizing resource usage.

[0073] The inline cache unit 320 focuses on optimizing the method call process. Due to the dynamic nature of Java, method calls usually require runtime lookups, which can cause significant performance overhead in a serverless environment. Our inline cache mechanism greatly reduces this overhead by caching the target address of method calls.

[0074] The core innovation of inline cache lies in its polymorphic adaptation mechanism. The efficiency of traditional inline cache will drop significantly when encountering polymorphic calls. To solve this problem, we designed Adaptive Polymorphic Inline Cache (APIC): APIC(Call) = {(Type1, Target1, P1), (Type2, Target2, P2), ...,(TypeN, TargetN, PN)} Among them, Typei is the receiver type, Targeti is the corresponding method address, and Pi is the probability of occurrence of the type. APIC dynamically learns and adjusts these probabilities and optimizes the cache structure according to the probability distribution. For high-frequency types, the system generates machine code for direct jumps; for low-frequency types, it degenerates to conventional virtual method table lookups. This mechanism greatly improves the performance of polymorphic calls.

[0075] The type information cache unit 330 caches the structural information of the class, mainly used to optimize reflection operations and dynamic calls. In a Serverless environment, the performance of reflection operations is particularly important because many frameworks and libraries use reflection extensively to achieve flexibility. Our type information cache not only stores the basic structure of the class, but also includes detailed information such as method signatures and field layouts.

[0076] The innovation of the type information cache lies in its incremental update mechanism. When a class is modified (such as through bytecode enhancement), traditional methods usually need to discard the entire cache entry. Our incremental update mechanism only updates the changed part, greatly improving the stability and efficiency of the cache. The update process can be expressed as: UpdatedCache(C) = MergeΔ(CurrentCache(C), Changes(C)) MergeΔ is an intelligent merge function that can efficiently integrate changes into the existing cache.

[0077] The overall workflow of the fine-grained code cache module is as follows: When a function instance is started, the system first loads cache metadata from persistent storage. During execution, the method-level cache unit continuously monitors method execution and dynamically adjusts the cache content. The inline cache unit inserts cache logic at the method call point and adjusts the cache structure according to the actual call pattern. The type information cache unit provides fast type information access during reflection operations and dynamic calls. Throughout the process, each unit works together to continuously optimize the cache strategy.

[0078] The main innovations of this embodiment include: adaptive hotspot method identification and caching, multi-level cache structure, adaptive polymorphic inline cache mechanism, and incremental update strategy of type information. These innovations greatly improve the efficiency of code execution, especially in the scenario of frequent cold start in Serverless environment. At the same time, fine-grained caching strategy and dynamic adjustment mechanism ensure the maximum performance improvement within the limited memory space.

[0079] Through this fine-grained code caching module, the present invention not only significantly reduces the execution time of Java Serverless functions, but also improves resource utilization efficiency.

[0080] Embodiment 5: Asynchronous preheating mechanism.

[0081] Reference Figure 5 The asynchronous preheating mechanism 400 of the present invention is a key innovation for improving the response speed of Java Serverless functions. The mechanism significantly reduces the cold start time of functions through intelligent background preheating and phased loading strategies, while ensuring efficient use of resources. The asynchronous preheating mechanism includes a background preheating unit 410 and a phased preheating unit 420.

[0082] The background preheating unit 410 is responsible for starting the background thread to perform class loading and JIT compilation preheating immediately after the function instance is created. The core idea of ​​this unit is to use the time window between the creation of the function instance and the arrival of the actual request to perform necessary preparations in advance. The workflow of the background preheating unit is as follows: First, based on the output of the intelligent class analysis and prediction module, the set of classes and methods that need to be preheated is determined. Then, a low-priority background thread is started to perform the preheating task. During the preheating process, the system will dynamically adjust the depth and breadth of the preheating to balance the preheating effect and resource consumption.

[0083] The key to the preheating strategy is how to maximize the preheating effect within a limited time. To this end, we introduced a preheating value scoring mechanism: PrewarmValue(E) = ω * P(E) + φ * I(E) - ψ * C(E) Where E can be a class or a method, P(E) is the probability of use, I(E) is the performance impact, C(E) is the prewarming cost, and ω, φ, ψ are weight coefficients. The system prioritizes prewarming tasks based on PrewarmValue to ensure that the most valuable elements are prewarmed first.

[0084] Another innovation of the background preheating unit is its adaptive resource control mechanism. In a Serverless environment, resource usage is directly related to cost. We designed a dynamic resource allocation algorithm to adjust the resource quota of the preheating thread in real time according to the current system load and preheating effect: ResourceQuota = BaseQuota * (1 + α * EffectivenessFactor - β *LoadFactor) Among them, EffectivenessFactor reflects the effectiveness of preheating, LoadFactor represents the system load, and α and β are the balance points for adjusting the system. This algorithm ensures that the preheating process does not significantly affect the main business logic while maximizing the preheating effect.

[0085] The phased preheating unit 420 is responsible for dividing the preheating process into multiple stages, allowing the request to be processed after partial preheating. This mechanism greatly reduces the response delay perceived by users. The core idea of ​​phased preheating is to divide the preheating task into multiple stages according to importance and dependency. After each stage is completed, the readiness of the function will be improved.

[0086] We designed an innovative multi-stage warm-up model: Stage 1: core class loading and basic environment initialization; Stage 2: Key business logic class loading and JIT compilation; Stage 3: Minor features and optimizations; Each stage has a completion threshold, when the threshold is reached, the system will mark the stage as complete and can start accepting requests. This mechanism ensures that the function reaches a usable state in the shortest time while continuing to perform deeper warm-up in the background.

[0087] Another innovation of the phased preheating is its dynamic phase adjustment mechanism. The system continuously monitors the effect and time consumption of each phase, and dynamically adjusts the phase division and threshold according to the actual situation: StageEffectiveness(S) = Σ(ImprovementFactor(E) / Time(E)) for all Ein S The system dynamically adjusts the content and order of each stage according to StageEffectiveness to ensure that the warm-up process always maintains optimal efficiency.

[0088] The overall workflow of the asynchronous preheating mechanism is as follows: After the function instance is created, the background preheating unit starts immediately and begins to execute the preheating task with the highest priority. At the same time, the staged preheating unit initializes the preheating stage and sets the goals and thresholds for each stage. As the preheating proceeds, the system continuously evaluates the preheating effect and resource usage, and dynamically adjusts the preheating strategy. When the completion threshold of the first stage is reached, the function can start accepting requests, while the preheating of subsequent stages continues in the background. Throughout the process, the system continuously optimizes the preheating strategy to adapt to different load conditions and function characteristics.

[0089] The main innovations of this embodiment include: intelligent preheating strategy based on value scoring, adaptive resource control mechanism, multi-stage preheating model, and dynamic stage adjustment mechanism. These innovations effectively solve the problem of slow cold start of Java Serverless functions and significantly improve the response speed and resource utilization efficiency of functions.

[0090] Through this asynchronous preheating mechanism, the present invention not only greatly reduces the cold start time of the Java Serverless function, but also realizes the parallel execution of the preheating process and request processing, greatly improving the user experience. Example 6: State preservation and recovery module.

[0091] Reference Figure 6 The state preservation and recovery module 500 of the present invention is a key component for realizing the fast startup of Java Serverless functions. The module significantly shortens the cold start time of functions through innovative serialization technology and fast recovery mechanism. The state preservation and recovery module includes a class loading state serialization unit 510, a JIT compilation state preservation unit 520, and a fast recovery unit 530.

[0092] The class loading state serialization unit 510 is responsible for efficiently saving the loaded class information. The traditional class loading process needs to be repeated every time a function is started, which is one of the main reasons for cold start delays. Our innovation lies in designing a lightweight class state serialization method, which not only saves the basic information of the class, but also includes key data such as the class initialization state and static field values.

[0093] The serialization process uses an incremental approach: SerializedState(C) = BaseInfo(C) + ΔState(C) Among them, BaseInfo(C) contains the invariant information of the class, such as class structure, method signature, etc., while ΔState(C) contains variable state, such as static field values, initialization flags, etc. This method greatly reduces the amount of data that needs to be serialized each time and improves efficiency.

[0094] To further optimize the serialization process, we introduced a selective serialization strategy: SerializationPriority(C) = η * Usage(C) + θ * InitCost(C) - ρ * Size(C) Among them, Usage(C) is the usage frequency of the class, InitCost(C) is the initialization cost of the class, Size(C) is the size after serialization, and η, θ, ρ are weight coefficients. The system selectively serializes high-priority classes based on SerializationPriority to maximize performance improvement within limited storage space.

[0095] The JIT compilation state preservation unit 520 is responsible for preserving the machine code and related metadata of the compiled method. JIT compilation is the key to Java runtime performance optimization, but it is also a major overhead during the cold start process. Our innovation lies in designing a cross-session JIT compilation state preservation mechanism.

[0096] The core of this mechanism is an adaptive compilation state selection algorithm: CompilationValueScore(M) = σ * ExecutionFrequency(M) + τ *CompilationCost(M) - υ * CodeSize(M) Among them, ExecutionFrequency(M) is the execution frequency of the method, CompilationCost(M) is the compilation cost, CodeSize(M) is the size of the compiled code, σ, τ, υ are weight coefficients. The system decides which methods' compilation status needs to be saved based on CompilationValueScore.

[0097] To handle compatibility issues with different hardware architectures and JVM versions, we introduced an intermediate representation layer (IR): SavedState(M) = {IR(M), OptimizationInfo(M), DependencyInfo(M)} IR(M) is the intermediate representation of the method, OptimizationInfo(M) contains optimization decision information, and DependencyInfo(M) records the dependencies between methods. This design enables the saved state to be quickly adapted and reused in different environments.

[0098] The fast recovery unit 530 is the core of this module and is responsible for quickly restoring the saved state in the new JVM instance. The traditional JVM startup process includes multiple steps such as class loading, verification, preparation, parsing and initialization. Our fast recovery mechanism greatly shortens this process through innovative methods.

[0099] The key to fast recovery lies in the combination of parallel recovery and lazy loading: RecoveryPlan = {ImmediateRecover: [C1, C2, ...], LazyRecover: [C3,C4, ...]} Based on the importance and dependencies of the classes, the system puts some key classes into the ImmediateRecover list for immediate recovery, and puts other classes into the LazyRecover list for lazy loading. This strategy ensures that the most critical classes and methods are available immediately while avoiding unnecessary recovery overhead.

[0100] To further improve the recovery speed, we designed an innovative memory mapping technology that maps the serialized state directly into memory, avoiding the data copy overhead in the traditional deserialization process: MemoryMap(State) = CreateMapping(SerializedState, VirtualMemory) This technique greatly speeds up the state recovery process, especially for large applications.

[0101] The overall workflow of the state preservation and recovery module is as follows: At the end of function execution, the class loading state serialization unit and the JIT compilation state preservation unit save the relevant states respectively. When a new function instance needs to be started, the fast recovery unit first loads the saved state metadata, and then performs parallel recovery and lazy loading according to the recovery plan. During the whole process, the system continuously monitors the recovery effect and dynamically adjusts the recovery strategy to adapt to different operating environments and load conditions.

[0102] The main innovations of this embodiment include: incremental class state serialization method, selective serialization strategy, cross-session JIT compilation state preservation mechanism, intermediate representation layer design, fast recovery strategy combining parallel recovery and lazy loading, and memory mapping technology. These innovations significantly reduce the cold start time of Java Serverless functions, allowing functions to reach optimal performance almost instantly.

[0103] Through this state preservation and recovery module, the present invention not only greatly improves the startup speed of Java Serverless functions, but also ensures that the performance of the restored functions is comparable to that of long-running functions. This is particularly important for Serverless application scenarios that require frequent cold starts, and greatly expands the application scope and competitiveness of Java in the field of Serverless computing.

[0104] Embodiment 7: Adaptive optimization module.

[0105] Reference Figure 7 The adaptive optimization module 600 of the present invention is a key component to ensure the long-term and efficient operation of Java Serverless functions. The module realizes adaptive optimization of system performance through continuous monitoring, dynamic adjustment and intelligent resource balancing. The adaptive optimization module includes a performance monitoring unit 610, a policy adjustment unit 620 and a resource balancing unit 630.

[0106] The performance monitoring unit 610 is responsible for continuously collecting and analyzing various performance indicators of the system. In a serverless environment, performance monitoring faces unique challenges, such as the short life cycle of function instances and high load variability. To this end, we designed a distributed, low-overhead monitoring system.

[0107] The system uses an innovative sampling strategy: SamplingRate(M) = BaseRate * (1 + log(Importance(M))) * (1 - exp(-LoadFactor)) Among them, M is the monitored indicator, Importance(M) reflects the importance of the indicator, and LoadFactor represents the system load. This strategy ensures that representative performance data can be obtained under different load conditions, while keeping the monitoring overhead within an acceptable range.

[0108] The performance monitoring unit not only collects raw data, but also performs real-time data analysis and anomaly detection. We use an anomaly detection algorithm based on time series: AnomalyScore(M, t) = |M(t) - Forecast(M, t)| / σ(M) Among them, M(t) is the actual value of indicator M at time t, Forecast(M, t) is the predicted value, and σ(M) is the standard deviation of the indicator. When AnomalyScore exceeds the threshold, the system triggers an alarm and starts the corresponding optimization process.

[0109] The strategy adjustment unit 620 is the core of this module and is responsible for dynamically adjusting the optimization strategies of the system based on monitoring data. Traditional static optimization strategies are difficult to cope with the complexity and variability of the Serverless environment. Our innovation lies in designing a self-learning strategy adjustment system.

[0110] The system is based on a reinforcement learning algorithm, and the system state, action, and reward are defined as follows: State: S = {PerformanceMetrics, ResourceUsage,WorkloadCharacteristics}Action: A = {AdjustCacheSize, ModifyPrewarmStrategy,TuneClassLoadingPolicy, ...}Reward: R = PerformanceImprovement - ResourceCost The system gradually learns the optimal strategy adjustment plan by constantly trying different actions and observing the rewards. To accelerate the learning process, we introduce an initial strategy and safety margin based on domain knowledge to ensure that there is no serious performance degradation during the learning process.

[0111] Another innovative aspect of policy adjustment is its multi-objective optimization mechanism. In a serverless environment, multiple objectives such as performance, cost, and reliability need to be considered simultaneously. We adopted the Pareto optimization method: ParetoScore(Strategy) = Σ wi * Objective(i) Among them, Objective(i) represents different optimization objectives, and wi is the corresponding weight. The system maintains a Pareto optimal solution set and dynamically selects the most suitable strategy based on the current priority.

[0112] The resource balancing unit 630 is responsible for finding the best balance between performance improvement and resource consumption. In a serverless environment, resource usage is directly related to operating costs, so efficient resource management is crucial. We designed a dynamic resource allocation algorithm: ResourceAllocation(F) = BaseAllocation * (1 + δ * PerformancGain(F) -ε * CostFactor) Among them, F represents a specific function instance, PerformanceGain(F) reflects the performance improvement brought by the increase of resources, CostFactor takes into account the resource cost, and δ and ε are balance coefficients. This algorithm can dynamically adjust resource allocation according to the actual needs and performance of the function to maximize resource utilization.

[0113] Another innovation of the resource balancing unit is its predictive resource scheduling mechanism. By analyzing historical load patterns and current trends, the system is able to predict future resource requirements: PredictedDemand(t) = ARIMA(HistoricalDemand) + TrendAdjustment(t) Based on this prediction, the system can prepare and schedule resources in advance, effectively reducing performance problems caused by insufficient or excessive resources.

[0114] The overall workflow of the adaptive optimization module is as follows: The performance monitoring unit continuously collects various system indicators for real-time analysis and anomaly detection. The policy adjustment unit dynamically adjusts various optimization strategies based on these data and the reinforcement learning algorithm. The resource balancing unit performs real-time resource allocation and scheduling based on current performance and predicted demand. These three units work closely together to form a closed-loop adaptive optimization system to ensure that Java Serverless functions can maintain optimal performance under various loads and environments.

[0115] The main innovations of this embodiment include: a distributed monitoring system with adaptive sampling, a policy adjustment mechanism based on reinforcement learning, a multi-objective Pareto optimization method, a dynamic resource allocation algorithm, and a predictive resource scheduling mechanism. These innovations enable the system to intelligently respond to various challenges in the Serverless environment, continuously optimize performance, and control costs.

[0116] Through this adaptive optimization module, the present invention not only ensures the long-term and efficient operation of Java Serverless functions, but also optimizes resource utilization, greatly improving the cost-effectiveness of the system.

[0117] Example 8: Security isolation and API module.

[0118] Reference Figure 8 The security isolation and API module 700 of the present invention is an important component to ensure the security and usability of Java Serverless functions. The module implements a highly secure multi-tenant environment and a convenient development interface through innovative isolation technology and flexible API design. The security isolation and API module includes a security isolation unit 710 and an API interface unit 720.

[0119] The security isolation unit 710 is responsible for ensuring that class loading and code caching between different function instances do not affect each other, while maintaining the version information of the class and code cache. In a Serverless environment, multiple functions may share the same physical machine resources, so an effective isolation mechanism is crucial to ensuring security and performance stability.

[0120] We designed an innovative multi-layer isolation architecture: IsolationLayer = {NamespaceIsolation, MemoryIsolation,ResourceIsolation} NamespaceIsolation uses improved class loader isolation technology. Each function instance has its own class loader hierarchy, ensuring the isolation of class definitions: ClassLoader(F) = {BootstrapLoader, ExtensionLoader, AppLoader(F)} Among them, AppLoader(F) is an application class loader specially customized for each function F, which implements the following isolation strategy: LoadClass(C, F) = if (C in SharedClasses) then SharedClassLoader.loadClass(C) else AppLoader(F).defineClass(C) This strategy allows safe sharing of common classes while ensuring that each function's private classes do not interfere with each other.

[0121] MemoryIsolation uses the JVM's heap isolation technology to allocate independent heap space for each function: HeapAllocation(F) = BaseHeap + DynamicHeap(F) Among them, DynamicHeap(F) is dynamically adjusted according to the needs of function F. We also implemented a safety check mechanism for cross-heap references to prevent potential memory leaks and illegal access.

[0122] ResourceIsolation uses virtualization technology to isolate resources such as CPU and I / O. We use a resource restriction mechanism based on cgroups and introduce a dynamic resource allocation algorithm: ResourceLimit(F, R) = BaseLimit(R) * (1 + α * Priority(F) - β * Usage(F)) Among them, R represents a specific resource type, Priority(F) is the priority of the function, Usage(F) is the historical usage rate, and α and β are adjustment coefficients. This mechanism ensures fair allocation and efficient utilization of resources.

[0123] Another innovation of the security isolation unit is its version control mechanism. We designed a distributed version management system: VersionControl = {ClassVersionMap, CacheVersionMap, DependencyGraph} Whenever a class or cache is updated, the system updates the corresponding version information and propagates it to the relevant nodes in the dependency graph. This ensures consistency and security in a dynamically updated environment.

[0124] The API interface unit 720 is responsible for providing a flexible and easy-to-use development interface, allowing developers to manually specify classes that need to be preloaded and integrate with common Java Serverless platforms. We have designed a set of declarative APIs that enable developers to easily optimize the performance of their functions: @Preload(classes = {"com.example.Util", "com.example.Config"}) @CacheConfig(strategy = CacheStrategy.AGGRESSIVE) public class MyFunction implements ServerlessFunction { / / Function implementation } This declarative API not only simplifies the development process, but also allows the system to make smarter optimizations based on these declarations.

[0125] To support more fine-grained control, we also provide a programmatic API: OptimizationContext ctx = OptimizationContext.getContext(); ctx.preloadClasses("com.example.DataProcessor"); ctx.setCacheStrategy(CacheStrategy.CONSERVATIVE); These APIs are seamlessly integrated with the system's core optimization modules, ensuring that the optimization strategies defined by developers can be effectively executed.

[0126] Another innovation of the API interface unit is its adaptive integration mechanism. The system can automatically detect and adapt to different Serverless platform environments: PlatformAdapter = detectPlatform() PlatformAdapter.initialize(systemConfig) This mechanism greatly simplifies the migration process between different platforms and improves the portability of the system.

[0127] The overall workflow of the security isolation and API modules is as follows: When a function is deployed, the security isolation unit creates an independent operating environment for it, including a dedicated class loader, memory space, and resource restrictions. The API interface unit parses the function's optimization declaration and converts it into optimization instructions within the system. During the function's operation, the security isolation unit continuously monitors and maintains the isolation boundary to ensure the security of the multi-tenant environment. At the same time, through the version control mechanism, the system can be dynamically updated and optimized safely.

[0128] The main innovations of this embodiment include: multi-layer isolation architecture, dynamic resource allocation algorithm, distributed version management system, declarative and programmatic optimization API, and adaptive platform integration mechanism. These innovations not only ensure the security and isolation of JavaServerless functions in a multi-tenant environment, but also provide a flexible and powerful development interface, greatly improving development efficiency and system availability.

[0129] Through this security isolation and API module, the present invention solves the security isolation problem in the Serverless environment while ensuring high performance and provides a friendly development interface.

[0130] Example 9: Full process optimization example.

[0131] This embodiment demonstrates the full-process optimization process of a Java Serverless function named "DataProcessFunction" from deployment to execution, and explains how the various modules of the present invention work together to achieve comprehensive performance improvement.

[0132] "DataProcessFunction" is a typical compute-intensive Serverless application that processes and analyzes a large amount of data records, involving data parsing, complex calculations, and database operations.

[0133] During the function deployment phase, the intelligent class analysis and prediction module first performs static analysis on the code to identify key classes and methods, such as data parsers, computing engines, and database connection managers. At the same time, based on historical data and function characteristics, it predicts possible class loading sequences and hot methods. The hierarchical class loading system then arranges the main dependent classes of the core Java runtime classes and functions in the core layer and function layer based on the analysis results, ready for preloading. Classes that may not be used immediately, such as database drivers, are placed in the library layer and use an on-demand loading strategy. The fine-grained code cache module prepares cache space in advance, focusing on predicted hot methods, such as data parsing and core computing logic.

[0134] When the first request triggers a cold start of a function, the asynchronous warm-up mechanism immediately starts loading core classes and function classes in the background. At the same time, the fast recovery unit loads the previously saved class loading state and JIT compilation state from the persistent storage, greatly speeding up the startup process. As the function starts to process data, dynamic class loading comes into play. For example, when a function accesses a database for the first time, the database driver class in the library layer is dynamically loaded. The fine-grained code cache module starts caching the compiled code of hot methods, such as frequently called data processing methods.

[0135] At runtime, the adaptive optimization module continuously monitors the performance indicators of functions, such as method call frequency, execution time, and memory usage. Based on this data, the system dynamically adjusts the class loading strategy and code caching strategy. For example, if a data processing algorithm is found to have become a new hot spot, the system will automatically increase its cache priority.

[0136] As the number of requests increases, the platform may start multiple function instances. At this time, the security isolation module ensures that each instance runs in an independent environment to prevent mutual interference. At the same time, resource optimization between instances is achieved by sharing a read-only code cache. After the function is executed, the state preservation and recovery module serializes the current class loading state and JIT compilation state to prepare for subsequent fast startup. The system intelligently selects the most valuable state information to save, balancing storage overhead and startup performance.

[0137] As the function is called multiple times, the intelligent class analysis and prediction module continuously learns and updates its prediction model, resulting in more accurate class loading predictions and more efficient preheating strategies. The adaptive optimization module also fine-tunes the parameters of each optimization module, such as cache size, preloading strategy, etc., based on long-term running data. Through the API module, developers can view the performance indicators of the function and manually adjust the optimization strategy as needed, such as marking certain key classes as preloading, or adjusting the cache strategy of specific methods.

[0138] Throughout the entire process, each module works closely together to form a complete optimization cycle. Intelligent class analysis provides guidance for loading and caching strategies, asynchronous warm-up mechanism and fast recovery technology significantly reduce cold start time, fine-grained caching and adaptive optimization ensure long-term high-performance operation, and secure isolation ensures stability and security in a multi-tenant environment.

[0139] This comprehensive optimization strategy enables "DataProcessFunction" to achieve performance close to that of traditional long-running services in a Serverless environment while maintaining the flexibility and cost-effectiveness of Serverless. Whether it is the first cold start or continuous operation under high load, the function can maintain excellent performance and responsiveness.

[0140] Through this example, we can clearly see how the present invention systematically solves the various challenges faced by Java Serverless functions, thereby fully leveraging the potential of Serverless computing while maintaining the advantages of the Java language. This opens up new possibilities for building high-performance, reliable, and economical Java Serverless applications.

[0141] For those skilled in the art, many improvements and modifications can be made without violating the principles of the present invention, all of which fall within the scope of protection of the present invention. For example, the present invention can be combined with virtualization, edge computing and other technologies to further expand the application scenarios and effects of intelligent scheduling.

Claims

1. A Java Serverless function cold start optimization system based on predictive class loading and code caching, characterized in that: include: Intelligent class analysis and prediction module, which is used to perform static analysis and dynamic tracking of function codes, and train machine learning models based on historical data to predict the most likely class sets required in different call scenarios; Hierarchical class loading system, including core layer, function layer, library layer and dynamic layer, is used to load classes at different levels according to the prediction results and priority; Fine-grained code cache module, used to cache the compiled machine code of hotspot methods, inline information of commonly used method calls, and class structure information; Asynchronous preheating mechanism, which is used to start background threads for class loading and just-in-time compilation (JIT) preheating after the function instance is created; The state preservation and restoration module is used to serialize and save the loaded class information and the machine code of the compiled methods, and quickly restore these states in a new JVM instance; The adaptive optimization module is used to continuously monitor system performance indicators and dynamically adjust preloading strategies and caching strategies.

2. The system according to claim 1, characterized in that The intelligent analysis and prediction module also includes: Static analysis unit, used to identify all possible classes used during function deployment; Dynamic tracing unit, used to record the classes actually loaded and their loading order when the function is running; A machine learning unit for training predictive models based on historical data.

3. The system according to claim 1, characterized in that In the hierarchical class loading system: The core layer contains the core classes required by the Java runtime and is always preloaded; The function layer contains the classes defined by the function and its direct dependencies, which are loaded first; The library layer contains classes of commonly used third-party libraries, which are loaded on demand based on predictions; The dynamic layer dynamically loads classes based on actual calls.

4. The system according to claim 1, characterized in that The fine-grained code cache module includes: Method-level cache unit, used to cache the compiled machine code of hotspot methods; Inline cache unit, used to store inline information of commonly used method calls; The type information cache unit is used to cache the structure information of the class and speed up reflection operations.

5. The system according to claim 1, characterized in that The asynchronous preheating mechanism includes: Background warm-up unit, used to start background threads for class loading and JIT compilation immediately after the function instance is created; A phased warmup unit is used to divide the warmup process into multiple phases, allowing to start processing requests after partial warmup.

6. The system according to claim 1, characterized in that The state preservation and recovery module includes: Class loading status serialization unit, used to serialize and save the loaded class information; JIT compilation state preservation unit, used to save the machine code and related metadata of the compiled method; A fast restore unit, used to quickly restore saved state to a new JVM instance.

7. The system according to claim 1, characterized in that The adaptive optimization module comprises: Performance monitoring unit, which continuously monitors the performance indicators of class loading, JIT compilation, and function execution; A policy adjustment unit, used to dynamically adjust the preloading policy and cache policy according to monitoring data; Resource balancing unit, used to find the best balance between performance improvement and resource consumption.

8. The system according to claim 1, characterized in that It also includes a security isolation module to ensure that class loading and code caching between different function instances do not affect each other, and maintain version information of classes and code caches.

9. The system according to claim 1, characterized in that It also includes an API module that provides an interface allowing developers to manually specify classes that need to be preloaded and integrate with common Java serverless platforms.

10. A Java Serverless function cold start optimization method based on the system according to any one of claims 1 to 9, characterized in that: The following steps are involved: Perform static analysis and dynamic tracking on function codes to predict the class sets that may be needed; Based on the prediction results, classes at different levels are loaded according to priority through the hierarchical class loading system; Use fine-grained code cache modules to cache hot methods, inline information, and class structure information; After the function instance is created, the asynchronous preheating mechanism is started to perform class loading and JIT compilation preheating; Serialization saves loaded class information and compiled method machine code and quickly restores them when needed; Continuously monitor system performance indicators, dynamically adjust preloading strategies and caching strategies, and achieve adaptive optimization.

Citation Information

Cited By

  • Strategy determination method and device

    CN121530852A