A code execution method and device

By selecting matching containers to execute code based on the code file attributes, the problems of waste of resources and unreasonable scheduling in the existing technology are solved, and more efficient resource utilization and scheduling are achieved.

CN119781778APending Publication Date: 2025-04-08SHANGHAI XIYU TECHNOLOGY CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510272213.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-10
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

In the prior art, fixed and same resources are allocated to each code during code execution, resulting in waste of resources and unreasonable scheduling.

Method used

By detecting code execution requests, obtaining attributes of the code file to be executed, and selecting a matching container from the candidate container as the target container based on these attributes, executing code based on the target container, improving the rationality of resource scheduling.

Benefits of technology

It effectively reduces resource waste, improves the rationality of resource scheduling, and ensures the satisfaction of code execution requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781778A_ABST
    Figure CN119781778A_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a code execution method and device. The method includes: if a code execution request is detected, obtaining a code file to be executed; according to the attributes of the code file to be executed, selecting a container that matches the attributes of the code file to be executed from candidate containers as a target container; wherein the candidate containers include at least two containers with different attributes, and each container is isolated from each other; executing the code file to be executed based on the target container, obtaining and outputting the code execution result. The technical solution can match containers with matching attributes for different code requirements, and use the resources associated with the container to execute the corresponding code, thereby improving the rationality of resource scheduling and effectively reducing resource waste on the basis of meeting the code execution requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of compilation technology, and in particular to a code execution method and device. Background Art

[0002] With the continuous development of compilation technology, the demand for code execution is increasing. In the related art, fixed and identical resources are usually allocated to each code that needs to be run for code execution. However, the resources used to execute code are limited. If the same resources are allocated to different code running requirements, when the code running requirements are small, the fixed resources will be wasted; and when the code running requirements are large, the fixed resources are not enough to execute the code, resulting in the inability to achieve the desired effect of the user, which is not conducive to resource scheduling. Summary of the invention

[0003] The present invention provides a code execution method and device, which can match containers with matching attributes according to different code requirements, and use resources associated with the containers to execute corresponding codes, thereby improving the rationality of resource scheduling and effectively reducing resource waste on the basis of meeting code execution requirements.

[0004] According to one aspect of the present invention, a code execution method is provided, the method comprising:

[0005] If a code execution request is detected, the code file to be executed is obtained;

[0006] According to the attribute of the code file to be executed, a container matching the attribute of the code file to be executed is selected from candidate containers as a target container; wherein the candidate containers include at least two containers with different attributes, and each container is isolated from each other;

[0007] The to-be-executed code file is executed based on the target container, and a code execution result is obtained and output.

[0008] According to another aspect of the present invention, there is provided a code execution device, the device comprising:

[0009] A module for acquiring code files to be executed, used to acquire code files to be executed if a code execution request is detected;

[0010] a target container determination module, configured to select, according to the attributes of the code file to be executed, a container matching the attributes of the code file to be executed from candidate containers as a target container; wherein the candidate containers include at least two containers with different attributes, and each container is isolated from each other;

[0011] The code execution result determination module is used to execute the to-be-executed code file based on the target container, and obtain and output the code execution result.

[0012] The technical solution of the embodiment of the present invention, when a code execution request is detected, first obtains the code file to be executed; then, according to the attributes of the code file to be executed, selects a container that matches the attributes of the code file to be executed from the candidate containers as the target container; wherein the candidate containers include at least two containers with different attributes, each of which is isolated from each other; then, the code file to be executed is executed based on the target container, and the code execution result is obtained and output. This technical solution can match containers with matching attributes for different code requirements, and use the resources associated with the container to execute the corresponding code, thereby improving the rationality of resource scheduling and effectively reducing resource waste on the basis of meeting the code execution requirements.

[0013] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0015] Figure 1 is a flowchart of a code execution method provided according to Embodiment 1 of the present invention;

[0016] Figure 2 is a flowchart of a code execution method provided according to Embodiment 2 of the present invention;

[0017] Figure 3 is a schematic diagram of the structure of a code execution device provided according to Embodiment 3 of the present invention;

[0018] Figure 4 It is a structural schematic diagram of an electronic device for implementing a code execution method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0019] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0020] It should be noted that the terms "first", "second", "target", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0021] Embodiment 1

