Application program running method, node and computing device cluster
By using enhancement containers in the microservice architecture for pre-bytecode enhancement and generating enhanced Java archive files, the problem of bytecode enhancement extending the startup time of Java applications is solved, and fast startup and efficient deployment is achieved.
Patent Information
- Application Number
- PCT/CN2024/092511
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-11-14
- Filing Date
- 2024-05-11
- Publication Date
- 2025-03-27
AI Technical Summary
Bytecode enhancement technology extends the startup time during the Java application startup process, causing the application to be unable to run in time, affecting the timeliness of service expansion.
By introducing enhancement containers into the microservice architecture, the original Java archive files of Java applications are loaded in advance, and bytecode enhancement is performed during the loading process to generate enhanced Java archive files. Then, during the official startup stage of the application, use the enhanced Java archive to directly launch the application to avoid the bytecode enhancement operation again.
While ensuring the bytecode enhancement effect of application, it significantly shortens the startup time of Java applications, improves the efficiency of service deployment and the timeliness of service expansion.
Smart Images

Figure CN2024092511_27032025_PF_FP_ABST
Abstract
Description
Application running method, node and computing device cluster
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on September 19, 2023, with application number 202311211237.X and application name “A Bytecode Enhanced Startup Acceleration Method and Device”, and the Chinese patent application filed with the State Intellectual Property Office of China on November 14, 2023, with application number 202311514763.3 and application name “Application Running Method, Node and Computing Device Cluster”, all contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to an application running method, a node, and a computing device cluster. Background Art
[0003] Bytecode enhancement is a technique that modifies the bytecode of a Java application during startup and runtime to enhance its functionality. Bytecode enhancement can enhance Java application functionality without modifying the application's source code, thus preventing damage to the source code during maintenance and upgrades.
[0004] During the startup process of Java applications, the implementation of bytecode enhancement technology prolongs the startup time of Java applications, resulting in the Java applications not being able to run in a timely manner.
[0005] Summary of the Invention
[0006] The embodiments of the present application provide an application running method, node, and computing device cluster, which can ensure the bytecode enhancement effect of the application while avoiding or reducing the impact of bytecode enhancement on the startup time of the application, so that the application can run in a timely manner, thereby achieving timely expansion or efficient deployment of services.
[0007] In a first aspect, a method for running an application is provided, which is applied to a microservice architecture, the microservice architecture including a first container group, and the microservice architecture storing a first Java archive file of the application. The method comprises: a first container in the first container group loads bytecode from the first Java archive file to obtain a second Java archive file of the application; wherein the second Java archive file includes first bytecode of a class to be enhanced of the application, and the first container runs a first enhancement component; the first bytecode is obtained by the first enhancement component modifying the bytecode of the class to be enhanced in the first Java archive file during the process of the first container loading the bytecode from the first Java archive file; a second container in the first container group loads the bytecode from the second Java archive file to obtain a first loading result; the first loading result includes a first object of the class to be enhanced, the first object being created by the second container based on the first bytecode during the process of the second container loading the bytecode from the second Java archive file; and the second container runs the application based on the first loading result. The application is a Java application.
[0008] In a microservices architecture, a container acts as a service instance within a container group, providing one or more services. Specifically, the container runs the application, which enables the container to provide the corresponding service. In other words, a container is not inherently a service instance; rather, it becomes a service instance after the container is created and the application is started and running.
[0009] In the method provided in an embodiment of the present application, when a service needs to be deployed in a container group, the first container in the container group can, while loading the Java archive file of the application corresponding to the service (i.e., the first Java archive file), perform bytecode enhancement on the Java archive file of the application, and include the enhanced bytecode in the Java archive file of the application to obtain an enhanced Java archive file (i.e., the second Java archive file). Then, the second container in the container group can start the application in the second container by loading the enhanced Java archive file.
[0010] The enhanced Java archive file includes enhanced bytecode. Therefore, when the second container loads the enhanced Java archive file, it can achieve the bytecode enhancement effect of the application without performing bytecode enhancement operations. This also reduces the application startup time and enables rapid startup of the application in the second container, thereby improving the service deployment efficiency in the container group, allowing the container group to provide services in a timely manner and respond to business needs. In particular, in the scenario of service expansion, newly created containers in the container group can quickly start and run applications by loading the enhanced Java archive file, ensuring timely service expansion.
[0011] In one possible implementation, the second container runs a second enhancement component, the second Java archive file includes a manifest, and the manifest includes an identifier of a class to be enhanced; the second container loads the bytecode in the second Java archive file, including: the second container obtains the manifest from the second Java archive file, wherein, during the process of the second container loading the bytecode in the second Java archive file, the manifest is used to indicate that the modification operation on the first bytecode has been completed.
[0012] In this implementation, the manifest in the second Java archive file indicates that the modification operation of the first bytecode has been completed. In this way, when the second container loads the second Java archive file, the second enhancement component in the second container can ignore the class represented by the identifier on the manifest and no longer identify the class represented by the identifier on the manifest, saving identification time and further reducing the startup time of the application.
[0013] In one possible implementation, the microservice architecture further includes a second container group, and the method further includes: a third container in the second container group loads the bytecode in the second Java archive file to obtain a second loading result; and the third container runs the application based on the second loading result.
[0014] In this implementation, when the service provided by the first container group fails to meet business needs and service expansion is required, the service can be deployed in another container group, such as the second container group. Deploying the service in the second container group requires the containers in the second container group to start and run the application corresponding to the service. The containers in the second container group can load the application's enhanced Java archive file (i.e., the second Java archive file) to quickly start and run the application, thereby rapidly providing the service and ensuring timely service expansion.
[0015] In one possible implementation, the microservice architecture further includes a management platform, and the method further includes: the management platform modifies the acquisition address of the Java archive file from the storage address of the first Java archive file to the storage address of the second Java archive file; the second container loads the bytecode in the second Java archive file, including: the second container obtains the second Java archive file based on the acquisition address.
[0016] In this implementation method, the address used by the container to obtain the Java archive file can be modified to the storage address of the enhanced Java archive file through the management platform. As a result, when the container needs to start the application, it obtains the enhanced Java archive file based on this address, and then can start the application by loading the enhanced Java archive file.
[0017] In a possible implementation, the method further includes: when an exception occurs when the second container runs the application based on the first loading result, the second container loads the first Java archive file to obtain a third loading result; and the second container runs the application based on the third loading result.
[0018] In this implementation, when an exception occurs when the container runs an application, the container can start and run the application by loading the original Java archive file (i.e., the first Java archive file) to ensure that the application can run normally, thereby ensuring the stability of the service.
[0019] In one possible implementation, the first container is the first container in the microservice architecture to load the first Java archive file.
[0020] In this implementation, when the Java archive file of an application (specifically the first Java archive file) is loaded for the first time, an enhanced Java archive file of the application is generated, so that the container that subsequently starts the application can start the application by loading the enhanced Java archive file, thereby improving the efficiency of deploying the service corresponding to the application in the microservice architecture.
[0021] In a second aspect, a node for running a container group is provided, wherein the node runs a first container group and stores a first Java archive file of an application; the first container in the first container group is used to: load the bytecode in the first Java archive file to obtain a second Java archive file of the application; wherein the second Java archive file includes the first bytecode of the class to be enhanced of the application, and the first container runs a first enhancement component; the first bytecode is obtained by the first enhancement component modifying the bytecode of the class to be enhanced in the first Java archive file during the process of the first container loading the bytecode in the first Java archive file; the second container in the first container group is used to: load the bytecode in the second Java archive file to obtain a first loading result; the first loading result includes a first object of the class to be enhanced, and the first object is created by the second container based on the first bytecode during the process of the second container loading the bytecode in the second Java archive file; the second container is also used to: run the application based on the first loading result.
[0022] In one possible implementation, the second container runs a second enhancement component, the second Java archive file includes a manifest, and the manifest includes an identifier of the class to be enhanced; the second container is further used to: obtain the manifest from the second Java archive file, wherein, during the process of the second container loading the bytecode in the second Java archive file, the manifest is used to indicate that the modification operation on the first bytecode has been completed.
[0023] In a possible implementation, the node further runs a second container group, wherein a third container in the second container group is used to: load bytecode in the second Java archive file to obtain a second loading result; and run the application based on the second loading result.
[0024] In one possible implementation, the node is connected to a management platform, and the management platform is used to: modify the acquisition address of the Java archive file from the storage address of the first Java archive file to the storage address of the second Java archive file; wherein the second container is used to: obtain the second Java archive file based on the acquisition address.
[0025] In a possible implementation, the second container is further configured to: when an exception occurs while the second container is running the application based on the first loading result, load the first Java archive file to obtain a third loading result; and run the application based on the third loading result.
[0026] In a possible implementation, the first container is a first container in the node that loads the first Java archive file.
[0027] In a third aspect, a computing device cluster is provided, comprising at least one computing device, each computing device comprising a processor and a memory; the processor of at least one computing device is used to execute instructions stored in the memory of at least one computing device, so that the computing device cluster performs the method provided in the first aspect.
[0028] In a fourth aspect, a computer-readable storage medium is provided, comprising computer program instructions. When the computer program instructions are executed by a computing device cluster, the computing device cluster executes the method provided in the first aspect.
[0029] In a fifth aspect, a computer program product comprising instructions is provided. When the instructions are executed by a computer device cluster, the computer device cluster executes the method provided in the first aspect.
[0030] The beneficial effects of the second to fifth aspects can be referred to the above introduction to the beneficial effects of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] FIG1 is a schematic diagram of the structure of a microservice architecture provided in an embodiment of the present application;
[0032] FIG2 is a flow chart of a method for running an application program provided in an embodiment of the present application;
[0033] FIG3 is a schematic diagram of a method for running an application program according to an embodiment of the present application;
[0034] FIG4 is a schematic diagram of a method for running an application program according to an embodiment of the present application;
[0035] FIG5 is a schematic diagram of a node provided in an embodiment of the present application;
[0036] FIG6 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application;
[0037] FIG7 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application;
[0038] FIG8 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application. DETAILED DESCRIPTION
[0039] The following describes the solutions provided by the embodiments of the present application in conjunction with the accompanying drawings. In the embodiments of the present application, "plurality" refers to two or more, and "multiple" refers to two or more. Terms such as "first" and "second" are used only to distinguish similar objects and do not necessarily describe a specific order or quantity of objects.
[0040] To facilitate understanding of the solutions provided by the embodiments of the present application, the technical terms that may be involved in the embodiments of the present application are first introduced.
[0041] Microservices architecture: A service-oriented architecture (SOA) that divides complex systems into multiple small services or applications. These small services or applications are called microservices. Each microservice is responsible for implementing an independent business logic. Microservices are built around business functions and can be deployed independently. Microservices rely on each other to provide a range of functions. Microservices are easy to understand and modify, which brings flexibility in language and framework selection. Microservices can run in containers. Containers containing multiple microservices with high interdependencies can form a container group. In the K8S (Kubernetes) system, container groups can be encapsulated into pods.
[0042] Container: A virtual computing instance, part of kernel virtualization technology, used to isolate processes and resources. Containers and virtual machines (VMs) share similar resource isolation and allocation methods. However, compared to VMs, containers virtualize the operating system rather than the hardware, making them more portable and efficient.
[0043] Business container: also known as user container, refers to the container where the microservice is located, that is, the container that runs the application used to provide the microservice.
[0044] Service grid: A technology that manages services for business containers through data proxies outside the business containers. In the service grid, the data proxies receive data packets sent by the business containers and perform service management (such as traffic management) on the data packets.
[0045] A sidecar is a data agent injected into a container group to manage the services of the business containers within that group. A sidecar can be implemented as a container or a process. When implemented as a container, the sidecar is also called a sidecar container.
[0046] Bytecode: Also known as a bytecode file, it is a binary file that contains an executable program and consists of a sequence of operation (op) code / data pairs. Bytecode is an intermediate binary file compiled from source code and is more abstract than machine code.
[0047] Bytecode enhancement: A technique that modifies the bytecode of a Java application during startup and runtime to enhance its functionality. Bytecode enhancement is commonly used in scenarios such as aspect-oriented programming (AOP) and dynamic proxies. Bytecode enhancement can be implemented using Java bytecode manipulation libraries such as ByteBuddy and Javassist. These libraries provide application programming interfaces (APIs) that allow developers to modify the bytecode of a Java application while it is running, thereby enhancing its functionality. Bytecode enhancement can enhance Java applications without modifying the source code. This avoids damage to the original Java application code (i.e., source code) and facilitates maintenance and upgrades. Common bytecode enhancement techniques include method interception, field injection, and class enhancement. These techniques can be used to implement logging, performance monitoring, transaction management, security control, and other functions.
[0048] Java Virtual Machine (JVM): The Java runtime for executing Java code. Designed to achieve the "compile once, run anywhere" principle, Java code is compiled into bytecode, a format that is easily distributed but cannot be run directly. The bytecode is then interpreted or compiled by the Java Virtual Machine, which also supports operations such as class loading and garbage collection.
[0049] Java applications are applications developed using Java. Java applications correspond to one or more services, and containers in a microservices architecture provide these services by running Java applications. In the following descriptions, Java applications are referred to simply as applications.
[0050] Java class: can be referred to as class for short. It is the basic unit of Java application code, used to describe Java objects. It contains a series of fields that define data and methods that define operations. It is a template for Java objects.
[0051] Java object: A data structure that contains a series of data and a series of methods for operating the data. Each Java object is a specific instance of the corresponding Java class.
[0052] Java heap: A memory space in the JVM used to store Java objects. All Java objects will logically be allocated in the Java heap.
[0053] Java archive (JAR) file: Also known as a JAR package, this is a software package file format that contains the bytecode of a Java application, associated metadata, and resource files (such as text and images). The bytecode of a Java application consists of the bytecode of its classes. A Java application is launched by loading its Java archive file. A Java archive file can contain multiple subpackages, each of which can contain one or more classes.
[0054] JavaAgent: Also known as an enhancement component, it is a new feature introduced after Java Development Kit (JDK) 1.5. It is used to implement bytecode enhancement. Specifically, JavaAgent allows developers to modify the bytecode after the JVM reads the bytecode file into memory and before using the class bytecode to generate Java objects in the Java heap. This allows the JVM to use the modified bytecode to generate Java objects in the Java heap, thereby achieving non-invasive business logic modification and replacement of Java applications. JavaAgent is a special Java program that is an instrumentation client. Unlike ordinary Java programs that are started through the main method, JavaAgent is not a program that can be started independently. It is usually attached to the JVM, running in the same process as the JVM, and interacting with the JVM through the instrumentation API.
[0055] Enhanced classes: These are classes that require bytecode enhancement during the startup or runtime of a Java application. Before generating objects of these classes, you must perform bytecode enhancement on the bytecodes of these classes.
[0056] Enhanced Java archive files: These are Java archive files whose bytecodes of classes requiring enhancement have been modified by enhancement components. These classes requiring enhancement are classes that require bytecode enhancement during the Java application startup process.
[0057] Original Java archive file: refers to a Java archive file whose bytecodes of the included classes have not been modified by the enhancement component. The original Java archive file can be the original Java archive file obtained by compiling the source code of the Java application.
[0058] During the loading process of the Java archive file of the Java application (i.e., the startup process of the Java application), bytecode enhancement identifies the class to be enhanced and modifies (e.g., converts, reconverts, etc.) the bytecode of the class to be enhanced to enhance the class to be enhanced. Identifying the class to be enhanced and modifying the bytecode of the class to be enhanced are both time-consuming, resulting in an increase in the startup time of the Java application. Typically, it will cause the startup time of the Java application to increase by at least 30%. Moreover, the higher the complexity of the Java application, the more the startup time of the Java application increases. Among them, loading the Java archive file specifically means loading the bytecode in the Java archive file.
[0059] In a microservices architecture, timely service expansion is necessary to handle sudden service requests. Service expansion requires more containers to run the Java applications that provide these services. To ensure timely service expansion, Java applications must be quickly started in newly created containers. However, bytecode enhancement increases Java application startup time, hindering timely service expansion.
[0060] In one solution, whenever a Java archive file of a Java application is loaded, the package names of the subpackages containing the classes in the Java archive file are analyzed, some subpackages are filtered out, and the classes that need to be enhanced are identified in the remaining subpackages, and the bytecodes of the classes that need to be enhanced are modified. This solution can identify classes that need to be enhanced within a smaller scope, reducing the time spent on identifying classes that need to be enhanced. However, this solution still needs to identify classes that need to be enhanced and modify the bytecodes of classes that need to be enhanced when starting a Java application, which still increases the startup time of the Java application. Furthermore, this solution needs to analyze the package names of the subpackages in advance each time a Java application is loaded, which is a cumbersome operation. Moreover, when the package names of the subpackages containing the classes that need to be enhanced and the subpackages containing the classes that do not need to be enhanced are the same, the subpackages that are filtered out are limited, thereby reducing the time spent on identifying classes that need to be enhanced.
[0061] In another solution, bytecode enhancement is not performed during the process of loading the Java application's Java archive file, that is, during the process of starting the Java application, to avoid the impact of bytecode enhancement on the Java application's startup time. Since this solution cannot enhance the classes used during the Java application startup process, it has significant limitations and cannot fully utilize the benefits of bytecode enhancement.
[0062] An embodiment of the present application provides a method for running an application. The method can be applied to a microservice architecture to achieve timely expansion or efficient deployment of services. Specifically, the method can be divided into a pre-enhancement stage and an application formal startup stage. The pre-enhancement stage can be a preparatory stage before the service is formally deployed, or it can be a stage where the service is first deployed. The service is a service provided by a container by running an application. In the pre-enhancement stage, the bytecode in the Java archive file of a Java application is loaded in a container to start the Java application in the container. When loading the bytecode in the Java archive file of the Java application, the enhancement component running in the container modifies the bytecode of the class to be enhanced in the Java archive file (that is, the bytecode enhancement is performed on the class to be enhanced) to obtain an updated Java archive file. The updated Java archive file is used as an enhanced Java archive file. In the application formal startup stage (for example, formal deployment of the service or expansion of the service), the enhanced Java archive file is loaded in the container to start the Java application. The bytecode of the classes to be enhanced in the enhanced Java archive file has been modified by the enhancement component. Therefore, when loading the enhanced Java archive file to start a Java application, there is no need to identify the classes to be enhanced and modify their bytecode. This ensures that the classes used during the Java application startup process are bytecode enhanced while also shortening the Java application startup time. This allows Java applications to start quickly in the container during formal service deployment or service expansion, ensuring efficient service deployment or timely service expansion.
[0063] Next, the application running method provided in the embodiment of the present application is described in detail.
[0064] FIG1 shows a microservice architecture 100 provided in an embodiment of the present application. As shown in FIG1 , the microservice architecture 100 includes a management platform 110 , multiple container groups, and a warehouse 140 .
[0065] Among them, multiple container groups may include container group 120, container group 130, etc. The container group may include multiple containers. For example, container group 120 may include enhanced container 121, business container 122, and sidecar container 123. For another example, container group 130 may include business container 131, business container 132, and sidecar container 133. Among them, the enhanced container, also known as the bytecode enhancement container, refers to the container used to load the original Java archive file of the Java application, and during the loading process, modifies the bytecode of the class to be enhanced in the original Java archive file to obtain the enhanced Java archive file. The enhanced container belongs to the initialization container (init container) in the container group, and the enhanced container is started before the business container in the container group. The container group may also include a storage module, which is shared by the containers in the container group, that is, different containers in the container group can store and read data in the storage module of the container group.
[0066] The controller platform 110 is used to create and manage container groups, for example, to create a container group, create containers in a container group, and manage the lifecycle of a container or container group.
[0067] As shown in Figure 1, the management platform 110 may include a container creation module 111 and a container injection module 112. The container creation module 111 can receive user operations and create a container group based on the user operations. The container creation module 111 can inject containers into the container group through the container injection module 112 based on the user operations to achieve container creation. In one example, a user can write a YAML file for creating a container group or container. YAML is a markup language and a format for expressing data serialization. The container creation module 111 can receive the YAML file and create a container group or container based on the YAML file. In one example, the container creation module 111 can be implemented as a k8s application programming interface server (API server). The container injection module 112 can be used to inject business containers and sidecar containers into the container group. The container injection module 112 can also act as an enhanced container injector (bytecode enhancement container injector) to inject enhanced containers 121 into the container group 120.
[0068] In some embodiments, the management platform 110 may further include a configuration module 113. The configuration module 113 may configure an address for obtaining a Java archive file of a Java application. This address is used by a container in the microservice architecture 100 to obtain the Java archive file of the Java application, so that the container can load the bytecode in the Java archive file and run the Java application.
[0069] Warehouse 140, also known as a mirroring warehouse, is used to store data. Warehouse 140 can serve as a Java archive file warehouse for storing Java archive files of Java applications. Specifically, warehouse 140 can store original Java archive files and enhanced Java archive files of Java applications. Warehouse 140 can also be used to store enhanced components. Warehouse 140 is shared by container groups in microservice architecture 100, meaning that containers in different container groups in microservice architecture 100 can store and read data in warehouse 140.
[0070] The above example introduces the microservice architecture 100 provided in the embodiment of the present application. Next, in conjunction with the microservice architecture 100, the application running method provided in the embodiment of the present application is introduced. Among them, the method can be executed by the management platform 110. As shown in Figure 2, the method includes the following steps.
[0071] In step 201, the enhanced container 121 in the container group 120 loads the bytecode from the original Java archive file of the Java application A1 to obtain an enhanced Java archive file of the Java application A1. The enhanced container 121 runs a JVM, and the original Java archive file of the Java application A1 is loaded into the JVM. In this embodiment of the present application, loading the bytecode from the Java archive file can be referred to as simply loading the Java archive file.
[0072] Loading the bytecode in the Java archive file of a Java application can be understood as the process of starting a Java application. During the process of loading the bytecode in the Java archive file of a Java application, class objects for running the Java application are generated. After loading is complete, these class objects can be used to run the Java application.
[0073] Before executing step 201, the original Java archive file of Java application A1 can be stored in the microservice architecture 100, for example, in the repository 140. For example, as shown in FIG3 , in step 301a, the management platform 110 can compile the source code of Java application A1 to obtain the original Java archive file of Java application A1. The management platform 110 can then store the original Java archive file in the repository 140.
[0074] The management platform 110 can configure an acquisition address for the Java archive file, which is used by the container to obtain the Java archive file. The management platform 110 can configure the acquisition address to be the storage address of the original Java archive file of Java application A1. The enhanced container 121 can obtain the acquisition address and, based on the acquisition address, obtain the original Java archive file of Java application A1. In step 302a, the enhanced container 121 can obtain the original Java archive file of Java application A1 based on the acquisition address. After the enhanced container 121 obtains the original Java archive file of Java application A1, the enhanced container 121 can load the bytecode in the original Java archive file of Java application A1.
[0075] When or before the enhanced container 121 starts loading the bytecodes in the original Java archive file of the Java application A1, the enhanced container 121 may start running the enhanced component. The running of the enhanced component and the loading of the original Java archive file of the Java application A1 are performed in the same JVM.
[0076] In some embodiments, referring to FIG. 3 , in step 301b , the management platform 110 may configure the enhancement component, for example, configuring the enhancement logic of the enhancement component. The management platform 110 may configure the enhancement component in response to a user's configuration operation. The management platform 110 may store the enhancement component in the repository 140 . The sidecar container 123 in the container group 130 may obtain the enhancement component from the repository 140 and store it in a storage module of the container group 130 . The enhancement container 121 may obtain the enhancement component from the storage module and run the enhancement component in step 302b .
[0077] As shown in Figure 3, step 201 includes step 303, where the enhanced container 121 loads the bytecodes in the original Java archive file of the Java application A1. While loading the bytecodes in the original Java archive file of the Java application A1, the enhanced container 121 also runs the enhanced component.
[0078] During the loading of the bytecode in the original Java archive file of Java application A1, the enhancement component can identify the classes to be enhanced in the original Java archive file and perform bytecode enhancement on the identified classes to be enhanced. Specifically, before generating objects of the classes to be enhanced, the enhancement component modifies the bytecode of the classes to be enhanced according to its bytecode enhancement logic. The enhancement container 121 can use the modified bytecode to replace the bytecode of the classes to be enhanced in the original Java archive file (i.e., the bytecode before modification), thereby obtaining an enhanced Java archive file for Java application A1. In other words, compared to the original Java archive file, the bytecode of the classes to be enhanced in the enhanced Java archive file is the bytecode modified by the enhancement component according to the bytecode enhancement logic. More specifically, the bytecode of the classes to be enhanced in the original Java archive file can be set to bytecode B1, and the modified bytecode can be set to bytecode B2. Then, when the enhancement container 121 loads the bytecode in the original Java archive file, the enhancement component running in the enhancement container 121 modifies bytecode B1 in the original Java archive file to bytecode B2, thereby obtaining an enhanced Java archive file for Java application A1. The classes to be enhanced of the Java application A1 herein refer to classes that require bytecode enhancement during the startup process of the Java application A1.
[0079] In some embodiments, the enhanced container 121 can add a tag to the enhanced Java archive file, wherein the tag indicates that the Java archive file where the tag is located is an enhanced Java archive file.
[0080] In some embodiments, the enhancement container 121 may add the identifier of the class to be enhanced to a list and include the list in the enhanced Java archive file, wherein the identifier of the class may be the class name.
[0081] The enhanced container 121 can store the enhanced Java archive file in the microservice architecture 100. In some embodiments, as described above, the microservice architecture 100 includes a repository 140. As shown in Figure 3, at step 304, the enhanced container 121 can store the enhanced Java archive file in the repository 140.
[0082] Among them, the microservice architecture 100 still retains the original JAR. That is, the enhanced JAR does not replace the original JAR, and both the enhanced JAR and the original JAR are stored in the microservice architecture 100 (e.g., warehouse 140).
[0083] In some embodiments, after the enhanced Java archive file is stored, for example, after the enhanced Java archive file is stored in the repository 140, the management platform 140 may redirect the address for obtaining the Java archive file. Specifically, the address for obtaining the Java archive file may be redirected from the storage address of the original Java archive file to the storage address of the enhanced Java archive file, that is, the address for obtaining the Java archive file may be modified from the storage address of the original Java archive file to the storage address of the enhanced Java archive file.
[0084] In some embodiments, the enhanced container 121 is the first container in the microservice architecture 100 to start the Java application A1, that is, the first container to load the JAR file of the Java application A1. As described above, the JAR file of the Java application A1 loaded by the enhanced container 121 is specifically the original JAR file of the Java application A1.
[0085] As described above, the application running method provided in the embodiment of the present application is divided into a pre-enhancement phase and an application formal startup phase. Step 201 belongs to the pre-enhancement phase. In one example, the pre-enhancement phase can be a preparatory phase before service deployment. That is, in this example, the enhanced container 121 is not used to run the Java application A1, but is only used to generate an enhanced Java archive file for the Java application A1. Therefore, in this example, after the enhanced container 121 generates the enhanced Java archive file for the Java application A1, the lifecycle of the enhanced container 121 ends. That is, after the enhanced container 121 generates the enhanced Java archive file for the Java application A1, the enhanced container 121 can be deleted. In one example, the pre-enhancement phase can be a service deployment phase before service expansion. In this example, the enhanced container 121 also serves as a business container. After loading the original Java archive file of the Java application A1, that is, after starting the Java application A1, the Java application A1 is run to provide services. In this example, the enhanced container 121 is the first container in the microservice architecture 100 to load the Java archive file (specifically, the original Java archive file) of the Java application A1 and run the Java application A1.
[0086] 2 , in step 202 , the business container 122 in the container group 120 loads the enhanced Java archive file of the Java application A1 to obtain a loading result C1 . The business container 122 runs a JVM, and the enhanced Java archive file of the Java application A1 is loaded into the JVM.
[0087] In some embodiments, the enhanced Java archive file of Java application A1 is stored in the warehouse 140, and the business container 122 can obtain the enhanced Java archive file of Java application A1 from the warehouse 140. As shown in FIG4 , in step 401a, the business container 122 obtains the enhanced Java archive file from the warehouse 140.
[0088] In some embodiments, as described above, the management platform 110 may modify the address for obtaining the Java archive file of Java application A1 from the storage address of the original Java archive file of Java application A1 to the storage address of the enhanced Java archive file of Java application A1. The service container 122 may obtain the Java archive file based on the modified address, thereby obtaining the enhanced Java archive file of Java application A1.
[0089] After obtaining the enhanced Java archive file of Java application A1, the business container 122 can load the bytecode in the enhanced Java archive file of Java application A1 to start Java application A1. The bytecode of the class to be enhanced in the enhanced Java archive file is the bytecode modified by the enhancement component according to the enhancement logic. Therefore, when the business container 122 loads the bytecode in the enhanced Java archive file, there is no need to perform an enhancement operation on the bytecode of the class to be enhanced. The bytecode enhancement operation is also called the bytecode modification operation, which refers to the operation of modifying the bytecode according to the bytecode enhancement logic. That is to say, when the business container 122 loads the bytecode in the enhanced Java archive file, it can directly generate an object of the class to be enhanced based on the bytecode of the class to be enhanced in the enhanced Java archive file. More specifically, as described above, the bytecode of the class to be enhanced in the enhanced Java archive file is bytecode B2. When the business container 122 loads the bytecode in the enhanced Java archive file, it generates an object of the class to be enhanced based on bytecode B2. In this way, the business container loads the bytecode in the enhanced Java archive file without performing bytecode enhancement operations on the classes to be enhanced. This ensures the bytecode enhancement effect while reducing the startup time of the Java application.
[0090] The service container 122 may include the object of the class to be enhanced generated when loading the bytecode in the enhanced Java archive file into the loading result C1.
[0091] When the service container 122 completes loading the bytecode in the enhanced Java archive file, it obtains a loading result C1 containing the bytecode required for the service container 122 to run the Java application A1. In step 203, the service container 122 runs the Java application A1 based on the loading result C1 to provide services.
[0092] In some embodiments, bytecode enhancement is dynamically woven in, and during the runtime after the Java application is started, there are still classes that need bytecode enhancement. In order to be able to perform bytecode enhancement on the classes of the Java application during the runtime after the Java application is started, as shown in step 403 in Figure 4, the business container 122 runs the enhancement component while running the Java application. The business container 122 can start running the enhancement component before or when the business container 122 starts loading the bytecode in the enhanced Java archive file of the Java application A1. The running of the enhancement component and the loading of the enhanced Java archive file of the Java application A1 are performed in the same JVM.
[0093] In one example, as described above, the enhancement component has been stored in the sidecar container 123 and in the storage module of the container group 120. Referring to Figure 4 , in step 401b, the business container 122 retrieves the enhancement component from the storage module. As shown in Figure 4 , step 202 includes step 402 , in which the business container 122 loads the bytecode from the enhanced Java archive file of the Java application A1. While loading the bytecode from the enhanced Java archive file of the Java application A1, the business container 122 also runs the enhancement component.
[0094] In one example, an enhanced Java archive file contains a manifest that includes identifiers of classes to be enhanced. The manifest indicates that the modification operation of the bytecode of the class corresponding to the identifier in the manifest (e.g., the class to be enhanced) has been completed, that is, the manifest is used to indicate that the modification operation of the bytecode of the class to be enhanced has been completed. The business container 122 can obtain the manifest from the enhanced Java archive file. During the process of the business container 122 loading the bytecode in the enhanced Java archive file, the enhancement component run by the business container 122 can ignore the modification operation of the bytecode of the class to be enhanced based on the manifest. The modification operation here is also called the enhancement operation, which refers to the modification operation performed on the bytecode according to the bytecode enhancement logic. More specifically, when the enhancement component identifies the class to be enhanced from the enhanced Java archive file, it can ignore the class represented by the identifier on the manifest and no longer identify the class represented by the identifier on the manifest. Therefore, through this manifest, the time consumed by the enhancement component in identifying the bytecode in the Java archive file when the business container loads it can be saved, further reducing the startup time of the Java application.
[0095] In some embodiments, after step 203, the running status of the Java application A1 run by the business container 122 can be observed, that is, the running status of the Java application A1 run by the business container 122 based on the loading result C1 can be observed. If the running status of the Java application A1 run by the business container 122 based on the loading result C1 is abnormal, the business container 122 can load the original Java archive file of the Java application A1 to obtain the loading result C2. Then, the business container 122 can run the Java application A1 based on the loading result C2. That is, in this embodiment, when the business container runs the Java application by loading the enhanced Java archive file and an abnormality occurs, the business container can run the Java application by loading the original Java archive file to ensure that the Java application can run normally.
[0096] In some embodiments, when deploying services provided by Java application A1 to a container group other than container group 120 (e.g., container group 130), Java application A1 can also be launched using its enhanced Java archive file to improve service deployment efficiency or the timeliness of service expansion. The following describes launching Java application A1 in business container 131 in container group 130 as an example.
[0097] The service container 131 may obtain the loading result C3 by reading the bytecode in the enhanced Java archive file of the Java application A1.
[0098] The business container 131 can obtain the enhanced Java archive file of the Java application A1, for example, from the repository 140, and then load the enhanced Java archive file of the Java application A1. For details, please refer to the above description of the business container 122 obtaining the enhanced Java archive file.
[0099] After obtaining the enhanced Java archive file of Java application A1, business container 131 can load the bytecode in the enhanced Java archive file of Java application A1 to start Java application A1. When loading the bytecode in the enhanced Java archive file, business container 131 can directly generate an object of the class to be enhanced based on the bytecode of the class to be enhanced in the enhanced Java archive file. That is, when business container 131 loads the bytecode in the enhanced Java archive file, business container 131 generates an object of the class to be enhanced based on bytecode B2. In this way, business container 131 loads the bytecode in the enhanced Java archive file without performing bytecode enhancement operations on the class to be enhanced. While ensuring the bytecode enhancement effect of Java application A1, it reduces the startup time of Java application A1.
[0100] The service container 131 can include the objects of the classes to be enhanced, generated during the process of loading the bytecode from the enhanced Java archive file, in the loading result C3. Upon completing the loading of the bytecode from the enhanced Java archive file, the service container 131 obtains the loading result C3 containing the data required for the service container 131 to run the Java application A1. The service container 131 can then run the Java application A1 based on the loading result C3 to provide services.
[0101] In summary, the embodiment of the present application provides an application running method, which can generate an enhanced Java archive file of the application, and the bytecode of the class to be enhanced in the enhanced Java archive file has been bytecode enhanced; when performing service deployment or service expansion in a microservice architecture, the container used for service deployment or service expansion can start the application by loading the enhanced Java archive file of the application. Among them, in the process of loading the enhanced Java archive file, there is no need to perform bytecode enhancement operations, thereby reducing the startup time and improving the efficiency of service deployment or the timeliness of service expansion. Moreover, the bytecode of the class to be enhanced in the enhanced Java archive file has been bytecode enhanced, so by loading the enhanced Java archive file of the application and starting the application, the effect of bytecode enhancement can be guaranteed. In short, the application running method provided by the embodiment of the present application reduces the startup time of the application while ensuring the effect of bytecode enhancement of the application.
[0102] This embodiment of the present application provides a node 500 running a container group. As shown in FIG5 , the node 500 runs a container group 510, and the node 500 stores a first Java archive file of an application. The container group 510 includes a first container 511 and a second container 512.
[0103] The first container 511 is configured to load the bytecodes in the first Java archive file to obtain a second Java archive file of the application; wherein the second Java archive file includes the first bytecode of the class to be enhanced of the application, and the first container 511 runs a first enhancement component; the first bytecode is obtained by the first enhancement component modifying the bytecode of the class to be enhanced in the first Java archive file while the bytecodes in the first Java archive file are loaded by the first container 511;
[0104] The second container 512 is configured to load the bytecode in the second Java archive file to obtain a first loading result; the first loading result includes a first object of the class to be enhanced, the first object being created by the second container 512 based on the first bytecode during the process of the second container 512 loading the bytecode in the second Java archive file;
[0105] The second container 512 is further configured to run the application based on the first loading result.
[0106] In some embodiments, the second container 512 runs a second enhancement component, and the second Java archive file includes a manifest, which includes an identifier of the class to be enhanced; the second container 512 is further used to: obtain the manifest from the second Java archive file, wherein, during the process of the second container loading the bytecode in the second Java archive file, the manifest is used to indicate that the modification operation on the first bytecode has been completed.
[0107] In some embodiments, the node 500 further includes a container group 520 , wherein a third container 521 in the container group 520 is used to: load the bytecode in the second Java archive file to obtain a second loading result; and run the application based on the second loading result.
[0108] In some embodiments, the node 500 is connected to a management platform 530, and the management platform 530 is used to: modify the acquisition address of the Java archive file from the storage address of the first Java archive file to the storage address of the second Java archive file; wherein the second container 512 is used to: obtain the second Java archive file based on the acquisition address.
[0109] In some embodiments, the second container 512 is further used to: when an exception occurs when the second container 512 runs the application based on the first loading result, load the first Java archive file to obtain a third loading result; and run the application with the third loading result.
[0110] In some embodiments, the first container 511 is the first container in the node 500 to load the first Java archive file.
[0111] Among them, the functions of the containers in node 500 can be implemented by referring to the above introduction of the containers in the microservice architecture 100. For example, the functions of the first container 511 can also be implemented by referring to the above introduction of the enhanced container 121, and the functions of the second container 512 can also be implemented by referring to the above introduction of the business container 122, and so on.
[0112] This application also provides a computing device 600. As shown in Figure 6, computing device 600 includes a bus 602, a processor 604, a memory 606, and a communication interface 608. Processor 604, memory 606, and communication interface 608 communicate with each other via bus 602. Computing device 600 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in computing device 600.
[0113] Bus 602 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, among others. Buses may be classified as address buses, data buses, control buses, and the like. For ease of illustration, FIG6 shows a single bus line, but this does not imply a single bus or type of bus. Bus 602 may include a path for transmitting information between various components of computing device 600 (e.g., memory 606, processor 604, and communication interface 608).
[0114] The processor 604 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0115] The memory 606 may include volatile memory, such as random access memory (RAM). The memory 606 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).
[0116] Memory 606 stores executable program code, which processor 604 executes to implement the functions of first container 511 (or enhanced container 121) and second container 512 (or business container 122), respectively, thereby implementing the method shown in FIG2 . In other words, memory 606 stores instructions for executing the method shown in FIG2 .
[0117] The communication interface 608 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 600 and other devices or a communication network.
[0118] Embodiments of the present application also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0119] As shown in Figure 7 , the computing device cluster includes at least one computing device 600. The memory 606 in one or more computing devices 600 in the computing device cluster may store the same instructions for executing the method shown in Figure 2 .
[0120] In some possible implementations, the memory 606 of one or more computing devices 600 in the computing device cluster may also respectively store some instructions for executing the method shown in Figure 2. In other words, the combination of one or more computing devices 600 can jointly execute the instructions for executing the method shown in Figure 2.
[0121] It should be noted that the memory 606 in different computing devices 600 in the computing device cluster can store different instructions, each used to execute part of the functions of the node 500. In other words, the instructions stored in the memory 606 in different computing devices 600 can implement the functions of one or more containers among the first container 511 (or enhanced container 121) and the second container 512 (or business container 122).
[0122] In some possible implementations, one or more computing devices in a computing device cluster may be connected via a network. The network may be a wide area network (WAN) or a local area network (LAN), among others. FIG. 8 illustrates a possible implementation. As shown in FIG. 8 , two computing devices 600A and 600B are connected via a network. Specifically, the network is connected via a communication interface in each computing device. In this type of possible implementation, the memory 606 in the computing device 600A stores instructions for executing the functions of the first container 511 (or enhanced container 121). Simultaneously, the memory 606 in the computing device 600B stores instructions for executing the functions of the second container 512 (or business container 122).
[0123] It should be understood that the functionality of the computing device 600A shown in FIG8 may also be implemented by multiple computing devices 600. Similarly, the functionality of the computing device 600B may also be implemented by multiple computing devices 600.
[0124] The present application also provides another computing device cluster. The connection relationship between the computing devices in this computing device cluster can be similar to the connection method of the computing device cluster described in Figures 7 and 8. However, the memory 606 in one or more computing devices 600 in this computing device cluster can store the same instructions for executing the method shown in Figure 2.
[0125] In some possible implementations, the memory 606 of one or more computing devices 600 in the computing device cluster may also respectively store some instructions for executing the method shown in Figure 2. In other words, the combination of one or more computing devices 600 can jointly execute the instructions for executing the method shown in Figure 2.
[0126] The present application also provides a computer program product comprising instructions. The computer program product may be software or a program product comprising instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the method shown in FIG2 .
[0127] The present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device, or a host migration device such as a data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the method shown in FIG. 2 .
[0128] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the protection scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for running an application, characterized in that: Applied to a microservice architecture, the microservice architecture includes a first container group, and the microservice architecture stores a first Java archive file of an application program, the method includes: The first container in the first container group loads the bytecode in the first Java archive file to obtain a second Java archive file of the application; wherein the second Java archive file includes the first bytecode of the class to be enhanced of the application, and the first container runs a first enhancement component; the first bytecode is obtained by the first enhancement component modifying the bytecode of the class to be enhanced in the first Java archive file during the process of the first container loading the bytecode in the first Java archive file; The second container in the first container group loads the bytecode in the second Java archive file to obtain a first loading result; the first loading result includes a first object of the class to be enhanced, and the first object is created by the second container based on the first bytecode during the process of the second container loading the bytecode in the second Java archive file; The second container runs the application based on the first loading result.
2. The method according to claim 1, characterized in that The second container runs a second enhancement component, the second Java archive file includes a manifest, and the manifest includes an identifier of the class to be enhanced; The second container loads the bytecode in the second Java archive file, including: The second container obtains the manifest from the second Java archive file, wherein, during the process of the second container loading the bytecode in the second Java archive file, the manifest is used to indicate that a modification operation on the first bytecode has been completed.
3. The method according to claim 1 or 2, characterized in that: The microservice architecture further includes a second container group, and the method further includes: The third container in the second container group loads the bytecode in the second Java archive file to obtain a second loading result; The third container runs the application based on the second loading result.
4. The method according to any one of claims 1 to 3, characterized in that The microservice architecture further includes a management platform, and the method further includes: the management platform modifies the acquisition address of the Java archive file from the storage address of the first Java archive file to the storage address of the second Java archive file; The second container loads the bytecode in the second Java archive file, including: The second container obtains the second Java archive file based on the acquisition address.
5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: When an exception occurs when the second container runs the application based on the first loading result, the second container loads the first Java archive file to obtain a third loading result; The second container runs the application based on the third loading result.
6. The method according to any one of claims 1 to 5, characterized in that The first container is the first container in the microservice architecture to load the first Java archive file.
7. A node running a container group, characterized in that: The node runs a first container group, and the node stores a first Java archive file of an application; The first container in the first container group is used to: load the bytecode in the first Java archive file to obtain a second Java archive file of the application; wherein the second Java archive file includes the first bytecode of the class to be enhanced of the application, and the first container runs a first enhancement component; the first bytecode is obtained by the first enhancement component modifying the bytecode of the class to be enhanced in the first Java archive file during the process of the first container loading the bytecode in the first Java archive file; The second container in the first container group is used to: load the bytecode in the second Java archive file to obtain a first loading result; the first loading result includes a first object of the class to be enhanced, and the first object is created by the second container based on the first bytecode during the process of the second container loading the bytecode in the second Java archive file; The second container is further used to: run the application based on the first loading result.
8. The node according to claim 7, characterized in that: The second container runs a second enhancement component, the second Java archive file includes a manifest, and the manifest includes an identifier of the class to be enhanced; The second container is further used to obtain the manifest from the second Java archive file, wherein, during the process of the second container loading the bytecode in the second Java archive file, the manifest is used to indicate that the modification operation on the first bytecode has been completed.
9. The node according to claim 7 or 8, characterized in that: The node also runs a second container group, wherein a third container in the second container group is used for: Loading the bytecode in the second Java archive file to obtain a second loading result; Based on the second loading result, the application is run.
10. The node according to any one of claims 7 to 9, characterized in that: The node is connected to a management platform, and the management platform is used to: modify the acquisition address of the Java archive file from the storage address of the first Java archive file to the storage address of the second Java archive file; wherein, The second container is used to obtain the second Java archive file based on the acquisition address.
11. The node according to any one of claims 7 to 10, characterized in that: The second container is also used for: When an exception occurs when the second container runs the application based on the first loading result, the first Java archive file is loaded to obtain a third loading result; Based on the third loading result, the application is run.
12. The node according to any one of claims 7 to 11, characterized in that: The first container is the first container in the node that loads the first Java archive file.
13. A computing device cluster, characterized in that: comprising at least one computing device, each computing device comprising a processor and a memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the method according to any one of claims 1 to 6.
14. A computer-readable storage medium, characterized in that: The method comprises computer program instructions, and when the computer program instructions are executed by a computing device cluster, the computing device cluster performs the method according to any one of claims 1 to 6.
15. A computer program product comprising instructions, characterized in that When the instructions are executed by a computer device cluster, the computer device cluster executes the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Application program running method, node and computing device cluster
CN119668678A
Method, device and system for weaving byte code
CN101957766A
Processing method and device based on Java virtual machine and electronic equipment
CN114237819A
Method for loading emergency patch by initializing container
CN114995962A
Methods and Apparatus for Dynamic Class Reloading and Versioning
US20100199259A1
Cited By
Software supply chain risk component calling identification method
CN120951327A
A software supply chain risk component invocation identification method
CN120951327B