Code execution method, device and equipment
Patent Information
- Application Number
- CN202280100252.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-15
- Publication Date
- 2025-04-25
AI Technical Summary
Existing code execution solutions are difficult to meet the efficient requirements of server-less computing, especially due to the long initialization time of class-static variables, large storage resource usage, and insufficient isolation.
By only saving metadata such as static variable values of the class after executing the code in the computing instance, deleting other data, and skipping the initialization of the class static variables when the code is executed again, using memory copy to achieve inter-code communication, and designing independent computing instance functions modules for efficient isolation.
It improves code execution efficiency, reduces storage resource overhead, achieves effective isolation between different codes, and improves the performance of server-less computing.
Smart Images

Figure CN119895817A_ABST
Abstract
Description
Code execution method, device and equipment Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a code execution method, apparatus, and device. Background Art
[0002] To reduce development complexity and improve efficiency, developers often write code in high-level languages such as Java, Python, or JavaScript. Execution of code written in these languages requires class static initialization. This typically takes a long time, significantly impacting code execution efficiency.
[0003] Serverless computing enables the execution of business logic-related code uploaded by users without the users being aware of the server, greatly reducing the burden on users to run their business. Therefore, serverless computing is becoming increasingly popular among users.
[0004] To improve the user experience of server-aware computing, server-aware computing pursues increasingly higher code execution efficiency. However, current code execution solutions are unable to meet the needs of server-aware computing.
[0005] Summary of the Invention
[0006] The embodiments of the present application provide a code execution method, apparatus, and device that can improve code execution efficiency.
[0007] In a first aspect, a code execution method is provided, which is applied to a computing device, the method comprising: receiving a first code and an execution request of the first code, the execution request being used to request the computing device to execute the first code; creating a first computing instance in the computing device, and executing the first code in the first computing instance; when the first code is executed in the first computing instance, releasing the first computing instance, saving the first data, and deleting the second data; the first data is a portion of the data involved when the first code is executed in the first computing instance, and the second data is the data other than the first data involved when the first code is executed in the first computing instance; wherein the first data includes the value of a class static variable of a class of the first code; the value of the class static variable is used to skip the initialization of the class static variable when the first code is executed again in the computing device.
[0008] The data involved in executing the code in the computing instance can be referred to as the execution data of the code. The first data can also be referred to as metadata in the execution data. The data in the execution data other than metadata can also be referred to as ordinary data.
[0009] Class static variables are a type of metadata within the execution data. Initializing class static variables takes a long time and significantly impacts code execution efficiency. Furthermore, metadata is relatively small, while regular data is much larger, and compute instances consume more storage and other resources.
[0010] After code execution completes, this method only saves metadata generated during code execution, such as the values of class static variables that affect the efficiency of code re-execution, while deleting ordinary data and releasing the computing instance. This reduces storage resource overhead and allows the storage of metadata for more code. Consequently, when more code is re-executed, metadata such as the values of class static variables stored by the computing device can be obtained, allowing the initialization of class static variables to be skipped, thereby improving code execution efficiency.
[0011] In a possible implementation, the first code is a Java language code, and the first computing instance is a sandbox in a Java virtual machine.
[0012] In this implementation, the sandbox in the Java virtual machine can be used as a computing instance to execute the first code, thereby eliminating the need to create a separate container or virtual machine for executing the first code, and creating a Java virtual machine in the container or virtual machine, thereby saving resource overhead and the overhead of creating a computing instance, and allowing the code to be executed as quickly as possible.
[0013] In a possible implementation, the first data further includes class metadata, where the class metadata is used to indicate the class to which the class static variables in the first data belong; and / or, the first data further includes just-in-time compiled code of the first code.
[0014] In this implementation, the class metadata of the first code is also saved. Thus, when the computing device executes the first code again, the class metadata can be obtained as quickly as possible, and the class metadata can be used to quickly identify the class to which the class static variable belongs, further improving the execution efficiency of the first code.
[0015] This implementation also includes the just-in-time compiled code of the first code. The just-in-time compiled code is optimized and has fast execution performance. When the first code is executed again, the just-in-time compiled code of the first code can be quickly retrieved from the storage space of the computing device and executed, further improving the execution efficiency of the first code.
[0016] In one possible implementation, executing the first code in a computing instance includes: before executing the first code, querying the value of the class static variable of the class of the first code in the data saved by the computing device; when the value of the class static variable of the class of the first code is queried, skipping the initialization of the class static variable during the execution of the first code.
[0017] In this implementation, before executing the first code, the value of the class static variable of the class of the first code is first queried in the data stored in the computing device, and then the first code is executed using the queried value of the class static variable of the class of the first code, thereby skipping the initialization of the class static variable and improving the execution efficiency of the first code.
[0018] In one possible implementation, a computing device stores initialization values of static variables of multiple classes; executing a first code in a computing instance includes: querying the class of the first code among multiple classes to obtain a first class; during the execution of the first code, obtaining the initialization values of the static variables of the first class from the initialization values of the static variables of multiple classes to skip the initialization of the static variables of the first class.
[0019] This implementation method provides initialization values for static variables of multiple classes. When the code is executed for the first time, the initialization values for the static variables of the class of the code can be obtained from the initialization values of the static variables of the multiple classes, thereby skipping the initialization of the static variables of the class, shortening the execution time of the code, and improving the efficiency of the first execution of the code.
[0020] In one possible implementation, the execution result of the first code is used as an execution parameter of the second code, wherein the second code is executed in a second computing instance in the computing device; the method also includes: copying the execution result of the first code from the memory of the first computing embodiment to the memory of the second computing instance.
[0021] In this implementation, communication between computing instances that execute code can be achieved through memory copying, reducing the communication overhead between computing instances.
[0022] In one possible implementation, the first code is a high-level language code, and the execution of the first code requires calling a machine language code. The method also includes: receiving a machine language code and an execution request of the machine language code, the execution request being used to request a computing device to execute the machine language code; creating a third computing instance in the computing device, the third computing instance being a container or a virtual machine; and executing the machine language code in the third computing instance.
[0023] In this implementation, the machine language code that the high-level language code needs to call is placed in a container or virtual machine outside the high-level language code execution environment for execution, thereby achieving effective isolation between the high-level language code and the machine language code.
[0024] In one possible implementation, the computing device includes multiple computing instances, and different computing instances are used to execute different codes; wherein the functional modules of different computing instances are independent of each other; wherein the functional modules are one or a combination of any multiple of a code executor, a memory space, a safe point, a garbage collector, and a JIT compilation thread.
[0025] In this implementation, the computing instance has a private code executor, memory space, safe point, garbage collector, JIT compilation thread, etc., achieving a high degree of isolation of the performance and functions of the computing instance.
[0026] In a second aspect, a code execution device is provided, which is configured in a computing device, and the execution device includes: a receiving unit, for receiving a first code and an execution request of the first code, the execution request being used to request the computing device to execute the first code; an execution unit, for creating a first computing instance in the computing device, and executing the first code in the first computing instance; a storage unit, for releasing the first computing instance after the first code is executed in the first computing instance, saving the first data, and deleting the second data; the first data is a part of the data involved when the first code is executed in the first computing instance, and the second data is the data other than the first data involved when the first code is executed in the first computing instance; wherein the first data includes the value of the class static variable of the class of the first code; the value of the class static variable is used to skip the initialization of the class static variable when the first code is executed again in the computing device.
[0027] In a possible implementation, the first code is a Java language code, and the first computing instance is a sandbox in a Java virtual machine.
[0028] In a possible implementation, the first data further includes class metadata, where the class metadata is used to indicate the class to which the class static variables in the first data belong; and / or, the first data further includes just-in-time compiled code of the first code.
[0029] In one possible implementation, the execution unit is further used to: before executing the first code, query the value of the class static variable of the class of the first code in the data saved by the computing device; when the value of the class static variable of the class of the first code is queried, skip the initialization of the class static variable during the execution of the first code.
[0030] In one possible implementation, the computing device stores initialization values of static variables of multiple classes; the execution unit is further used to: query the class of the first code from the multiple classes to obtain the first class; during the execution of the first code, obtain the initialization values of the static variables of the first class from the initialization values of the static variables of the multiple classes to skip the initialization of the static variables of the first class.
[0031] In one possible implementation, the execution result of the first code is used as an execution parameter of the second code, wherein the second code is executed in a second computing instance in the computing device; the execution device also includes a copy unit for copying the execution result of the first code from the memory of the first computing embodiment to the memory of the second computing instance.
[0032] In one possible implementation, the first code is a high-level language code, and the execution of the first code requires calling a machine language code; the receiving unit is also used to: receive the machine language code and an execution request of the machine language code, and the execution request is used to request the computing device to execute the machine language code; the execution unit is also used to: create a third computing instance in the computing device, and the third computing instance is a container or a virtual machine; in the third computing instance, execute the machine language code.
[0033] In one possible implementation, the computing device includes multiple computing instances, and different computing instances are used to execute different codes; wherein the functional modules of different computing instances are independent of each other; wherein the functional modules are one or a combination of any multiple of a code executor, a memory space, a safe point, a garbage collector, and a JIT compilation thread.
[0034] In a third aspect, a computing device is provided, characterized in that it includes a processor and a memory; the memory is used to store a computer program; and the processor is used to execute the computer program to implement the method provided in the first aspect.
[0035] In a fourth aspect, a computer storage medium is provided, characterized in that a computer program is stored on the computer storage medium, and when the computer program is executed by a processor, the method provided in the first aspect is implemented.
[0036] In a fifth aspect, a computer program product is provided, characterized in that it includes a program for implementing the method provided in the first aspect.
[0037] After code execution is completed, the code execution method, device, and apparatus provided in the embodiments of the present application only save metadata such as the values of class static variables that affect the efficiency of code re-execution from the data generated during code execution, while deleting other data and releasing the computing instance. This reduces storage resource overhead and enables the storage of metadata for more codes. As a result, when more codes are executed again, metadata such as the values of class static variables saved by the computing device can be obtained, and the initialization of class static variables of the class can be skipped, thereby improving the execution efficiency of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] FIG1 is a schematic diagram of a system architecture provided in an embodiment of the present application;
[0039] FIG2 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application;
[0040] FIG3 is a schematic diagram of the structure of a language runtime provided in an embodiment of the present application;
[0041] FIG4 is a schematic diagram of a system architecture provided in an embodiment of the present application;
[0042] FIG5 is a flowchart of a code execution solution provided in an embodiment of the present application;
[0043] FIG6 is a schematic diagram of a machine language code execution solution provided in an embodiment of the present application;
[0044] FIG7 is a diagram comparing the code execution effects of the code execution solution provided by an embodiment of the present application and other code execution solutions;
[0045] FIG8 is a diagram comparing the code execution effects of the code execution solution provided by an embodiment of the present application and other code execution solutions;
[0046] FIG9 is a diagram comparing the code execution effects of the code execution solution provided by an embodiment of the present application and other code execution solutions;
[0047] FIG10 is a flowchart of a code execution method provided in an embodiment of the present application;
[0048] FIG11 is a schematic diagram of the structure of a code execution device provided in an embodiment of the present application;
[0049] FIG12 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0050] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings. Obviously, the embodiments described in this specification are only part of the embodiments of the present application, rather than all the embodiments.
[0051] Developers often write code in high-level languages like JavaScript, Python, or Java to improve development efficiency. Java, in particular, has become a popular programming language due to its high efficiency, cross-platform nature, and automatic memory management.
[0052] At present, the execution efficiency of high-level language codes is low. Taking the execution of Java language codes in the field of server-unaware computing as an example, the execution of Java language codes depends on the Java virtual machine (JVM), a language runtime. It takes a long time to start the JVM, and it takes a long time to start executing the Java language code. In addition, the execution of Java language codes requires class static initialization, which seriously affects the execution efficiency of the code. In addition, different JVMs need to communicate through the network, which makes cross-JVM communication have high serialization and deserialization overhead. These problems bring obstacles to the application of Java language codes in server-unaware computing.
[0053] In addition, in the field of server-aware computing, since the server-aware computing platform may execute multiple codes simultaneously, and different codes in the multiple codes may be uploaded by different users, it is necessary to ensure the isolation between the execution of multiple codes.
[0054] Isolation can include functional isolation and performance isolation. Functional isolation means that code execution logically monopolizes the entire language runtime, and the execution results of the code are not affected by the execution results of other code. Performance isolation means that the resources utilized by code execution (such as computing resources, storage resources, communication resources, etc.) are not affected by the resource usage of other code execution.
[0055] To achieve isolation between different code executions while minimizing equipment costs, multiple compute instances are typically created on a computing device, with different codes executed in different compute instances. A compute instance, also known as an isolation instance, refers to software that provides an isolated environment for code execution. In particular, in the server-agnostic world, compute instances are used to run isolated code execution environments belonging to different users.
[0056] In Solution 1, in order to ensure the isolation of multiple Java language code executions, multiple containers or virtual machines (VMs) are created on the physical machine as computing instances. Then, a JVM is created in each computing instance to execute the Java language code. In order to improve the efficiency of code execution, after the current execution of the code is completed, the computing instance and JVM are not closed, and the data involved in the current execution of the code (the data involved in the code execution can be called execution data) are cached. When the code is executed again, the unclosed computing instance and JVM can continue to be used, and the cached execution data can be used to execute the code, thereby eliminating the computing instance and JVM, reducing class initialization time, and improving code execution efficiency.
[0057] In this solution, compute instances and JVMs are not shut down, nor is code execution data cached. This results in high memory and cache overhead. Limited memory and cache resources make it difficult to support a large number of compute instances, JVMs, and code execution data. Furthermore, in this solution, code runs in different JVMs. When one code requires the results of another, cross-JVM communication is required, resulting in high communication overhead.
[0058] In Solution 2, to ensure isolation between multiple Java code executions, multiple sandboxes are created within the same JVM. This solution is known as a multi-sandbox JVM solution. A sandbox, also known as a sandbox, provides an isolated environment for code execution. A sandbox serves as a computing instance for executing code. Different code executes in different sandboxes, or computing instances.
[0059] In order to improve the efficiency of code re-execution, this solution caches the data involved in the current execution of the code (i.e., execution data) after the code is executed, so that this data can be used when it is executed again, reducing class initialization time. Usually, the amount of execution data is large, resulting in large cache overhead, and cache resources are limited, making it difficult to cache the execution data of more code. Therefore, this solution has limited improvement on code execution efficiency. In addition, this solution has problems such as sharing class static variables between different codes, which makes it difficult for this solution to provide an effective isolation environment for codes of different users.
[0060] In summary, the execution of high-level language codes represented by Java language codes still has the following problems.
[0061] 1. To improve code execution efficiency, computing instances and / or code execution data with large data volumes are cached, which occupies a large cache and limits the number of computing instances or codes that can be cached. This results in a high probability that the execution data of code that needs to be executed again will not be cached, making it difficult to achieve improved execution efficiency.
[0062] 2. The communication overhead between different codes is large.
[0063] 3. In a multi-sandbox JVM solution, the isolation between sandboxes is low, making it difficult to meet the isolation requirements between different users' code. Furthermore, in a multi-sandbox JVM solution, it is difficult to effectively isolate high-level language code from machine language code.
[0064] Machine language code, also known as native code, refers to binary computer instructions written and compiled in languages such as C / C++. During the execution of high-level language code, machine language code may need to be called to improve the execution performance of the high-level language code.
[0065] The embodiment of the present application provides a code execution scheme that can solve the above problems. Specifically, first, after the code execution ends, the embodiment of the present application only keeps the metadata that affects the efficiency of code execution again in the data generated when the code is executed (such as the value of the static variable of the class of the code), and deletes other data, thereby reducing the overhead of storage resources, and can store more metadata of the code, so that all or most of the metadata of the code that needs to be executed again are maintained. Secondly, the embodiment of the present application provides the initialization values of the static variables of multiple classes. When the code is executed for the first time, the initialization values of the static variables of the class of the code can be obtained from the initialization values of the static variables of the multiple classes, so that the initialization of the static variables of the class can be skipped, shortening the execution time of the code and improving the efficiency of the first execution of the code. Moreover, communication between codes can be achieved by memory copying, reducing the overhead of communication between codes. And, the embodiment of the present application places the machine language code that the high-level language code needs to call into a container or virtual machine outside the high-level language code execution environment for execution, achieving effective isolation between the high-level language code and the machine language code. In addition, the embodiments of the present application isolate the performance and functions of computing instances used to execute different codes, thereby improving the isolation between different computing instances.
[0066] Next, the code execution solution provided in the embodiment of the present application is introduced in detail.
[0067] First, the terms that may be involved in the embodiments of the present application are introduced.
[0068] Serverless computing: also known as serverless computing, is a new paradigm in cloud computing. This model only requires cloud platform users to upload code related to business logic. The cloud platform or server-aware computing platform schedules, deploys, and executes the code, thereby significantly reducing the burden on users.
[0069] Server-aware computing code: A small code snippet uploaded by the user, which is the basic computing logic unit running on the cloud platform or server-aware computing platform.
[0070] Isolate instances, also known as compute instances or funclet, are software that provides an isolated environment for code execution. In the server-agnostic world, compute instances or isolate instances are used to run code belonging to different users in isolated code execution environments.
[0071] Language runtime: The language runtime environment required to execute code written in high-level languages such as Java, JavaScript, and Python.
[0072] 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 Java Virtual Machine then interprets and compiles the bytecode, providing support for operations like class loading and garbage collection.
[0073] Multi-tenant JVM: A Java virtual machine that supports multi-tenancy. Multi-tenancy allows code belonging to different tenants to run within the same Java virtual machine process, with a certain level of isolation (depending on the specific implementation of the multi-tenant JVM). A tenant is a user who uploads code to a cloud platform or server-agnostic computing platform and uses it to execute the code.
[0074] Sandbox: A computing instance that can be created in the JVM, that is, a computing instance supported by the JVM, used to execute code in an isolated environment.
[0075] Tenant sandbox: A compute instance that can be created in a multi-tenant JVM, that is, a compute instance supported by a multi-tenant JVM, used to execute code in an isolated environment.
[0076] Functional isolation: This means that code execution logically appears to have exclusive access to the entire language runtime, and the results of code execution are not affected by the results of other code executions. Functional isolation can be used as a metric to describe the isolation between computing instances (such as sandboxes). For example, when code executes in a sandbox, it appears to have exclusive access to the entire JVM and is not affected by the results of code executing in other sandboxes within the same JVM.
[0077] Performance isolation: This refers to the fact that the resources utilized by code execution (such as computing resources, storage resources, and communication resources) are not affected by the resource usage of other code execution. Performance isolation can be used as a metric to describe the isolation between computing instances (such as sandboxes). For example, when code executes in a sandbox, its execution performance is not affected by code executing in other sandboxes within the same JVM. For example, there will be no processor resource preemption.
[0078] Java class: The basic unit of Java 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.
[0079] Java object: A data structure that contains a series of fields and a series of methods for operating the data. Each Java object is a specific instance of the corresponding Java class.
[0080] Java heap: A memory space in the JVM used to store Java objects. All Java objects will logically be allocated in the Java heap.
[0081] Java Native Interface (JNI): An interface provided by the JVM for Java language code to call native code (also known as machine language code, that is, assembly code that runs directly on the processor) written and compiled in languages such as C / C++.
[0082] Class static variables: also known as class variables, are contained in every Java class, shared by all objects of the same class, and are the only domain of the class.
[0083] Hotspot virtual machine (oracle hotspot VM): part of the OpenJDK project, (The most widely used open source JVM launched by
[0084] Class metadata: This is a data structure used within the JVM to represent Java class information (such as the class name, class loader, and all of the class's methods). It defines the class structure. For the Hotspot virtual machine, class metadata is also known as Klass. Class metadata can be used to determine the class to which data belongs based on its data structure. In other words, class metadata indicates the class to which data belongs.
[0085] Just-in-time (JIT) compiled code: To achieve the "compile once, run everywhere" feature, Java code is distributed in the form of bytecode. This intermediate expression, bytecode, cannot be run directly on the CPU and must be interpreted by the JVM into assembly instructions understandable to the processor before it can be executed. This process is called interpreted execution. After Java code is interpreted and executed multiple times, the JVM compiles the method's bytecode and, through a series of optimizations, generates highly optimized, fast-execution native code. This compilation and optimization process is called runtime just-in-time compilation, and accordingly, the code generated by runtime just-in-time compilation is called JIT-compiled code.
[0086] A storage instance for class static variables: This data structure is used to store class static variables, stored as a Java object in the Java heap. For the Hotspot virtual machine, a storage instance for class static variables is also called a Java Mirror.
[0087] Initialization of class static variables: It can also be called class static initialization, which refers to the process of calling the static constructor to execute the user-defined static initialization logic and modifying the object state of the storage instance of the class static variable. During the execution of the code, the object state of the storage instance of the class static variable may also change, that is, the execution of the code may modify the object state of the storage instance of the class static variable. Among them, the object state of the storage instance of the class static variable can be called the value of the class static variable. The object state of the storage instance of the class static variable obtained by the initialization of the class static variable can be called the initialization value of the class static variable. The value of the class static variable can refer to the object state of the storage instance of the class static variable after the code execution is modified, or it can refer to the initialization value of the class static variable.
[0088] Next, a system architecture 100 that can be used to implement the code execution solution provided in the embodiment of the present application is introduced.
[0089] As shown in Figure 1, the system architecture 100 may include a computing device 110. The computing device 110 serves as a code execution end for executing the code.
[0090] When computing device 110 needs to execute code, it can create a computing instance and execute the code in the computing instance. Different codes create different computing instances, and different codes are executed in different computing instances. This allows for the simultaneous execution of multiple codes while ensuring the isolation of code execution.
[0091] The computing device 110 can be implemented in hardware. For example, the computing device 110 can be a server, a terminal device (such as a mobile phone, a laptop computer, a vehicle-mounted terminal, a tablet computer, etc.) or other forms of hardware devices. As a physical machine, the computing device 110 can run multiple computing instances, for example, run multiple virtual machines or containers. The computing device 110 can also be implemented in software. For example, the computing device 110 can be a virtual machine, a container or a JVM. Among them, when the computing device 110 is a JVM, the computing instance created by the computing device 110 can be a sandbox. When the computing device 110 is a virtual machine or a container, the computing instance created by the computing device 110 can be a language runtime corresponding to the code to be executed. For example, if the code to be executed is Java language code, the computing instance can be a JVM.
[0092] When code execution in a compute instance ends, the compute instance is released, the metadata in the code's execution data is saved, and the normal data is deleted. Code execution data refers to the data involved in code execution. Metadata in execution data refers to data involved in the current code execution that can be used to re-execute the code and improve its efficiency. Normal data in execution data refers to data that is irrelevant or less relevant to the re-execution of the code. The metadata in the execution data and the normal data in the execution data constitute the execution data. That is, data other than metadata in the execution data is normal data. Releasing a compute instance means shutting down the compute instance and releasing the resources occupied by the compute instance. The resources occupied by the compute instance refer to the resources that enable the compute instance to run and execute code within the compute instance, including computing resources (such as processor resources), storage resources (such as memory resources, cache resources, and hard disk resources), and communication resources (such as network card resources).
[0093] In addition, the code here refers to high-level language code, such as Java language code. The data involved in the code execution may include data generated, obtained, and modified during the code execution process.
[0094] The metadata in the code execution data may include the values of class static variables of the code's class. When the code is executed again, the values of the class static variables of the code's class generated or obtained during the previous execution of the code can be obtained from the storage space of the computing device 110, and the obtained values of the class static variables of the code's class can be used as the values of the class static variables of the code's class during the current execution. Therefore, the initialization of the class static variables does not need to be performed again, that is, the initialization of the class static variables is skipped.
[0095] Generally speaking, the initialization of class static variables takes a long time, which is an important factor limiting the efficiency of code execution. The solution provided by the embodiment of the present application can skip the initialization of class static variables, saving code execution time and improving code execution efficiency.
[0096] In addition, the values of class static variables of a code class are relatively small in size. Therefore, the computing device 110 can store the values of class static variables of more code classes without requiring large storage overhead, thereby improving the execution efficiency when more codes are executed again.
[0097] In some embodiments, the metadata in the execution data of the code may include the class metadata of the code. As shown above, the class metadata indicates the class to which the data belongs. Therefore, the class metadata can indicate the class to which the class static variables in the metadata in the execution data belong. When the code is executed again, the class metadata generated or obtained by the last execution of the code can be obtained from the storage space of the computing device 110, thereby shortening the time to obtain the class metadata. Then, based on the class metadata, it is possible to quickly identify which classes the data belongs to, especially which classes the values of the class static variables belong to, thereby further saving code execution time and improving code execution efficiency.
[0098] In some embodiments, the metadata in the code execution data may include the code's just-in-time compiled code. Just-in-time compiled code is optimized and has fast execution performance. When the code is executed again, the just-in-time compiled code can be retrieved from the storage space of computing device 110 and executed, further improving the code's execution efficiency.
[0099] Furthermore, the class metadata of the code and the just-in-time compiled code contain relatively little data and are small in size. In these embodiments, the computing device 110 can store the class metadata and just-in-time compiled code for more codes without requiring significant storage overhead, thereby improving the execution efficiency of the more codes when they are executed again.
[0100] In some embodiments, the computing device 110 may have a software structure as shown in FIG2 . The user mode of the computing device 110 runs a language runtime 200 for providing an execution environment for the corresponding code. The language runtime 200 may be implemented as a process. The language runtime has a manager 210, and multiple computing instances such as a computing instance 221 and a computing instance 222 may be created in the language runtime 210. Different codes may be executed in different computing instances, for example, the computing instance 221 executes code A1, and the computing instance 222 executes code A2. Different codes may be codes from different users, or codes from different segments of the same user.
[0101] The manager 210 may also manage and release computing instances, and perform other operations that require the language runtime 200 to execute. In some embodiments, the manager 210 may be one or more threads in the language runtime.
[0102] As shown in Figure 2, the storage space occupied by the language runtime 200 includes a metadata storage area 230. The storage space can be memory space, cache space, or hard disk storage space. Metadata storage area 230 is used to store metadata in the code's execution data. In other words, when code execution in a compute instance ends, the metadata in the code's execution data can be saved to metadata storage area 230. This allows the metadata in the execution data to be preserved when the resources occupied by the compute instance are released.
[0103] In some embodiments, the language runtime 200 may further include a shared metadata repository 240. The shared metadata repository 240 may include metadata of public classes that can be shared between different codes and does not affect the isolation of code execution. The metadata of public classes can improve the execution efficiency of the code when it is first executed on the computing device 110. Among them, a public class refers to a class that multiple codes have. In some embodiments, the metadata of public classes may include at least one of class metadata of public classes, just-in-time compiled code of public classes, and initialization values of class static variables of public classes. As shown in Figure 3, when the code is first executed on the computing device 110, the computing instance used to execute the code can obtain the public class metadata from the shared metadata repository 240, obtain the class metadata required by the code, and improve the efficiency of the initial execution of the code.
[0104] Referring to Figure 3, in order to ensure functional isolation between computing instances, each computing instance has a private thread group, private space, private metadata, etc. That is, each computing instance has exclusive thread groups, spaces, and metadata. Here, space refers to storage space, such as memory space, cache space, hard disk storage space, etc. Among them, the private thread group of the computing instance can be called a code executor, which is used to execute code. When the code is executed, the private thread group of the computing instance can obtain or generate the immediately compiled code, the value or initial value of the class static variable of the class, and use the private user class loader to load the class metadata to obtain private metadata. The private thread of the computing instance calls the private metadata in the private space and executes the code, thereby ensuring the functional isolation between the execution of codes by different computing instances.
[0105] As shown in Figure 3, for metadata about public classes, a compute instance can use a private user class loader to copy the initialization values of class static variables of public classes in the code from the shared metadata repository to the private space. The initialization values of the class static variables of public classes copied to the private space are used as the initialization values of the class static variables of the corresponding code class. Therefore, even if the initialization values of such static variables can be modified during code execution, it will not affect the execution of code in other compute instances.
[0106] In addition, during the code execution process, the class metadata of the public class and the just-in-time compiled code of the public class will not be modified. Therefore, there is no need to copy the class metadata of the public class and the just-in-time compiled code of the public class to the private space. You can directly use the class metadata of the public class and the just-in-time compiled code of the public class in the shared metadata database.
[0107] In some embodiments, the language runtime can provide an interface for the computing instance to access external information (such as files). The external information is information outside the language runtime. The interface can modify the identification of the information (such as the identification of the information) according to the identification of the computing instance (such as the name of the computing instance) when the computing instance accesses a certain information through the interface. Thus, when different computing instances access the same information through the interface, they can access the information from an isolated perspective. That is, the identification of the same information is different from the perspective of different computing instances. In one example, the language runtime is a JVM, and the interface can be a Java common class library. The Java common class library is a bytecode stored on the hard disk.
[0108] In some embodiments, independent performance control can be provided for different computing instances in kernel mode.
[0109] In one example, as shown in FIG2 , a computing instance has a private thread group for implementing the functionality of the computing instance. As shown in FIG2 , a private control group (CGroup) of the computing instance can be created for each computing instance. For example, the private control group of computing instance 221 is controller B1, the private control group of computing instance 222 is control group B2, and so on. The control groups of different computing instances are independent of each other. A control group is A system component used for software performance management. Control groups can be used to manage resource limits for software execution, such as disk bandwidth limits, processor usage limits, and memory usage limits. This example creates a separate control group for each compute instance to manage the resources used by the thread group of that compute instance. The resources used by different compute instances are managed by different control groups, ensuring performance isolation between compute instances.
[0110] In one example, as shown in Figure 2, a private virtual network interface card (VNIC) can be created for each compute instance to implement traffic control. For example, the private VNIC of compute instance 221 is VNIC C1, the private VNIC of compute instance 222 is VNIC C2, and so on. Bandwidth caps can be set for the private VNICs of the compute instances to implement traffic control for the compute instances, further ensuring performance isolation between the compute instances.
[0111] In one example, a function module for implementing global component functionality can be created for each compute instance, so that each compute instance has an independent function component for implementing global component functionality. Global component functionality refers to functionality that can be implemented by a global component. Global components may include a garbage collector (GC), a safepoint, a JIT compilation thread, and the like.
[0112] Safepoints are specific locations in the code execution process where code execution can be safely paused to allow for operations such as garbage collection. Failure to pause at safepoints can lead to instability in the language runtime, impacting the correctness of language runtime management operations. Each compute instance can have its own private safepoint. This allows each compute instance to independently pause code execution, allowing for garbage collection and other operations within the compute instance without affecting code execution in other compute instances.
[0113] A private garbage collector can be created for each computing instance, and the private garbage collector of the computing instance can be incorporated into the management of the private control group of the computing instance, so that when the garbage collector is used to perform garbage collection on the computing instance, the performance of other computing embodiments will not be affected.
[0114] A private JIT compilation thread can be created for each computing instance, and the private JIT compilation thread of the computing instance can be included in the management of the private control group of the computing instance, so that when the JIT compilation thread is used to JIT compile the computing instance, the performance of other computing embodiments will not be affected.
[0115] Continuing with FIG1 , the system architecture 100 may further include a computing device 120. The computing device 120 may serve as a code caller, requesting the execution end (i.e., the computing device 110) to execute the code. This will be described in detail below and will not be repeated here.
[0116] The computing device 120 may be implemented in hardware. For example, the computing device 120 may be a server or other hardware device. The computing device 120 may also be implemented in software. For example, the computing device 120 may be a virtual machine, a container, or a process.
[0117] Figure 4 shows a possible structure of the system architecture 100 when it is applied in the field of server-unaware computing. As shown in Figure 4, the computing device 120 and the computing device 110 can form an execution server for executing code. Among them, the system architecture 100 may include multiple execution servers (not shown). The system architecture 100 also includes a computing device 130. The computing device 130 can manage the execution server and receive the code uploaded by the user, that is, the server-unaware computing code. Then, according to the status of the execution server, such as the load size, the execution server for executing the code is selected.
[0118] The computing device 130 may be implemented in hardware. For example, the computing device 130 may be a server or other hardware device. The computing device 130 may also be implemented in software. For example, the computing device 130 may be a virtual machine, a container, or a process.
[0119] In some embodiments, system architecture 100 can be implemented as a function as a service (FaaS) platform. In one example, the FaaS platform can be OpenWhisk, an open source FaaS platform. Computing device 130 serves as the FaaS platform controller, computing device 120 serves as the FaaS platform caller, and computing device 110 serves as the FaaS platform executor.
[0120] In one example, computing device 130 runs the Controller and LoadBalancer components of the OpenWhisk framework, enabling computing device 130 to function as a FaaS platform controller. Computing device 120 runs the OpenWhisk Invoker, enabling computing device 130 to function as a FaaS platform caller. The language runtime 200 in computing device 110 can be modified from the Oracle Hotspot VM JVM, enabling the JVM to support the code execution solution provided in the embodiments of this application. Furthermore, computing device 110 utilizes the Linux operating system, enabling performance isolation between computing instances through control groups and the like.
[0121] The above example introduces a system architecture 100 that can be used to implement the code execution solution provided by the embodiment of the present application. Next, the process of the code execution solution provided by the embodiment of the present application is introduced in conjunction with the system architecture 100. As shown in Figure 5, the solution can include the following steps.
[0122] After the language runtime 200 is started, the manager 210 in the language runtime may execute step 501 to create a shared metadata repository 240 .
[0123] In step 501, metadata of a public class may be added to the shared metadata repository 240. The metadata of a public class may include at least one of class metadata of the public class, just-in-time compiled code of the public class, and initialized values of class static variables of the public class. A public class may be multiple classes, i.e., there may be multiple public classes.
[0124] As mentioned above, class metadata is used to identify which classes data belongs to, particularly the classes to which the values of class static variables belong. Sharing class metadata for public classes allows for faster access to public class metadata during code execution, enabling faster identification of data belonging to public classes. This further reduces code execution time and improves code execution efficiency.
[0125] The just-in-time compiled code of a public class can improve the execution efficiency of the public class and the execution efficiency of the code containing the public class.
[0126] The entire duration of code execution is mainly affected by the initialization of the class static variables of the code class. Therefore, the initialization values of the class static variables of the public class are added to the shared metadata library 240, so that when the code is executed, the initialization values of the class static variables of the public class can be obtained, thereby skipping the initialization of the class static variables of the public class, reducing the execution time of the code, and improving the code execution efficiency.
[0127] In some embodiments, in step 501, general code including a public class may be executed to initialize the class static variables of the public class and obtain the initialization values of the class static variables of the public class. The general code is contentless, and after completing the initialization of the class static variables of the public class, the execution of the general code will not contaminate the initialization values of the class static variables of the public class. Exemplarily, the contentless general code may be provided by the platform to which the computing device 110 belongs. In one example, the computing device 110 belongs to a FaaS platform, and the general code is a contentless general empty function provided by the FaaS platform.
[0128] The manager 210 may execute step 502 to receive at least one code and an execution request for the at least one code. For example, the at least one code and the execution request for the at least one code may be sent from the computing device 120 to the computing device 110 .
[0129] The at least one code includes code A1, and the execution request of the at least one code includes the execution request of code A1. Next, taking code A1 as an example, a code execution solution is introduced.
[0130] The manager 210 may execute step 503 to determine whether the computing device 110 has saved the metadata in the execution data of the code A1.
[0131] As mentioned above, code execution data refers to the data involved in code execution, including data generated, obtained, and modified during code execution. Metadata within execution data refers to data that can be used to re-execute the code and improve its efficiency when it is re-executed.
[0132] The metadata in the execution data of code A1 may include the values of class static variables of the class of code A1. If the initialization value of the class static variable is modified during a particular execution of code A1, the value of the class static variable in the metadata in the execution data of that execution is the modified value. If the initialization value of the class static variable is not modified during a particular execution of code A1, the value of the class static variable in the metadata in the execution data of that execution is the initialization value of the class static variable.
[0133] In some embodiments, the metadata in the execution data of code A1 may further include class metadata of the class of code A1. In some embodiments, the metadata in the execution data of code A1 may further include just-in-time compiled code of code A1.
[0134] When the judgment result of step 503 is no, that is, when the computing device 110 does not save the metadata in the execution data of code A1, the manager 210 can create a computing instance 221 in the language runtime 200, and execute code A1 in the computing instance 221 in combination with the metadata of the classes in the collection A11.
[0135] Creating the computing instance 221 may specifically include: creating a thread group and a private space for the computing instance 221, as well as creating a private control group, a virtual network card, and a security point for the computing instance 221. For details, please refer to the above introduction and will not be repeated here.
[0136] The set A11 is the intersection of the classes in code A1 and the classes in shared metadata repository 240. During or before the execution of code A1, the metadata of the classes in code A1 can be queried in shared metadata repository 240 and copied to the private space of computing instance 221 as the metadata of the class.
[0137] Among them, the metadata may include at least one of the class metadata of the public class, the just-in-time compiled code of the public class, and the initialization value of the class static variable of the public class. In one example, taking the initialization value of the class static variable as an example, during the execution of code A1, when it is necessary to perform class static initialization of a certain class, the static initialization value of the class can be queried in the shared metadata database 240. If the initialization value of the class static variable of the class is queried, the initialization value of the class static variable of the class in the shared metadata database 240 can be copied as copy data to the private space of the computing instance 221. The copied data of the private space of the computing instance 221 can be set as the initialization value of the class static variable of the class, so that the initialization of the class static variable of the class can be skipped and the subsequent execution process of code A1 can be started, thereby improving the execution efficiency of code A1.
[0138] If the initialization value of the class static variable of the class is not found, the initialization of the class static variable of the class is performed normally in the calculation instance 221, and the code is executed normally.
[0139] When the judgment result of step 503 is yes, that is, when the computing device 110 saves the metadata in the execution data of code A1, the manager 210 can execute step 504b, create a computing instance 221 in the language runtime 200, and execute code A1 in the computing instance 221 in combination with the metadata in the execution data.
[0140] At step 504b, private space may be allocated for compute instance 221. The metadata in the execution data stored by computing device 110 is then copied to the private space of compute instance 221. The values of the class static variables of the copied class may be set to the values of the static variables of the corresponding class in code A1, thereby skipping the initialization of the class static variables of code A1. A thread group may be allocated to compute instance 221, and this thread group executes code A1 in compute instance 221.
[0141] In some embodiments, when code A1 is executed in the computing instance 221, the manager 210 can execute step 505 to determine whether code A1 belongs to a code chain. The code chain can also be called a function chain, which refers to a chain composed of multiple codes with execution dependencies. Developers can develop multiple codes and call them in sequence in the form of a chain to form a code chain. The dependency relationship of the code means that the execution result of one code is the execution parameter of the next code of the code. The next code of code A1 refers to the code that is adjacent to code A1 in the code chain and whose execution time is after code A1. For the convenience of description, the next code of code A1 can be set to code A2. The execution parameters of the code refer to the data required for the execution of the code.
[0142] When code A1 belongs to a code chain, step 506 can be executed to transfer data by means of memory copy. Specifically, the private space of the computing instance includes a private memory space. In step 506, the return value of code A1 can be copied from the memory space of the computing instance 221 to the memory space of the computing instance where the next code of code A1 (i.e., code A2) is located. More specifically, in the case where code A1 belongs to a code chain, the computing device 120 can notify the manager 210 of the chain relationship of the code chain to which code A1 belongs. The manager 210 can create computing instances for all codes on the code chain in parallel. Among them, the memory space addresses of the computing instances created for adjacent codes on the code chain are adjacent, thereby facilitating memory copying.
[0143] Communication between computing instances is performed through memory copying, which greatly reduces the communication overhead between computing instances.
[0144] After the return value of code A1 is copied to the memory space of the computing instance where code A2 is located, the manager 210 may notify the thread group of the computing instance where code A2 is located to start executing code A2 using the copied return value of code A1 as an execution parameter.
[0145] In one example, code A1 is Java language code, and the data format of the return value of code A1 is a Java object. In one example of this example, the class metadata of the Java object of the return value of code A1 may be the private class metadata of the computing instance 221. The thread group of the computing instance where code A2 is located may not be able to identify the class to which the return value of code A1 belongs. The manager 210 can identify the private class metadata of each computing instance. In order to solve the problem that the thread group of the computing instance where code A2 is located does not identify the class to which the return value of code A1 belongs, the manager 210 can instruct the thread group of the computing instance where code A2 is located to load the class to which the return value Java object belongs, so that code A2 can identify the class to which the return value of code A1 belongs.
[0146] In one example, the execution result of code A1 includes multiple return values, and the user can select at least one return value from the multiple return values as an execution parameter of the next code of code A1.
[0147] 5 , when the code A1 is executed completely in the computing instance 221 , the manager 210 may execute step 507 to save the metadata in the execution data involved in step 504 .
[0148] Steps 504a and 504b shown in FIG5 can be collectively referred to as step 505. Metadata associated with the data involved in the execution of code A1 in step 505, i.e., metadata associated with the data involved in the execution of code A1 in computing instance 221, can be saved. The metadata includes the values of class static variables of the class of code A1. Exemplarily, the metadata includes class metadata and / or just-in-time compiled code of code A1.
[0149] Saving metadata from the data involved in executing code A1 in computing instance 221 can specifically involve copying the metadata from the private space of computing instance 221 to metadata storage area 230. Metadata storage area 230 is located outside computing instance 221. Therefore, when computing instance 221 is deleted or its resources are released, the metadata can be preserved in metadata storage area 230. Storage area 230 is located in computing device 110, so the storage of metadata in metadata storage area 230 can also be referred to as computing device 110 preserving the metadata.
[0150] In some embodiments, if code A1 is Java language code, the values of the class static variables of code A1's class are located in the private space of compute instance 221. Therefore, in step 507, the values of the class static variables of code A1's class are copied to metadata storage area 230. The class metadata and just-in-time compiled code of code A1 are located in the metaspace. Deleting compute instance 221 does not affect the data in the metaspace, so there is no need to copy the class metadata and just-in-time compiled code of code A1 to metadata storage area 230.
[0151] While, before, or after saving the metadata in the data involved in the execution of the code A1 in the computing instance 221 , ordinary data in the data involved in the execution of the code A1 in the computing instance 221 may be deleted.
[0152] After saving the metadata of the data involved in the execution of code A1 in computing instance 221, the resources occupied by computing instance 221, such as thread groups, storage space, etc., can be released. Releasing computing instance 221 can also be called deleting computing instance 221.
[0153] In some embodiments, metadata storage area 230 is specifically an area in memory. Before executing step 507, it can be determined whether the memory resources of computing device 110 are limited. If so, step 507 is executed. If not, all data involved in the execution of code A1 in computing instance 221 can be saved, and the resources occupied by computing instance 221 are not released.
[0154] In some embodiments, as described above, code A1 is high-level language code. The execution of code A1 can be configured to require the invocation of machine language code, that is, native code. For example, Java language code calls machine language code via JNI. High-level language code is interpreted or compiled by the language runtime, and therefore its execution is fully controlled by the language runtime. Machine language code, on the other hand, executes directly on the processor and is not controlled by the language runtime.
[0155] As shown in Figure 6, in this embodiment, to isolate the execution of machine language code from the execution of high-level language code, a high-level isolation environment is created for the machine language code, that is, a highly isolated computing instance is created. Specifically, this highly isolated computing instance can be a container or a virtual machine. The machine language code is then run in the highly isolated computing instance, thereby ensuring isolation between the execution of the machine language code and the execution of the high-level language code.
[0156] Specifically, when the execution of code A1 includes a local call (i.e., the execution of code A1 requires calling machine language code), computing device 120 may notify manager 210 of the inclusion of the local call. When manager 210 creates computing instance 221, it may create a highly isolated computing instance.
[0157] In one example, a communication module and an executor for executing machine language code can be created in a highly isolated computing instance. The communication module and the computing instance 221 can perform inter-process communication, and the communication module and the executor can perform intra-process communication. The manager 210 can record the correspondence between the computing instance 221 and the highly isolated computing instance to obtain a one-to-one mapping table. When code A1 is executed in the computing instance 221 and the machine language code needs to be called, the computing instance 221 can query the mapping table to obtain the computing instance where the machine language code is located. Then, the computing instance 221 can exchange information with the computing instance communication module where the machine language code is located through inter-process communication, and the communication module can exchange information with the executor of the computing instance where the machine language code is located through intra-process communication, thereby realizing the call of the machine language code by code A1.
[0158] The communication module may be a lightweight communication module. Specifically, the memory occupied by the communication module during operation is less than 10 KB.
[0159] In one example, the communication module can perform inter-process communication with the computing instance 221 through a socket.
[0160] The code execution scheme provided by the embodiment of the present application, after the code execution is completed, only the metadata that affects the efficiency of code execution again (such as the value of the static variable of the class of the code) in the data generated when the code is executed is saved, and other data is deleted, thereby reducing the overhead of storage resources, and being able to store the metadata of more codes, so that all or most of the metadata of the code that needs to be executed again is saved. Secondly, the embodiment of the present application provides the initialization values of the static variables of multiple classes. When the code is executed for the first time, the initialization values of the static variables of the class of the code can be obtained from the initialization values of the static variables of the multiple classes, so that the initialization of the static variables of the class can be skipped, shortening the execution time of the code and improving the efficiency of the first execution of the code. Moreover, the communication between the computing instances where the code is located can be achieved by memory copying, reducing the overhead of communication between computing instances. And, the embodiment of the present application places the machine language code that the high-level language code needs to call into a container or virtual machine outside the high-level language code execution environment for execution, achieving effective isolation between the high-level language code and the machine language code. In addition, the embodiment of the present application isolates the performance and function of the computing instances used to execute different codes, improving the isolation between different computing instances.
[0161] Next, the effects of the code execution solution provided in this application are compared with those of other code execution solutions.
[0162] Code execution solution D1: This solution is implemented using solution 1 described above. Specifically, a container called the application container engine (Docker) is used as a computing instance, and the FaaS platform OpenWhisk is run in the computing instance to execute the code.
[0163] Code execution solution D2: This solution is implemented using solution 1 described above. Specifically, Firecracker, a lightweight virtual machine, is used as a computing instance, and the OpenWhisk FaaS platform is run in this computing instance to execute the code.
[0164] Code execution solution D3: This solution is implemented using solution 2 described above. Specifically, the sandbox provided by the open source Dragonwell JVM is used as the computing instance, and the OpenWhisk FaaS platform is run in this computing instance to execute the code.
[0165] Code execution solution D3: It is implemented using the code execution solution provided in the embodiment of the present application. Specifically, the language runtime 200 in the computing device 110 is modified based on the JVM of Oracle Hotspot VM. This modification enables the JVM to support the code execution solution provided in the embodiment of the present application; and the computing device 110 adopts the Linux operating system, so that performance isolation between computing instances can be achieved through control groups, etc.
[0166] The above code execution scheme executes the code time, code sort, code hash, code resize, code imgpipe, code specjbb, code hotel, and code mapreduce, respectively. Code time, code sort, code hash, code resize, code imgpipe, code specjbb, code hotel, and code mapreduce are each server-aware functions. Code imgpipe, code specjbb, code hotel, and code mapreduce form a code chain, comprising multiple codes. For ease of description, in the following description, a code chain as a whole may also be referred to as code.
[0167] The execution status of each code execution scheme for the above codes is shown in Figures 7 to 9.
[0168] Among them, the execution time of each code execution scheme to execute the above codes is shown in Figure 7. Among them, the horizontal axis is the executed code, and the vertical axis is the code execution time. It can be seen that compared with schemes D1 and D2, for most codes, the execution time of scheme D4 is shorter (that is, more efficient). Specifically, compared with the execution efficiency of scheme D1, the execution efficiency of scheme D4 is increased by an average of 6.66 times. Compared with the execution efficiency of scheme D2, the execution efficiency of scheme D4 is increased by an average of 5.08 times. In addition, compared with scheme D3, scheme D4 can achieve similar or faster execution efficiency when executing most codes while achieving higher isolation. In addition, for codes that need to call local code (that is, resize and imgpipe), scheme D4 achieves isolation similar to schemes D1 and D2.
[0169] The number of saved codes for each code execution scheme is shown in Figure 8. The horizontal axis is the executed code, and the vertical axis is the number of saved codes when using 64GB of memory. Save here means save in memory. For code execution schemes D1 and D3, the number of saved codes refers to the number of codes that save the execution data; for code execution scheme D4, the number of saved codes refers to the number of codes that save the metadata in the execution data. As shown in Figure 8, compared with schemes D1 and D3, for a single code, scheme D4 significantly reduces the memory overhead. Specifically, the average number of saved codes for scheme D4 under multiple codes is 33.03 times the average number of saved codes for scheme D1, and 24.19 times the average number of saved codes for scheme D3. In addition, as mentioned above, scheme D4 saves the metadata in the execution data, and the execution efficiency of re-executing the code using the metadata is similar to the execution efficiency of re-executing the code using the execution data.
[0170] Figure 9 shows the communication overhead of various code execution schemes when executing code within a code chain. Communication overhead is represented by the total communication duration during code execution; longer durations indicate higher overhead. Total communication duration refers solely to the time consumed by communication, not the total execution time of the code. The horizontal axis represents the name of the code chain, while the vertical axis represents the total communication duration between compute instances containing different codes within the code chain. Compared to schemes D1 and D3, scheme D4 communicates directly through memory copying, eliminating the need for network transmission or passing through the FaaS platform control or caller, significantly reducing communication time. Specifically, across multiple code chains, the average total communication duration of scheme D1 is 23.63 times that of scheme D4, and the average total communication duration of scheme D3 is 22.60 times that of scheme D4.
[0171] From this, we can see that solution D4 significantly reduces the overhead of storage resources and can store more code metadata, so that the metadata of all or most of the code that needs to be executed again can be maintained, thereby reducing storage overhead while improving code execution efficiency.
[0172] Based on the code execution scheme described above, an embodiment of the present application further provides a code execution method. The method is applied to a computing device. As shown in FIG10 , the method includes the following steps.
[0173] Step 1001: Receive a first code and an execution request for the first code, wherein the execution request is used to request the computing device to execute the first code. For details, please refer to the above description of step 502 in FIG. 5 , which will not be repeated here.
[0174] Step 1003: Create a first computing instance in the computing device and execute the first code in the first computing instance. Detailed implementation can be found in the above description of step 504 in FIG. 5 , which will not be repeated here.
[0175] Step 1005: After the first code is executed in the first computing instance, the first computing instance is released, the first data is saved, and the second data is deleted; the first data is a part of the data involved when the first code is executed in the first computing instance, and the second data is the data other than the first data involved when the first code is executed in the first computing instance; wherein, the first data includes the value of the class static variable of the class of the first code; the value of the class static variable is used to skip the initialization of the class static variable when the first code is executed again in the computing device. For details, please refer to the above description of step 507 in Figure 5 and the metadata in the execution data, which will not be repeated here.
[0176] In some embodiments, the first code is a Java language code, and the first computing instance is a sandbox in a Java virtual machine.
[0177] In some embodiments, the first data further includes class metadata, where the class metadata is used to indicate the class to which the class static variables in the first data belong; and / or, the first data further includes just-in-time compiled code of the first code.
[0178] In some embodiments, executing the first code in the computing instance includes: before executing the first code, querying data stored by the computing device for a value of a class static variable of the class of the first code; and if the value of the class static variable of the class of the first code is found, skipping initialization of the class static variable during execution of the first code. For details, please refer to the above description of step 504b in Figure 5 and will not be repeated here.
[0179] In some embodiments, the computing device stores initialization values for static variables of multiple classes; executing the first code in the computing instance includes: querying the multiple classes for a class of the first code to obtain a first class; and during execution of the first code, obtaining initialization values for static variables of the first class from the initialization values for static variables of the multiple classes, thereby skipping initialization of the static variables of the first class. For details, please refer to the above description of step 504a in Figure 5 and will not be repeated here.
[0180] In some embodiments, the execution result of the first code is used as an execution parameter for a second code, wherein the second code is executed in a second computing instance in the computing device. The method further includes copying the execution result of the first code from the memory of the first computing instance to the memory of the second computing instance. For details, please refer to the above description of step 506 in Figure 5 and will not be repeated here.
[0181] In some embodiments, the first code is a high-level language code, and execution of the first code requires calling a machine language code. The method further includes: receiving a machine language code and an execution request for the machine language code, the execution request being used to request the computing device to execute the machine language code; creating a third computing instance in the computing device, the third computing instance being a container or a virtual machine; and executing the machine language code in the third computing instance. For details, please refer to the above description of the embodiment shown in Figure 6 and will not be repeated here.
[0182] In some embodiments, the computing device includes multiple computing instances, each of which is used to execute different codes; wherein the functional modules of the different computing instances are independent of each other; wherein the functional modules are one or a combination of any number of the following: a code executor, a memory space, a safe point, a garbage collector, and a JIT compilation thread. For details, please refer to the above description of the embodiment shown in Figure 3 and will not be repeated here.
[0183] After code execution is completed, the code execution method provided by the embodiment of the present application only saves metadata such as the values of class static variables that affect the efficiency of code re-execution from the data generated during code execution, while deleting other data and releasing the computing instance. This reduces the overhead of storage resources and can save metadata for more codes. As a result, when more codes are executed again, metadata such as the values of class static variables saved by the computing device can be obtained, and the initialization of class static variables of the class can be skipped, thereby improving the execution efficiency of the code.
[0184] The present application also provides a code execution device. The execution device is configured in a computing device, such as computing device 110. The execution device includes functional units for implementing the method shown in FIG10. Referring to FIG11, the execution device may include the following functional units.
[0185] A receiving unit 1110 is configured to receive a first code and an execution request for the first code, wherein the execution request is used to request the computing device to execute the first code;
[0186] an execution unit 1120, configured to create a first computing instance in the computing device and execute the first code in the first computing instance;
[0187] Storage unit 1130 is configured to release the first computing instance, save the first data, and delete the second data after the first code completes execution in the first computing instance; the first data is a portion of the data involved in the execution of the first code in the first computing instance, and the second data is the data involved in the execution of the first code in the first computing instance other than the first data;
[0188] The first data includes the value of a class static variable of the class of the first code; the value of the class static variable is used to skip initialization of the class static variable when the first code is executed again in the computing device.
[0189] The above mainly introduces the device provided by the embodiment of the present application from the perspective of the method flow. It is understandable that, in order to implement the above functions, each terminal includes a hardware structure and / or software module corresponding to the execution of each function. Those skilled in the art should easily appreciate that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in a hardware or computer software driven hardware manner depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0190] Referring to FIG. 12 , an embodiment of the present application provides a computing device 1200 . Computing device 1200 may include a processor 1210 and a memory 1220 . Memory 1220 stores instructions that are executable by processor 1210 . When processor 1210 executes these instructions, computing device 1200 may execute the solution shown in FIG. 5 or the method shown in FIG. 10 .
[0191] It is understood that the processor in the embodiments of the present application may be a central processing unit (CPU), or may be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.
[0192] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.
[0193] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted via the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can 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 drive (SSD)).
[0194] It will be understood that the various numerical numbers involved in the embodiments of the present application are merely distinctions for the convenience of description and are not intended to limit the scope of the embodiments of the present application.
Claims
1. A code execution method, characterized in that: Applied to a computing device, the method includes: receiving a first code and an execution request for the first code, wherein the execution request is used to request the computing device to execute the first code; Creating a first computing instance in the computing device, and executing the first code in the first computing instance; After the first code is executed in the first computing instance, the first computing instance is released, the first data is saved, and the second data is deleted; the first data is a portion of the data involved in the execution of the first code in the first computing instance, and the second data is the data involved in the execution of the first code in the first computing instance other than the first data; The first data includes the value of a class static variable of the class of the first code; the value of the class static variable is used to skip initialization of the class static variable when the first code is executed again in the computing device.
2. The method according to claim 1, characterized in that The first code is a Java language code, and the first computing instance is a sandbox in a Java virtual machine.
3. The method according to claim 1 or 2, characterized in that The first data further includes class metadata, where the class metadata is used to indicate the class to which the class static variable in the first data belongs; and / or, The first data also includes a just-in-time compiled code of the first code.
4. The method according to any one of claims 1 to 3, characterized in that Executing the first code in the computing instance includes: Before executing the first code, querying the data stored in the computing device for a value of a class static variable of the class of the first code; In a case where a value of a class static variable of a class of the first code is queried, initialization of the class static variable is skipped during execution of the first code.
5. The method according to any one of claims 1 to 3, characterized in that The computing device stores initialization values of static variables of multiple classes; Executing the first code in the computing instance includes: Searching for a class of the first code in the multiple classes to obtain a first class; During execution of the first code, initialization values of static variables of a first class are obtained from initialization values of static variables of the plurality of classes, so as to skip initialization of the static variables of the first class.
6. The method according to any one of claims 1 to 5, characterized in that The execution result of the first code is used as an execution parameter of the second code, wherein the second code is executed in the second computing instance in the computing device; the method also includes: copying the execution result of the first code from the memory of the first computing embodiment to the memory of the second computing instance.
7. The method according to any one of claims 1 to 6, characterized in that The first code is a high-level language code, and execution of the first code requires calling a machine language code. The method further includes: receiving a machine language code and an execution request for the machine language code, wherein the execution request is used to request the computing device to execute the machine language code; Creating a third computing instance in the computing device, where the third computing instance is a container or a virtual machine; In the third computing instance, the machine language code is executed.
8. The method according to any one of claims 1 to 7, characterized in that The computing device includes multiple computing instances, different computing instances are used to execute different codes; wherein the functional modules of different computing instances are independent of each other; wherein the functional modules are one or a combination of any multiple of a code executor, a memory space, a safe point, a garbage collector, and a JIT compilation thread.
9. A code execution device, characterized in that: Configured in a computing device, the execution device includes: a receiving unit, configured to receive a first code and an execution request for the first code, wherein the execution request is used to request the computing device to execute the first code; an execution unit, configured to create a first computing instance in the computing device and execute the first code in the first computing instance; a storage unit, configured to release the first computing instance, save the first data, and delete the second data after the first code is executed in the first computing instance; the first data being a portion of the data involved in the execution of the first code in the first computing instance, and the second data being the data involved in the execution of the first code in the first computing instance other than the first data; The first data includes the value of a class static variable of the class of the first code; the value of the class static variable is used to skip initialization of the class static variable when the first code is executed again in the computing device.
10. The execution device according to claim 9, characterized in that: The first code is a Java language code, and the first computing instance is a sandbox in a Java virtual machine.
11. The execution device according to claim 9 or 10, characterized in that: The first data further includes class metadata, where the class metadata is used to indicate the class to which the class static variable in the first data belongs; and / or, The first data also includes a just-in-time compiled code of the first code.
12. The execution device according to any one of claims 9 to 11, characterized in that: The execution unit is further configured to: Before executing the first code, querying the data stored in the computing device for a value of a class static variable of the class of the first code; In a case where a value of a class static variable of a class of the first code is queried, initialization of the class static variable is skipped during execution of the first code.
13. The execution device according to any one of claims 9 to 11, characterized in that: The computing device stores initialization values of static variables of multiple classes; the execution unit is further configured to: Searching for a class of the first code in the multiple classes to obtain a first class; During execution of the first code, initialization values of static variables of a first class are obtained from initialization values of static variables of the plurality of classes, so as to skip initialization of the static variables of the first class.
14. The execution device according to any one of claims 9 to 13, characterized in that: The execution result of the first code is used as an execution parameter of the second code, wherein the second code is executed in the second computing instance in the computing device; the execution device also includes a copy unit for copying the execution result of the first code from the memory of the first computing embodiment to the memory of the second computing instance.
15. The execution device according to any one of claims 9 to 14, characterized in that: The first code is a high-level language code, and execution of the first code requires calling a machine language code; The receiving unit is further configured to: receive a machine language code and an execution request for the machine language code, wherein the execution request is configured to request the computing device to execute the machine language code; The execution unit is further configured to: Creating a third computing instance in the computing device, where the third computing instance is a container or a virtual machine; In the third computing instance, the machine language code is executed.
16. The execution device according to any one of claims 9 to 15, characterized in that: The computing device includes multiple computing instances, different computing instances are used to execute different codes; wherein the functional modules of different computing instances are independent of each other; wherein the functional modules are one or a combination of any multiple of a code executor, a memory space, a safe point, a garbage collector, and a JIT compilation thread.
17. A computing device, characterized in that The system comprises a processor and a memory; the memory is used to store a computer program; the processor is used to execute the computer program to implement the method according to any one of claims 1 to 8.
18. A computer storage medium, characterized in that The computer storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
19. A computer program product, characterized in that The method comprises a program for implementing the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Allocation method and device of static storage
CN102096638A
Code static detection method
CN104965788A
Event processing method based on buried points, electronic equipment and computer storage medium
CN110515821A
Code loading method, device and system under Serverless architecture and storage medium
CN113282377A
Code execution method and device
CN113568681A