[0022] Figure 1 This is a flowchart of a code execution method provided in Embodiment 1 of the present invention. This embodiment is applicable to the case where a container suitable for adapting memory is used for code execution. The method can be executed by a code execution device, which can be implemented in the form of hardware and / or software. The code execution device can be configured in an electronic device with data processing capabilities. Figure 1 As shown, the method includes:

[0023] S110: If a code execution request is detected, a code file to be executed is obtained.

[0024] Among them, the code execution request can be used to request the execution of the code contained in the code file to be executed. The code file to be executed may refer to a file containing the required execution code waiting to be executed. Exemplarily, the code file to be executed may be a code file transmitted through a preset file transfer interface, or it may be a code file generated by an artificial intelligence model according to the code prompt information provided in a preset interactive interface. Among them, the code prompt information can be used to guide the artificial intelligence model to generate the code to be executed. For example, the code prompt information can be expressed in the form of text, instructions, questions, files or scenario descriptions.

[0025] Among them, the artificial intelligence model can be an NLP (Natural Language Processing) model, an LLM (Large Language Model), an AIGC (Artificial Intelligence Generated Content) model, or a GPT (Generative Pre-Trained) model, etc. This embodiment does not specifically limit the type and structure of the artificial intelligence model.

[0026] For example, when a user uploads a file containing a large amount of data to the artificial intelligence model, the artificial intelligence model is required to perform data analysis on the content of the file and output the corresponding data analysis results; or, when a user inputs the instruction "draw a world map" to the artificial intelligence model, the artificial intelligence model receives the corresponding file and / or instruction and needs to generate the corresponding code to meet the user's needs. After the artificial intelligence model forms the corresponding code, it will send a code execution request to the code execution device.

[0027] In this embodiment, when a code execution request is detected, a code file to be executed is first obtained, which is transmitted through a preset file transfer interface or generated by an artificial intelligence model according to code prompt information provided in a preset interactive interface. The code file to be executed includes the code to be executed.

[0028] S120, according to the attributes of the code file to be executed, select a container that matches the attributes of the code file to be executed from the candidate containers as a target container; wherein the candidate containers include at least two containers with different attributes, and each container is isolated from each other.

[0029] Among them, the attributes of the code file to be executed can be used to match the target container with the matching attributes, so that the code in the code file to be executed can be subsequently executed based on the target container with the matching attributes. Specifically, the attributes of the code file to be executed may include the file's own attributes and the code running attributes. Exemplarily, the file's own attributes may include the file's name, source, size, and content, etc.; the code running attributes may include the running resource requirements corresponding to the code execution. For example, the running resource requirements may include the running computing power requirements, the running memory requirements, and the running result storage requirements, etc.

[0030] Among them, the container can be used to execute code. The candidate container may refer to a container including at least two different attributes that can be selected for code execution requirements, each container is isolated from each other, and the container of each attribute can be set to one or more, which can be set according to actual needs. For example, container attributes may include but are not limited to container size, network configuration, and resource restrictions. Exemplarily, the candidate container may include a first container, a second container, and a third container, and the first container, the second container, and the third container have different sizes. The target container may refer to a container selected from the candidate containers for executing code in the code file to be executed.

[0031] In this embodiment, after obtaining the code file to be executed, the size of the running resources required to execute the code can be estimated according to the attributes of the code file to be executed (such as the code content in the file and / or the running resource requirements corresponding to the code execution), the estimated running resource size is used as the predicted container size, and a container with a matching size is determined from the candidate containers as the target container according to the predicted container size. Optionally, determining a container with a matching size from the candidate containers as the target container according to the predicted container size includes: selecting a container with the smallest difference in size with the predicted container from the candidate containers that are not smaller than the predicted container size as the target container.

[0032] It is understandable that in order to meet the code execution requirements, the size of the selected target container must be greater than or equal to the predicted container size, otherwise sufficient resources cannot be provided to support code execution; in addition, under the premise of meeting the code execution requirements, in order to avoid the problem of resource waste caused by an overly large container, the size of the selected target container needs to have a minimum difference with the predicted container size, and at this time the size of the target container is closest to the predicted container size.

[0033] Through the above settings, a smaller container can be matched for codes with smaller code execution requirements, thereby leaving more memory resources for codes with larger code execution requirements. This can reduce resource waste while meeting code execution requirements and achieve better memory resource control.

