Application program running method, node and computing device cluster
By using enhancement containers in the microservice architecture to modify the bytecode of the Java application in advance, and generate enhanced Java archive files, the problem of bytecode enhancement extending the startup time is solved, and the application is quickly started and the service is expanded in a timely manner.
Patent Information
- Application Number
- CN202311514763.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-09-19
- Filing Date
- 2023-11-14
- Publication Date
- 2025-03-21
AI Technical Summary
Bytecode enhancement technology extends the startup time during the Java application startup process, resulting in the application not being able to run in time, affecting the timely expansion and efficient deployment of services.
By introducing enhancement containers into the microservice architecture, the original Java archive files of Java applications are loaded in advance, and the bytecode of the enhanced class is modified by enhancing components during the loading process to generate enhanced Java archive files. Then, during the official startup stage of the application, the container loads the enhanced Java archive file to avoid bytecode enhancement operations again, thereby shortening the startup time.
While ensuring the bytecode enhancement effect of application, it significantly reduces the startup time of Java applications, improves the efficiency of service deployment and the timeliness of service expansion.
Smart Images

Figure CN119668678A_ABST
Abstract
Description
Technical Field
[0001] 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
[0002] Bytecode enhancement technology is a technology that modifies the bytecode of a Java application when it is started and running to enhance the functionality of the Java application. Bytecode enhancement technology can enhance the functionality of a Java application without modifying the source code of the Java application, thereby avoiding damage to the source code when maintaining and upgrading the Java application.
[0003] During the startup process of a Java application, the bytecode enhancement technology is implemented, which prolongs the startup time of the Java application and causes the Java application to fail to run in time. Summary of the invention
[0004] The embodiments of the present application provide an application running method, node, and computing device cluster, which can avoid or reduce the impact of bytecode enhancement on the startup time of the application while ensuring the bytecode enhancement effect of the application, so that the application can run in a timely manner, thereby achieving timely expansion or efficient deployment of the service.
[0005] In a first aspect, a method for running an application is provided, which is applied to a microservice architecture, wherein the microservice architecture includes a first container group, and the microservice architecture stores a first Java archive file of the application, and the method includes: a 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; and the second container runs the application based on the first loading result. Wherein, the application refers to a Java application.
[0006] In the microservice architecture, a container is a service instance in a container group, used to provide one or more services. Specifically, the container runs the application, which enables the container to provide the corresponding service. In other words, the container is not a service instance by nature, but after the container is created, the container starts and runs the application and becomes a service instance.
[0007] In the method provided in the embodiment of the present application, when a service needs to be deployed in a container group, the first container in the container group can perform bytecode enhancement on the Java archive file of the application corresponding to the service (i.e., the first Java archive file), and include the enhanced bytecode into 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.
[0008] Among them, the enhanced Java archive file includes enhanced bytecode, so 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, and also reduce the startup time of the application, and achieve rapid startup of the application in the second container, thereby improving the service deployment efficiency in the container group, so that the container group can provide services in a timely manner and respond to business needs. In particular, in the scenario of service expansion, the newly created container in the container group can quickly start and run the application by loading the enhanced Java archive file, thereby achieving the timeliness of service expansion.
[0009] In a 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.
[0010] 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, thereby saving identification time and further reducing the startup time of the application.
[0011] In a 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.
[0012] In this implementation, when the service provided by the first container group is difficult to meet business needs and service expansion is required, the service can be deployed in other container groups such as the second container group. To deploy the service in the second container group, the container in the second container group needs to start and run the application corresponding to the service. Among them, the container in the second container group can load the enhanced Java archive file (i.e., the second Java archive file) of the application to quickly start and run the application, so that the service can be provided quickly, realizing the timeliness of service expansion.
[0013] In a possible implementation, the microservice architecture also includes a management platform, and the method also 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.
[0014] 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 the address, and then can start the application by loading the enhanced Java archive file.
[0015] 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.
[0016] 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.
[0017] In one possible implementation, the first container is the first container in the microservice architecture that loads the first Java archive file.
[0018] 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.
[0019] In a second aspect, a node running a container group is provided, wherein the node runs a first container group and stores a first Java archive file of an application; a first container in the first container group is used to: load bytecodes in the first Java archive file to obtain a second Java archive file of the application; wherein the second Java archive file includes a 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 modifying the bytecode of the class to be enhanced in the first Java archive file by the first enhancement component during the process of loading the bytecodes in the first Java archive file by the first container; a second container in the first container group is used to: load the bytecodes 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 loading the bytecodes in the second Java archive file by the second container; the second container is also used to: run the application based on the first loading result.
[0020] 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 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.
[0021] 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 the bytecode in the second Java archive file to obtain a second loading result; and run the application based on the second loading result.
[0022] In a 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: acquire the second Java archive file based on the acquisition address.
[0023] In a possible implementation, the second container is further used to: when an exception occurs when the second container 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 based on the third loading result.
[0024] In a possible implementation, the first container is a first container in the node that loads the first Java archive file.
[0025] 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 executes the method provided in the first aspect.
[0026] 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.
[0027] 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.
[0028] 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
[0029] Figure 1 A schematic diagram of the structure of a microservice architecture provided in an embodiment of the present application;
[0030] Figure 2 A flowchart of a method for running an application program provided in an embodiment of the present application;
[0031] Figure 3 A schematic diagram of a method for running an application program provided in an embodiment of the present application;
[0032] Figure 4 A schematic diagram of a method for running an application program provided in an embodiment of the present application;
[0033] Figure 5 A schematic diagram of a node provided in an embodiment of the present application;
[0034] Figure 6 A schematic diagram of the structure of a computing device provided in an embodiment of the present application;
[0035] Figure 7 A schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application;
[0036] Figure 8 A schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The scheme provided by the embodiment of the present application will be described below in conjunction with the accompanying drawings. In the embodiment of the present application, "multiple" means two or more, and "multiple" means two or more. "First", "second", etc. are only used to distinguish similar objects and are not necessarily used to describe a specific order or number of objects.
[0038] 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.
[0039] Microservice architecture: A service-oriented architecture (SOA) that divides a complex system into multiple small services or applications. The small service or application can be called a microservice. Each microservice is responsible for implementing an independent business logic. Microservices are built around business functions and can be deployed independently. Microservices are interdependent and can 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. Among them, the containers where multiple microservices with high interdependence are located can form a container group. Among them, in the K8S (kubernetes) system, the container group can be encapsulated into a pod.
[0040] Container: A virtual computing instance, a kernel virtualization technology used to isolate processes and resources. Containers and virtual machines (VMs) have similar resource isolation and allocation methods. Compared with virtual machines, containers virtualize the operating system instead of the hardware, making them more portable and efficient.
[0041] 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 microservices.
[0042] Service grid: A technology that manages services for business containers through data agents outside the business containers. In the service grid, the data agent obtains data packets sent by the business container and performs service management (such as traffic management) on the data packets.
[0043] Sidecar: A data agent injected into a container group for service management of business containers in the container group. A sidecar can be implemented through a container or a process. When a sidecar is implemented through a container, it is also called a sidecar container.
[0044] Bytecode: Also known as 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 that is compiled from source code and is more abstract than machine code.
[0045] Bytecode enhancement: A technology that modifies the bytecode of a Java application when it is started and running to enhance the functionality of the Java application. Bytecode enhancement is usually used in scenarios such as aspect-oriented programming (AOP) and dynamic proxy. Bytecode enhancement can be implemented through Java bytecode manipulation libraries (such as ByteBuddy, Javassist, etc.). These libraries provide some application programming interfaces (APIs) that allow developers to modify the bytecode of a Java application while the Java application is running, thereby enhancing the functionality of the application. Bytecode enhancement can enhance Java applications without modifying the source code. In this way, the damage to the original code (i.e., source code) of the Java application can be avoided, and the maintenance and upgrade of the Java application can also be facilitated. Common bytecode enhancement technologies include method interception, field injection, class enhancement, etc. These technologies can be used to implement functions such as logging, performance monitoring, transaction management, and security control.
[0046] Java virtual machine (JVM): A language runtime used to execute Java language code. In order to achieve the "compile once, run everywhere" feature when designing the Java language, Java code is compiled into bytecode during compilation, a format that is easy to distribute but cannot be run directly. The bytecode must then be interpreted or compiled by the Java virtual machine, and it provides support for operations such as class loading and garbage collection.
[0047] Java application: refers to an application developed using Java. A Java application corresponds to one or more services, and the container in the microservice architecture provides the one or more services by running the Java application. In the following description, a Java application may be referred to as an application.
[0048] Java class: can be referred to as class for short. It is the basic unit of Java application code. It is 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.
[0049] 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.
[0050] Java heap: A piece of memory space in the JVM used to store Java objects. All Java objects will logically be allocated in the Java heap.
[0051] Java archive (JAR) file: also known as JAR package, a software package file format, including the bytecode of a Java application, related metadata, and resource (text, image, etc.) files. The bytecode of a Java application consists of the bytecode of the class of the Java application. The Java application is started by loading the Java archive file of the Java application. The Java archive file can include multiple sub-packages, and each sub-package can include one or more classes.
[0052] JavaAgent: Also known as the enhancement component, it is a new feature introduced after Java Development Kit (JDK) 1.5, which is used to implement bytecode enhancement. Specifically, JavaAgent supports 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, so that the JVM can use the modified bytecode to generate Java objects in the Java heap, thereby realizing non-intrusive business logic modification and replacement of Java applications. JavaAgent is a special Java program and 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, runs in the same process as the JVM, and interacts with the JVM through the instrumentation API.
[0053] Classes to be enhanced: refers to classes that need bytecode enhancement during the startup or running process of a Java application. Before generating objects of the class to be enhanced, the bytecode of the class to be enhanced needs to be enhanced.
[0054] Enhanced Java archive file: refers to a Java archive file in which the bytecode of the class to be enhanced is modified by the enhancement component. The class to be enhanced here refers to the class that needs to be bytecode enhanced during the startup process of the Java application.
[0055] Original Java archive file: refers to a Java archive file whose bytecodes of the included classes are not 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.
[0056] 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, the startup time of the Java application will 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 a Java archive file specifically means loading the bytecode in the Java archive file.
[0057] In a microservice architecture, in order to cope with sudden service access, service expansion needs to be carried out in a timely manner. Service expansion requires more containers to run the Java application that provides the service. In order to ensure the timeliness of service expansion, Java applications need to be started quickly in newly created containers. However, bytecode enhancement increases the startup time of Java applications, affecting the timeliness of service expansion.
[0058] In one solution, whenever a Java archive file of a Java application is loaded, the package name of the subpackage where the class in the Java archive file is located is 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 the classes that need to be enhanced in a smaller range, reducing the time spent on identifying the classes that need to be enhanced. However, when starting a Java application, this solution still needs to identify the classes that need to be enhanced and modify the bytecodes of the classes that need to be enhanced, which still increases the startup time of the Java application. In addition, this solution needs to analyze the package name of the subpackage in advance each time a Java application is loaded, which is cumbersome to operate, and when the package name of the subpackage where the class that needs to be enhanced is the same as the package name of the subpackage where the class that does not need to be enhanced is located, the subpackages that are filtered out are limited, thereby reducing the time spent on identifying the classes that need to be enhanced.
[0059] In another solution, in the process of loading the Java archive file of the Java application, that is, in the process of starting the Java application, bytecode enhancement is not performed to avoid the impact of bytecode enhancement on the startup time of the Java application. When this solution cannot enhance the classes used in the process of starting the Java application, it has great limitations and cannot fully utilize the effect of bytecode enhancement.
[0060] The 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. Among them, the pre-enhancement stage can be a preparatory stage before the formal deployment of the service, or it can be a stage where the service is deployed for the first time. The service is a service provided by a container by running an application. Among them, 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), and an updated Java archive file is obtained. The updated Java archive file is used as an enhanced Java archive file. In the formal startup stage of the application (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 class 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 the Java application, there is no need to identify the class to be enhanced and modify the bytecode of the class to be enhanced. This can ensure that the classes used in the Java application startup process are bytecode enhanced while shortening the startup time of the Java application. In this way, when the service is officially deployed or the service is expanded, the Java application can be quickly started in the container, ensuring the efficiency of service deployment or the timeliness of service expansion.
[0061] Next, the application running method provided in the embodiment of the present application is introduced in detail.
[0062] Figure 1 FIG. 1 shows a microservice architecture 100 provided in an embodiment of the present application. Figure 1 As shown, the microservice architecture 100 includes a management platform 110 , multiple container groups, and a warehouse 140 .
[0063] 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, the bytecode of the class to be enhanced in the original Java archive file is modified 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.
[0064] The controller platform 110 is used to create and manage container groups, for example, to create a container group, to create a container in a container group, and to manage the life cycle of a container or a container group.
[0065] like Figure 1 As shown, the management platform 110 may include a container creation module 111 and a container injection module 112. The container creation module 111 may receive user operations and create a container group based on the user operations. The container creation module 111 may 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 may write a YAML file for creating a container group or a container. YAML is a markup language and a format for expressing data serialization. The container creation module 111 may receive the YAML file and create a container group or a container based on the YAML file. In one example, the container creation module 111 may be implemented as an application programming interface server (API server) of k8s. The container injection module 112 may be used to inject business containers and sidecar containers into the container group. The container injection module 112 may also be used as a bytecode enhancement container injector to inject an enhanced container 121 into the container group 120.
[0066] In some embodiments, the management platform 110 may further include a configuration module 113. The configuration module 113 may configure an acquisition address of a Java archive file of a Java application. The acquisition address is used by a container in the microservice architecture 100 to acquire a Java archive file of a Java application so that the container can load the bytecode in the Java archive file and then run the Java application.
[0067] Warehouse 140 is also called a mirroring warehouse, which is used to store data. Warehouse 140 can be used as a Java archive file warehouse to store Java archive files of Java applications. Warehouse 140 can specifically 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, that is, containers in different container groups in microservice architecture 100 can store and read data in warehouse 140.
[0068] The above example introduces the microservice architecture 100 provided in the embodiment of the present application. Next, in combination with the microservice architecture 100, the application program running method provided in the embodiment of the present application is introduced. Among them, the method can be executed by the management platform 110. Figure 2 As shown, the method includes the following steps.
[0069] In step 201, the enhanced container 121 in the container group 120 loads the bytecode in the original Java archive file of the Java application A1 to obtain the 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 in the JVM. In addition, in the embodiment of the present application, loading the bytecode in the Java archive file can be referred to as loading the Java archive file.
[0070] Loading the bytecode in the Java archive file of the Java application can be understood as the startup process of the Java application. Among them, in the process of loading the bytecode in the Java archive file of the Java application, a class object for running the Java application is generated. After the loading is completed, these class objects can be used to run the Java application.
[0071] Before executing step 201, the original Java archive file of the Java application A1 may be stored in the microservice architecture 100, for example, in the warehouse 140. For example, Figure 3As shown, in step 301a, the management platform 110 can compile the source code of the Java application A1 to obtain the original Java archive file of the Java application A1. Then, the management platform 110 can store the original Java archive file in the warehouse 140.
[0072] The management platform 110 can configure an acquisition address for a Java archive file, and the acquisition address is used for the container to acquire the Java archive file. The management platform 110 can configure the acquisition address as the storage address of the original Java archive file of the Java application A1. The enhanced container 121 can obtain the acquisition address, and based on the acquisition address, acquire the original Java archive file of the Java application A1. In step 302a, the enhanced container 121 can acquire the original Java archive file of the Java application A1 based on the acquisition address. After the enhanced container 121 acquires the original Java archive file of the Java application A1, the enhanced container 121 can load the bytecode in the original Java archive file of the Java application A1.
[0073] When or before the enhanced container 121 starts to load the bytecode in the original Java archive file of the Java application A1, the enhanced container 121 can 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.
[0074] In some embodiments, see Figure 3 In step 301b, the management platform 110 may configure the enhancement component, for example, configure the enhancement logic of the enhancement component. The management platform 110 may configure the enhancement component in response to the configuration operation of the user. The management platform 110 may store the enhancement component in the warehouse 140. The sidecar container 123 in the container group 130 may obtain the enhancement component from the warehouse 140 and store the enhancement component in the 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 through step 302b.
[0075] like Figure 3 As shown, step 201 includes step 303, the enhanced container 121 loads the bytecode in the original Java archive file of the Java application A1. Wherein, the enhanced container 121 runs the enhanced component while loading the bytecode in the original Java archive file of the Java application A1.
[0076] During the loading process of the bytecode in the original Java archive file of the Java application A1, the enhancement component can identify the class to be enhanced of the Java application A1 in the original Java archive file, and perform bytecode enhancement on the identified class to be enhanced. Specifically, before generating the object of the class to be enhanced, the enhancement component modifies the bytecode of the class to be enhanced according to its bytecode enhancement logic. The enhancement container 121 can use the modified bytecode to replace the bytecode of the class to be enhanced in the original Java archive file (i.e., the bytecode before modification) to obtain the enhanced Java archive file of the Java application A1. That is to say, compared with the original Java archive file, 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 bytecode enhancement logic. More specifically, the bytecode of the class 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 run by the enhancement container 121 modifies the bytecode B1 in the original Java archive file to bytecode B2, and obtains the enhanced Java archive file of the Java application A1. The class to be enhanced of the Java application A1 here refers to a class that needs to be bytecode enhanced during the startup process of the Java application A1.
[0077] 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.
[0078] In some embodiments, the enhancement container 121 may add the identifier of the class to be enhanced to a list, and include the list into the enhanced Java archive file, wherein the identifier of the class may be a class name.
[0079] The enhanced container 121 can store the enhanced Java archive files in the microservice architecture 100. In some embodiments, as described above, the microservice architecture 100 includes a repository 140. Figure 3 As shown, in step 304 , the enhanced container 121 may store the enhanced Java archive file in the repository 140 .
[0080] 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 (for example, the warehouse 140).
[0081] In some embodiments, after the storage of the enhanced Java archive file is completed, for example, after the enhanced Java archive file is stored in the warehouse 140, the management platform 140 may redirect the acquisition address of the Java archive file. Specifically, the acquisition address of 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 acquisition address of the Java archive file is modified from the storage address of the original Java archive file to the storage address of the enhanced Java archive file.
[0082] In some embodiments, the enhanced container 121 is the first container to start the Java application A1 in the microservice architecture 100, that is, the first container to load the JAR of the Java application A1. As described above, the JAR of the Java application A1 loaded by the enhanced container 121 is specifically the original JAR of the Java application A1.
[0083] As described above, the application running method provided in the embodiment of the present application is divided into a pre-enhancement stage and an application formal startup stage. Among them, step 201 belongs to the pre-enhancement stage. In one example, the pre-enhancement stage can be a preparatory stage 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 of the Java application A1. Then, in this example, after the enhanced container 121 generates the enhanced Java archive file of the Java application A1, the life cycle of the enhanced container 121 ends. That is, after the enhanced container 121 generates the enhanced Java archive file of the Java application A1, the enhanced container 121 can be deleted. In one example, the pre-enhancement stage can be a service deployment stage before service expansion. In this example, the enhanced container 121 is also used as a business container. After the original Java archive file of the Java application A1 is loaded, that is, after the Java application A1 is started, the Java application A1 is run to provide services. In this example, the enhanced container 121 is the first Java archive file (specifically the original Java archive file) of the Java application A1 in the microservice architecture 100, and the container that runs the Java application A1.
[0084] Continue reading Figure 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 in the JVM.
[0085] In some embodiments, the enhanced Java archive file of the Java application A1 is stored in the warehouse 140, and the business container 122 can obtain the enhanced Java archive file of the Java application A1 from the warehouse 140. Figure 4 As shown, through step 401a, the business container 122 obtains the enhanced Java archive file from the warehouse 140.
[0086] In some embodiments, as described above, the management platform 110 may modify the acquisition address of the Java archive file of the Java application A1 from the storage address of the original Java archive file of the Java application A1 to the storage address of the enhanced Java archive file of the Java application A1. The business container 122 may acquire the Java archive file based on the modified acquisition address, thereby acquiring the enhanced Java archive file of the Java application A1.
[0087] 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. Among them, the bytecode of the class to be enhanced in the enhanced Java archive file is the bytecode modified by the enhanced 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. Among them, 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 mentioned 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, thereby reducing the startup time of the Java application while ensuring the bytecode enhancement effect.
[0088] The business 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.
[0089] When the business container 122 completes loading the bytecode in the enhanced Java archive file, it can obtain the loading result C1 required for the business container 122 to run the Java application A1. In this way, the business container 122 can run the Java application A1 based on the loading result C1 in step 203 to provide services.
[0090] In some embodiments, bytecode enhancement is dynamically woven, 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, such as Figure 4 As shown in step 403 in FIG. 1 , the business container 122 runs the enhancement component while running the Java application. The business container 122 may start running the enhancement component when or before 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.
[0091] In one example, as described above, the enhancement component is stored in the sidecar container 123 and stored in the storage module of the container group 120. Figure 4 In step 401b, the business container 122 obtains the enhancement component from the storage module. Figure 4 As shown, step 202 includes step 402, the business container 122 loads the bytecode in the enhanced Java archive file of the Java application A1. The business container 122 runs the enhanced component while loading the bytecode in the enhanced Java archive file of the Java application A1.
[0092] In one example, an enhanced Java archive file contains a list, which includes an identifier of a class to be enhanced. The list indicates that the modification operation of the bytecode of the class corresponding to the identifier in the list (for example, the class to be enhanced) has been completed, that is, the list 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 list from the enhanced Java archive file. In 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 list. Among them, 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, the class represented by the identifier on the list can be ignored, and the class represented by the identifier on the list is no longer identified. Therefore, through the list, the recognition time of the enhancement component when the business container loads the bytecode in the Java archive file can be saved, and the startup time of the Java application is further reduced.
[0093] In some embodiments, after step 203, the running state of the Java application A1 run by the business container 122 can be observed, that is, the running state of the Java application A1 run by the business container 122 based on the loading result C1 can be observed. If the running state 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 to say, in this embodiment, when the business container runs the Java application abnormally by loading the enhanced Java archive file, the business container can run the Java application by loading the original Java archive file to ensure that the Java application can run normally.
[0094] In some embodiments, when deploying services provided by Java application A1 to other container groups (e.g., container group 130) outside container group 120, the enhanced Java archive file of Java application A1 can also be used to start Java application A1 to improve the efficiency of service deployment or the timeliness of service expansion. Next, starting Java application A1 in business container 131 in container group 130 is taken as an example for introduction.
[0095] The business container 131 may obtain the loading result C3 by reading the bytecode in the enhanced Java archive file of the Java application A1.
[0096] The business container 131 can obtain the enhanced Java archive file of the Java application A1, for example, from the warehouse 140, and then load the enhanced Java archive file of the Java application A1. For details, please refer to the above introduction of the business container 122 obtaining the enhanced Java archive file.
[0097] 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, thereby reducing the startup time of Java application A1 while ensuring the bytecode enhancement effect of Java application A1.
[0098] The business container 131 can include the object of the class to be enhanced generated in the process of loading the bytecode in the enhanced Java archive file into the loading result C3. When the business container 131 completes the loading of the bytecode in the enhanced Java archive file, it can obtain the loading result C3 containing the business container 131 required to run the Java application A1. Then, the business container 131 can run the Java application A1 based on the loading result C3 to provide services.
[0099] In summary, the embodiments of the present application provide 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 the 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. In addition, 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 embodiments of the present application reduces the startup time of the application while ensuring the effect of bytecode enhancement of the application.
[0100] The present application embodiment provides a node 500 for running a container group. Figure 5 As shown, the node 500 runs a container group 510, and the node 500 stores a first Java archive file of an application program. The container group 510 includes a first container 511 and a second container 512.
[0101] The first container 511 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 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 during the process of the first container 511 loading the bytecode in the first Java archive file;
[0102] The second container 512 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 512 based on the first bytecode during the process of the second container 512 loading the bytecode in the second Java archive file;
[0103] The second container 512 is further used to run the application based on the first loading result.
[0104] 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 also 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.
[0105] 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.
[0106] 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: acquire the second Java archive file based on the acquisition address.
[0107] In some embodiments, the second container 512 is further used for: when an exception occurs when the second container 512 runs the application based on the first loading result, loading the first Java archive file to obtain a third loading result; and running the application with the third loading result.
[0108] In some embodiments, the first container 511 is the first container in the node 500 to load the first Java archive file.
[0109] Among them, the functions of the containers in node 500 can be implemented by referring to the above introduction to the containers in the microservice architecture 100. For example, the function of the first container 511 can also be implemented by referring to the above introduction to the enhanced container 121, and the function of the second container 512 can also be implemented by referring to the above introduction to the business container 122, and so on.
[0110] The present application also provides a computing device 600. Figure 6 As shown, computing device 600 includes: bus 602, processor 604, memory 606 and communication interface 608. Processor 604, memory 606 and communication interface 608 communicate through bus 602. Computing device 600 can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in computing device 600.
[0111] The bus 602 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 The bus 602 may include a path for transmitting information between various components of the computing device 600 (eg, the memory 606, the processor 604, and the communication interface 608).
[0112] The processor 604 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0113] The memory 606 may include a volatile memory, such as a random access memory (RAM). The memory 606 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).
[0114] The memory 606 stores executable program codes, and the processor 604 executes the executable program codes to respectively implement the functions of the first container 511 (or enhanced container 121) and the second container 512 (or business container 122), thereby implementing Figure 2 That is, the memory 606 stores the method for executing Figure 2 Instructions for the method shown.
[0115] 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 communication networks.
[0116] The embodiment of the present application also provides 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 smart phone.
[0117] like Figure 7 As shown, 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 Figure 2 Instructions for the method shown.
[0118] In some possible implementations, the memory 606 of one or more computing devices 600 in the computing device cluster may also store a program for executing Figure 2 In other words, the combination of one or more computing devices 600 can jointly execute instructions for executing Figure 2 Instructions for the method shown.
[0119] It should be noted that the memory 606 in different computing devices 600 in the computing device cluster may store different instructions, which are respectively used to execute part of the functions of the node 500. That is, the instructions stored in the memory 606 in different computing devices 600 may implement the functions of one or more containers in the first container 511 (or enhanced container 121) and the second container 512 (or business container 122).
[0120] In some possible implementations, one or more computing devices in the computing device cluster may be connected via a network, which may be a wide area network or a local area network. Figure 8 A possible implementation is shown. Figure 8 As shown, 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). At the same time, the memory 606 in the computing device 600B stores instructions for executing the functions of the second container 512 (or business container 122).
[0121] It should be understood that Figure 8 The functions of the computing device 600A shown in FIG. 6A may also be completed by multiple computing devices 600. Similarly, the functions of the computing device 600B may also be completed by multiple computing devices 600.
[0122] The present application embodiment also provides another computing device cluster. The connection relationship between the computing devices in the computing device cluster can be similar to that of Figure 7 and Figure 8 The difference is that the memory 606 in one or more computing devices 600 in the computing device cluster may store the same memory for executing Figure 2 Instructions for the method shown.
[0123] In some possible implementations, the memory 606 of one or more computing devices 600 in the computing device cluster may also store a program for executing Figure 2 In other words, the combination of one or more computing devices 600 can jointly execute instructions for executing Figure 2 Instructions for the method shown.
[0124] The present application also provides a computer program product including instructions. The computer program product may be software or a program product including 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 Figure 2 The method shown.
[0125] The present application also provides a computer-readable storage medium. The computer-readable storage medium may 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 may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the computing device to execute Figure 2 The method shown.
[0126] 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 it. 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 cause the essence of the corresponding technical solutions to deviate 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
Cited By
Application program running method, node and computing device cluster
EP4779463A1
Application program running method, node and computing device cluster
WO2025060449A1