[0034] In this embodiment, the candidate containers are optionally stored in a queue form; accordingly, according to the attributes of the code file to be executed, a container matching the attributes of the code file to be executed is selected from the candidate containers as the target container, including: according to the attributes of the code file to be executed, a container queue matching the attributes is matched from the candidate container queue as the target container queue, the candidate container queue includes at least two container queues with different attributes, each container queue includes a plurality of containers with the same attributes, and each container queue meets the first-in-first-out principle.

[0035] In this embodiment, candidate containers are stored in the form of queues. Among them, multiple containers can be set in the queue, and each queue follows the first-in-first-out principle. Specifically, in this embodiment, a candidate container queue is set, and the candidate container queue includes at least two container queues with different attributes, each container queue contains several containers with the same attributes, and each container queue satisfies the first-in-first-out principle. Exemplarily, taking the container size as the container attribute, the candidate container queue includes at least two container queues of different sizes, and each container queue contains several containers of the same size. That is to say, containers of the same size are stored in the same container queue, that is, containers of different sizes are stored in different container queues. Exemplarily, if a total of three different sizes of containers of the first size, the second size and the third size are included, the candidate container queue includes a first container queue, a second container queue and a third container queue (more queues can be arranged according to actual needs), wherein the first container queue is used to store containers of the first size, the second container queue is used to store containers of the second size, and the third container queue is used to store containers of the third size.

[0036] In this embodiment, when determining the target container, a container queue with matching attributes can be matched from the candidate container queue according to the attributes of the code file to be executed as the target container queue, and then the container at the head position in the target container queue is used as the target container. It should be noted that since each container queue satisfies the first-in-first-out principle, that is, each container queue is a first-in-first-out FIFO queue, when the code needs to be executed, the first container can be directly called from the target container queue. The first container here is the container at the head position in the target container queue.

[0037] Through such a setting, this solution uses a queue method to centrally, uniformly and efficiently manage candidate containers, thereby improving the convenience and efficiency of container management.

[0038] Furthermore, considering the correlation between different codes, for multiple code files to be executed uploaded by the same provider, or the case where the same provider continuously proposes multiple code prompt information to the artificial intelligence model to generate multiple code files to be executed, the multiple code files to be executed associated with the same provider can be set in the same container for execution until the container memory is exhausted and the container reports an error. When the container memory is exhausted, the multiple code files to be executed associated with the provider can also be migrated to a container with larger memory for execution. Different containers are used for the code files to be executed associated with different providers, which can improve the code execution efficiency and facilitate code execution management.

[0039] S130, executing the code file to be executed based on the target container, and obtaining and outputting the code execution result.

[0040] In this embodiment, after determining the target container corresponding to the code file to be executed, the code in the code file to be executed can be executed through the target container, and the corresponding code execution result can be generated after the code execution is completed. Among them, the code execution result corresponds to two situations: normal code execution and abnormal code execution. For example, when an error or security warning occurs in the code execution, it can be determined that the code execution is abnormal. Exemplarily, for the case where the code executes normally, the corresponding code execution results include but are not limited to printing printf signals, result signals obtained according to a certain calculation process, show signals for generating charts, etc., and can also be diverged to other results that the code can achieve according to actual needs. For the case of abnormal code execution, the corresponding code execution results may include error information and warning information. Among them, the error information can be used to describe the error problems that occur during the code execution process, and the warning information can be used to describe the security warning problems that occur during the code execution process.

[0041] The technical solution of the embodiment of the present invention, when a code execution request is detected, first obtains the code file to be executed; then, according to the attributes of the code file to be executed, selects a container that matches the attributes of the code file to be executed from the candidate containers as the target container; wherein the candidate containers include at least two containers with different attributes, each of which is isolated from each other; then, the code file to be executed is executed based on the target container, and the code execution result is obtained and output. This technical solution can match containers with matching attributes for different code requirements, and use the resources associated with the container to execute the corresponding code, thereby improving the rationality of resource scheduling and effectively reducing resource waste on the basis of meeting the code execution requirements.

[0042] In this embodiment, optionally, the method further includes: determining a current state of a container corresponding to the candidate container, where the current state of the container at least includes: waiting, occupied, and occupation completed; when the occupied container meets a first preset release condition, converting the current state of the container corresponding to the occupied container to occupation completed, and releasing resources of the container whose occupation has completed.

[0043] The current state of the container can be used to characterize the usage state of the container at the current moment, including but not limited to waiting, occupied, and ended. The first preset release condition may refer to a condition for releasing resources of a container in an occupied state that is preset according to actual needs. Exemplarily, the first preset release condition may be set to the end of the code running operation of the occupied container or the code running operation is not executed within a preset time after the end of the code running, wherein the preset time can be flexibly set according to actual needs.

[0044] In this embodiment, in order to avoid the problem of resource waste caused by invalid occupation of resources, a container life cycle management method is proposed. Specifically, the state function of each container can be continuously monitored, and the current state of the container can be determined according to the change of the state function. Among them, the value of the state function includes at least alive and false, alive means that the current state of the container is occupied, and false means that the current state of the container is waiting or the occupation is over. For example, if it is detected that the state function of the container changes from alive to false, it indicates that the current state of the container changes from occupied to occupied, that is, the current state of the container is occupied. Exemplarily, when the occupied container ends the code running operation or the code running operation is still not executed within the preset time after the code running is ended, that is, the occupied container meets the first preset release condition, at this time, the state function corresponding to the container is expressed as changing from alive to false, in order to avoid resource waste, the resources of the container that has ended the occupation are released.

[0045] Through such a setting, this solution can effectively avoid the problem of resource waste caused by invalid resource occupation by managing the life cycle of the container.

[0046] In this embodiment, optionally, the method further includes: if it is detected that a resource release operation occurs in the container whose occupation has ended, the container whose occupation has ended is added back into the container queue of the corresponding attribute as a waiting container, and the current state of the container corresponding to the waiting container is converted to waiting.

[0047] Specifically, when the control module detects that a resource release operation occurs in a container in an occupation-ending state, after the resource release is completed, the occupation-ending container can be re-added to a container queue of a corresponding attribute as a waiting container, and the current state of the container corresponding to the waiting container is converted from occupation-ending to waiting, so as to prepare for subsequent container calls.

[0048] In this embodiment, optionally, the method further includes a preloading step: the control module obtains that the current state of the container is a waiting container, and preloads the code running environment for the waiting container; wherein the process of preloading the code running environment includes: the control module loads a running kernel into at least one waiting container, and after the running kernel is loaded, an identification code is assigned to the waiting container, the identification code is used to uniquely identify each container, and the identification code is returned to the control module.

[0049] In this embodiment, in order to avoid the problem of low code execution efficiency caused by the long cold start time when waiting for the container to be called, a preloading mechanism for the code running environment is set. Among them, the code running environment can refer to the environment required for code execution. Specifically, first, the current state of the container is obtained as a waiting container through the control module, and then the running kernel is loaded into at least one waiting container through the control module to configure the code running environment. Among them, the running kernel needs to be adapted to the code running environment. For example, the running kernel required by the Python environment is the jupyter kernel. After the running kernel is loaded, an identification code can be assigned to the waiting container through the running kernel, and the identification code is returned to the control module, and the identification code can be used to uniquely identify each container. For example, the identification code can be an ID. In addition, while loading the running kernel, a processor corresponding to the container attributes (such as CPU, GPU, etc.) can also be configured. The preloading mechanism enables the code running environment to load the corresponding resources or environment without waiting for the waiting container to be called, which can effectively avoid the problem of low code execution efficiency caused by too long cold start time.

[0050] Through such a setting, this solution uses the preloading mechanism to load the code running environment into the waiting container during the queuing process, which can effectively avoid the low code execution efficiency caused by the long cold start time when the waiting container is called, and help improve the code execution efficiency.

[0051] In this embodiment, optionally, the method further includes: determining the number of containers and / or the number of free containers in each container queue in the candidate container queue; judging whether the number of containers in each container queue in the candidate container queue meets a first preset number standard, and / or judging whether the number of free containers in each container queue in the candidate container queue meets a second preset number standard; if there is a container queue in the candidate container queue whose number of containers does not meet the first preset number standard, and / or if there is a container queue in the candidate container queue whose number of free containers does not meet the second preset number standard, performing a queue expansion operation on the container queue that does not meet the first preset number standard and / or does not meet the second preset number standard.

[0052] In this embodiment, the minimum number of containers and / or the minimum number of available containers may be set in advance for each container queue, and the minimum number of containers may be used as the first preset number, and the minimum number of available containers may be used as the second preset number. Specifically, the number of containers and / or the number of idle containers in each container queue may be monitored in real time or periodically. If the number of containers in the container queue is lower than the first preset number, it may be determined that the number of containers in the container queue meets the first preset number standard; if the number of idle containers in the container queue is lower than the second preset number, it may be determined that the number of idle containers in the container queue meets the second preset number standard. If there is a container queue in the candidate container queue whose number of containers does not meet the first preset number standard, and / or if there is a container queue in the candidate container queue whose number of idle containers does not meet the second preset number standard, the control module may be triggered to perform queue expansion processing on the container queue, so as to add a new number of containers to the container queue that does not meet the first preset number standard and / or does not meet the second preset number standard, thereby ensuring that there are sufficient number of containers available even if multiple users access at the same time. Exemplarily, when there is a container queue in the candidate container queue whose number of containers does not meet the first preset number standard, the number of newly added containers can be set to twice the first preset number; when there is a container queue in the candidate container queue whose number of idle containers does not meet the second preset number standard, the number of newly added containers can be set to twice the second preset number.

[0053] It should be noted that the specific values ​​of the first preset number and the second preset number can be predicted through historical records, and the values ​​are updated at a certain period. In addition, the first preset number and / or the second preset number corresponding to different container queues can be set to the same or different values, which can be set according to actual needs.

[0054] Through such a setting, the present solution triggers a queue expansion operation when the number of containers in the container queue does not meet a first preset number standard and / or when the number of free containers in the container queue does not meet a second preset number standard, so as to provide a sufficient number of containers to meet the access needs of multiple users.

[0055] In this embodiment, optionally, the candidate container has a built-in security module, and the security module is used to restrict the candidate container from executing preset operations, and the preset operations include restricting function running operations and network connection operations.

[0056] Specifically, a security module can also be built into the candidate container. The security module can be written by the control module when the new container is loaded into the running kernel. The security module can be used to limit the container to only execute preset operations, where the preset operations include but are not limited to limiting the running operations of functions and network connection operations.

[0057] Through such a setting, this solution uses a built-in security module in the container to limit container behavior, which can effectively avoid illegal operations and ensure the security of code execution.

[0058] Embodiment 2

[0059] Figure 2 This is a flowchart of a code execution method provided in Embodiment 2 of the present invention. This embodiment is optimized based on the above embodiment.

[0060] like Figure 2 As shown, the method of this embodiment specifically includes the following steps:

[0061] S210: If a code generation request is detected, at least one code file to be executed is generated according to the code generation request through an artificial intelligence model, and properties of the code file to be executed are obtained.

[0062] The code generation request may be used to request the generation of a to-be-executed code file including the required execution code. Exemplarily, the code generation request may include code prompt information that needs to be implemented based on the code, and the code prompt information may be used to guide the artificial intelligence model to generate the required execution code. The code prompt information may be expressed in the form of text, instructions, questions, files, or scenario descriptions.

[0063] In this embodiment, when a code generation request is detected, the code prompt information in the code generation request is first obtained through the artificial intelligence model, and then at least one to-be-executed code file including the required execution code is generated according to the code prompt information, and the properties of the to-be-executed code file are obtained.

[0064] S220, based on the attributes of the code file to be executed, obtaining the running resource requirements of the code file to be executed through the artificial intelligence model, and the running resource requirements at least include running computing power requirements and running memory requirements.

[0065] In this embodiment, after obtaining the attributes of the code file to be executed, the running resource requirements of the code file to be executed can be further obtained from multiple attributes of the code file to be executed through an artificial intelligence model, and the running resource requirements include at least running computing power requirements and running memory requirements.

[0066] S230, the control module matches the optimal candidate container that meets the operating resource requirement as the target container according to the operating resource requirement, and obtains an identification code of the target container; wherein the identification code of the target container is used to uniquely identify the target container.

[0067] In this embodiment, after obtaining the running resource requirements of the code file to be executed through the artificial intelligence model, the control module can match an optimal candidate container that meets the running resource requirements from the candidate containers as the target container according to the running resource requirements, and obtain the identification code of the target container. Among them, the candidate containers include at least two containers with different attributes, each of which is isolated from each other; the identification code of the target container is used to uniquely identify the target container.

[0068] S240, the control module sends the code execution request and the code file to be executed to the target address of the target container based on the identification code of the target container, so that the code file to be executed runs in the target container.

[0069] In this embodiment, after obtaining the identification code of the target container, the control module can determine the target address corresponding to the target container according to the identification code of the target container, and then accurately locate the target container through the target address. Then, the code execution request and the code file to be executed are sent to the target address of the target container, so that the code file to be executed runs in the target container. Among them, the target address can be used to accurately locate the target container through addressing.

[0070] S250, obtaining and outputting the code execution result of the code file to be executed through the artificial intelligence model.

[0071] In this embodiment, when the code file to be executed is run in the target container, a corresponding code execution result can be generated. After the code execution result is generated, the code execution result of the code file to be executed can be obtained and output through the artificial intelligence model to display the code execution result.

[0072] In this embodiment, optionally, the method also includes: if the code execution result includes exception information, obtaining the exception information through an artificial intelligence model, and optimizing the code in the code file to be executed based on the exception information; wherein the exception information includes at least one of error information and warning information.

[0073] Among them, the types of abnormal information include error information and warning information. Error information is used to describe error problems that occur during code execution, and warning information is used to describe security warning problems that occur during code execution. Exemplarily, error information may include error codes and error types. Among them, error types include but are not limited to syntax errors, runtime errors, type errors, name errors, and module import errors. Among them, error information will affect the code execution process and terminate the code execution; warning information does not affect the code execution process, but it also has the value of being used for the artificial intelligence model to continue adaptive learning.

[0074] In this embodiment, if it is determined that the code execution result contains exception information, the exception information can be obtained through the artificial intelligence model, and the code in the code file to be executed can be optimized based on the exception information. Exemplarily, the artificial intelligence model can be used to adaptively modify the code in the code file to be executed based on the error information and warning information in the exception information to improve the code optimization efficiency.

[0075] The technical solution of the embodiment of the present invention is that when a code generation request is detected, at least one to-be-executed code file is first generated according to the code generation request through an artificial intelligence model, and the attributes of the to-be-executed code file are obtained; then, based on the attributes of the to-be-executed code file, the running resource requirements of the to-be-executed code file are obtained through the artificial intelligence model, wherein the running resource requirements at least include running computing power requirements and running memory requirements; then, the control module matches the optimal candidate container that meets the running resource requirements as the target container according to the running resource requirements, and obtains the identification code of the target container; wherein the identification code of the target container is used to uniquely identify the target container; then, the control module sends the code execution request and the to-be-executed code file to the target address of the target container based on the identification code of the target container, so that the to-be-executed code file runs in the target container; finally, the code execution result of the to-be-executed code file is obtained and output through the artificial intelligence model. This technical solution can use artificial intelligence models to generate code files to be executed, which effectively improves the code generation efficiency compared to manual writing methods. The control module matches containers with matching attributes for different code files, and uses the resources associated with the containers to execute the corresponding codes, thereby improving the rationality of resource scheduling, effectively reducing resource waste while meeting code execution requirements, and enhancing user experience. In addition, when abnormal situations occur during code execution, the artificial intelligence model can be used to adaptively optimize the code based on the abnormal information, thereby improving the code optimization efficiency.

[0076] Embodiment 3

[0077] Figure 3 This is a schematic diagram of the structure of a code execution device provided in the third embodiment of the present invention. The device can execute the code execution method provided in any embodiment of the present invention and has the corresponding functional modules and beneficial effects of the execution method. Figure 3 As shown, the device comprises:

[0078] The to-be-executed code file acquisition module 310 is used to acquire the to-be-executed code file if a code execution request is detected;

[0079] A target container determination module 320, configured to select, according to the attributes of the code file to be executed, a container that matches the attributes of the code file to be executed from candidate containers as a target container; wherein the candidate containers include at least two containers with different attributes, and each container is isolated from each other;

[0080] The code execution result determination module 330 is used to execute the to-be-executed code file based on the target container, and obtain and output the code execution result.

[0081] Optionally, the candidate containers are stored in a queue;

[0082] Accordingly, the target container determination module 320 is used to:

[0083] According to the attributes of the code file to be executed, a container queue with matching attributes is matched from the candidate container queue as the target container queue, wherein the candidate container queue includes at least two container queues with different attributes, each container queue includes a plurality of containers with the same attributes, and each container queue satisfies the first-in-first-out principle.

[0084] Optionally, the device is also used for:

[0085] If a code generation request is detected, at least one of the to-be-executed code files is generated according to the code generation request by using an artificial intelligence model, and properties of the to-be-executed code file are obtained;

[0086] Selecting a target container that matches the attributes of the code file to be executed according to the attributes of the code file to be executed, and allowing the code file to be executed to run in the target container;

[0087] The code execution result of the code file to be executed is obtained and output through the artificial intelligence model.

[0088] Optionally, the device is also used for:

[0089] Determine a current state of a container corresponding to the candidate container, where the current state of the container at least includes: waiting, occupied, and occupied;

[0090] When the occupied container meets the first preset release condition, the current state of the container corresponding to the occupied container is converted to occupation ended, and the resources of the container whose occupation ended are released.

[0091] Optionally, the device is also used for:

[0092] The control module obtains that the current state of the container is a waiting container, and preloads a code running environment for the waiting container;

[0093] Among them, the process of preloading the code running environment includes: the control module loads the running kernel into at least one waiting container, and after the running kernel is loaded, an identification code is assigned to the waiting container, and the identification code is used to uniquely identify each container, and the identification code is returned to the control module.

[0094] Optionally, the device is also used for:

[0095] If it is detected that a resource release operation occurs in the container whose occupation has ended, the container whose occupation has ended is added back into the container queue of the corresponding attribute as a waiting container, and the current state of the container corresponding to the waiting container is converted to waiting.

[0096] Optionally, the device is also used for:

[0097] Based on the attributes of the code file to be executed, obtaining the running resource requirements of the code file to be executed through the artificial intelligence model, wherein the running resource requirements at least include running computing power requirements and running memory requirements;

[0098] The control module matches the optimal candidate container that meets the operating resource requirement as the target container according to the operating resource requirement, and obtains an identification code of the target container; wherein the identification code of the target container is used to uniquely identify the target container;

[0099] The control module sends the code execution request and the to-be-executed code file to a target address of the target container based on the identification code of the target container.

[0100] Optionally, the device is also used for:

[0101] Determine the number of containers and / or the number of idle containers in each container queue in the candidate container queue;

[0102] Determining whether the number of containers in each container queue in the candidate container queue meets a first preset number standard, and / or determining whether the number of free containers in each container queue in the candidate container queue meets a second preset number standard;

[0103] If there is a container queue in the candidate container queue whose number of containers does not meet the first preset number standard, and / or if there is a container queue in the candidate container queue whose number of idle containers does not meet the second preset number standard, a queue expansion operation is performed on the container queue that does not meet the first preset number standard and / or does not meet the second preset number standard.

[0104] Optionally, the device is also used for:

[0105] If the code execution result includes exception information, the exception information is obtained through the artificial intelligence model, and the code in the to-be-executed code file is optimized based on the exception information;

[0106] The abnormal information includes at least one of error information and warning information.

[0107] Optionally, the candidate container has a built-in security module, and the security module is used to restrict the candidate container from executing preset operations, and the preset operations include restricting function running operations and network connection operations.

[0108] A code execution device provided in an embodiment of the present invention can execute a code execution method provided in any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution method.

[0109] Embodiment 4

[0110] Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0111] like Figure 4 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.

[0112] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0113] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a code execution method.

[0114] In some embodiments, the code execution method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the code execution method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the code execution method in any other appropriate manner (e.g., by means of firmware).

[0115] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0116] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0117] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0118] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0119] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0120] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0121] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0122] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A code execution method, characterized in that: The method comprises: If a code execution request is detected, the code file to be executed is obtained; According to the attribute of the code file to be executed, a container matching the attribute of the code file to be executed is selected from candidate containers as a target container; wherein the candidate containers include at least two containers with different attributes, and each container is isolated from each other; The to-be-executed code file is executed based on the target container, and a code execution result is obtained and output.

2. The method according to claim 1, characterized in that The candidate containers are stored in a queue form; Correspondingly, according to the attribute of the code file to be executed, selecting a container matching the attribute of the code file to be executed from the candidate containers as the target container includes: According to the attributes of the code file to be executed, a container queue with matching attributes is matched from the candidate container queue as the target container queue, wherein the candidate container queue includes at least two container queues with different attributes, each container queue includes a plurality of containers with the same attributes, and each container queue satisfies the first-in-first-out principle.

3. The method according to claim 2, characterized in that The method further comprises: If a code generation request is detected, at least one of the to-be-executed code files is generated according to the code generation request by using an artificial intelligence model, and properties of the to-be-executed code file are obtained; Selecting a target container that matches the attributes of the code file to be executed according to the attributes of the code file to be executed, and allowing the code file to be executed to run in the target container; The code execution result of the code file to be executed is obtained and output through the artificial intelligence model.

4. The method according to claim 3, characterized in that The method further comprises: Determine a current state of a container corresponding to the candidate container, where the current state of the container at least includes: waiting, occupied, and occupied; When the occupied container meets the first preset release condition, the current state of the container corresponding to the occupied container is converted to occupation ended, and the resources of the container whose occupation ended are released.

5. The method according to claim 4, characterized in that The method further comprises a preloading step: The control module obtains that the current state of the container is a waiting container, and preloads a code running environment for the waiting container; Among them, the process of preloading the code running environment includes: the control module loads the running kernel into at least one waiting container, and after the running kernel is loaded, an identification code is assigned to the waiting container, and the identification code is used to uniquely identify each container, and the identification code is returned to the control module.

6. The method according to claim 4, characterized in that The method further comprises: If it is detected that a resource release operation occurs in the container whose occupation has ended, the container whose occupation has ended is added back into the container queue of the corresponding attribute as a waiting container, and the current state of the container corresponding to the waiting container is converted to waiting.

7. The method according to claim 3, characterized in that Selecting a target container that matches the attribute of the code file to be executed according to the attribute of the code file to be executed includes: Based on the attributes of the code file to be executed, obtaining the running resource requirements of the code file to be executed through the artificial intelligence model, where the running resource requirements at least include running computing power requirements and running memory requirements; The control module matches the optimal candidate container that meets the operating resource requirement as the target container according to the operating resource requirement, and obtains an identification code of the target container; wherein the identification code of the target container is used to uniquely identify the target container; The control module sends the code execution request and the to-be-executed code file to a target address of the target container based on the identification code of the target container.

8. The method according to claim 2, characterized in that: The method further comprises: Determine the number of containers and / or the number of idle containers in each container queue in the candidate container queue; Determining whether the number of containers in each container queue in the candidate container queue meets a first preset number standard, and / or determining whether the number of free containers in each container queue in the candidate container queue meets a second preset number standard; If there is a container queue in the candidate container queue whose number of containers does not meet the first preset number standard, and / or if there is a container queue in the candidate container queue whose number of idle containers does not meet the second preset number standard, a queue expansion operation is performed on the container queue that does not meet the first preset number standard and / or does not meet the second preset number standard.

9. The method according to any one of claims 3 to 7, characterized in that: The method further comprises: If the code execution result includes exception information, the exception information is obtained through the artificial intelligence model, and the code in the to-be-executed code file is optimized based on the exception information; The abnormal information includes at least one of error information and warning information.

10. A code execution device, characterized in that: The device comprises: A module for acquiring code files to be executed, used to acquire code files to be executed if a code execution request is detected; a target container determination module, configured to select, according to the attributes of the code file to be executed, a container matching the attributes of the code file to be executed from candidate containers as a target container; wherein the candidate containers include at least two containers with different attributes, and each container is isolated from each other; The code execution result determination module is used to execute the to-be-executed code file based on the target container, and obtain and output the code execution result.

Citation Information

Patent Citations

  • Task processing method and device, computer equipment and storage medium

    CN111104222A

  • Container group setting method, access request processing method and related device

    CN116541101A

  • Data processing method and device, electronic equipment and storage medium

    CN116737314A

  • Container resource allocation method and device

    CN119003173A

  • Method and apparatus for allocating server resource, electronic device and storage medium

    US20210218690A1