This disclosure relates to the field of cloud technologies, and in particular, to a cloud platform and a cloud platform-based program code processing method.
Currently, cloud computing becomes increasingly popular, and is an inevitable trend of future information technology development. A cloud computing service is a basic cloud service provided by a cloud service provider, and a tenant may use the basic cloud service through the internet. For example, the cloud service provider configures a server in a cloud data center operated by the cloud service provider, and the tenant may obtain a remote use permission of a virtual machine in a specification in the server by paying to the cloud service provider, to use the basic cloud service. The cloud service is not limited to the virtual machine, and may also include an object storage service, a database service, a security service, and a face recognition service. The cloud computing service enables the tenant to skip a tedious server configuration process and obtain, by paying, the basic cloud service provided by the cloud service provider.
Due to popularity of cloud computing, a programmer may also use, in a process of developing a large-scale computing program, a computing capability provided by the cloud service. For example, the programmer may separately set a plurality of virtual machines, separately write program code pre-split by the programmer into the plurality of virtual machines, and enable the plurality of virtual machines to separately run the program code. Finally, the programmer collects running results of the program code in the plurality of virtual machines, to run the large-scale computing program by using the computing capability provided by the cloud service. For example, Hadoop and Spark in a MapReduce architecture are good manners for completing large-scale computing.
However, currently, a method for completing large-scale computing by using the cloud service is still complex in use. The tenant needs to log in to a cloud platform. The tenant inputs, on an interface provided by the cloud platform, a configuration of a required virtual machine to create a virtual machine, logs in to the created virtual machine, and sets the virtual machine to run program code, resulting in poor user experience.
This disclosure provides a cloud platform and a cloud platform-based program code processing method, which can improve experience of a programmer in using cloud resources for program development.
According to a first aspect, this disclosure provides a cloud service-based program code processing method. A cloud platform may receive program code of a tenant, and process the program code. The method includes the following steps: a cloud platform obtains program code of a tenant, where the program code includes a first tag and subroutine code, and the first tag is used to indicate configuration information of a virtual instance running the subroutine code; the cloud platform creates or selects one or more first virtual instances based on the first tag; the cloud platform separately sends the subroutine code to the one or more first virtual instances; and the cloud platform receives a first running result obtained by separately running the subroutine code by the one or more first virtual instances.
When writing the program code, the tenant may set, in the program code, the first tag used to indicate the configuration information of the virtual instance running the subroutine code. The cloud platform obtains the program code. The cloud platform creates or selects, based on the first tag, at least one virtual instance to run the subroutine code, and receives the first running result obtained by running the subroutine code by the at least one virtual instance. Therefore, the tenant can add a tag in the program code, to indicate the cloud platform to create a corresponding virtual instance and run the subroutine code, cloud resources can be effectively used to run the subroutine code without changing an existing programming habit, and user experience can be improved.
In addition, the tenant does not need to log in to the first virtual instance, and the first virtual instance is configured by the cloud platform in the background, which can further improve user experience.
The tag is further used to separate different subroutine code, so that the cloud platform determines the different subroutine code based on the tag.
Optionally, the configuration information includes a virtual instance specification.
The virtual instance specification includes a processor core number, a primary frequency amplitude of a processor, and a memory size that are of the virtual instance.
In a programming process, the tenant adds a tag in the program code, and sets a specification of a to-be-created virtual instance in the configuration information indicated by the tag. When a computing capability required for running the subroutine code is high, the virtual instance specification may be set as a high specification; or when the computing capability required for running the subroutine code is low, the virtual instance specification may be set as a low specification, thereby achieving a technical effect of flexibly using cloud resources to run the subroutine code. Because the virtual instance specification is in direct proportion to a sale price of the virtual instance, the tenant can also properly set, by setting a tag, a virtual instance specification based on cloud resource computing power required by the tenant, thereby effectively reducing costs of purchasing cloud resources from the cloud platform.
Optionally, the configuration information includes a virtual instance type, and the virtual instance type is used to indicate any one of a virtual machine, a container, and a bare metal server.
In the programming process, the tenant adds a tag in the program code, and sets a type of a to-be-created virtual instance in configuration information indicated by the tag, and the type is, for example, the virtual machine, the container, or the bare metal server, thereby achieving a technical effect of flexibly using cloud resources to run the subroutine code. Because different virtual instance types, for example, the virtual machine, the container, and the bare metal server, have different sale prices, the tenant can also properly select, by setting a tag, a virtual instance type based on cloud resource computing power required by the tenant, thereby effectively reducing costs of purchasing cloud resources from the cloud platform.
For large-scale computing, the tenant may select the virtual machine or the bare metal server. These two virtual instances run stably. For small-scale computing, the tenant may select the container.
Optionally, the configuration information includes a virtual instance number N, where N is a positive integer.
In the programming process, the tenant adds a tag in the program code, and sets a number of to-be-created virtual instances in configuration information indicated by the tag. The number is used to indicate a number of virtual instances running the subroutine code. When N is set as a complex number, the subroutine code runs in a plurality of virtual instances. For a big data scenario, parallel computing is an important data processing method. The tenant may tag, in the program code, a number of virtual instances running subroutine code, so that the plurality of virtual instances run the subroutine code in parallel. Therefore, the cloud platform can provide a parallel programming capability for the tenant.
Optionally, there are a plurality of first virtual instances, and the subroutine code is used to indicate the plurality of first virtual instances to respectively obtain different to-be-processed data from a shared storage space and respectively perform data processing on the obtained to-be-processed data.
Based on a scenario in which the plurality of virtual instances run the subroutine code in parallel, the tenant writes the subroutine code, so that the subroutine code is used to indicate the plurality of first virtual instances to respectively obtain the different to-be-processed data from the shared storage space and respectively perform data processing on the obtained to-be-processed data. Therefore, the plurality of first virtual instances can run same subroutine code for the different to-be-processed data to implement same program logic and implement parallel computing.
Optionally, the program code further includes nested program code and a second tag, the second tag is used to indicate configuration information of a virtual instance running the nested program code, and the nested program code is invoked by the subroutine code. The method further includes the following steps: the cloud platform creates or selects one or more second virtual instances based on the second tag, and sends the nested program code to the one or more second virtual instances; and the cloud platform receives a second running result obtained by separately running the nested program code by the one or more second virtual instances, and sends the second running result to the first virtual instance.
In this implementation, when the subroutine code invokes another piece of subroutine code, the other piece of subroutine code is referred to the nested program code. The second tag indicates the configuration information of the virtual instance running the nested program code. The cloud platform creates or selects the one or more second virtual instances based on the configuration information indicated by the second tag, sends the nested program code to the one or more second virtual instances for running, and sends the second running result obtained through running to the first virtual instance. Therefore, in this implementation, when subroutine code nesting exists, the cloud platform obtains the running result from the virtual instance running the nested program code, and sends the running result to the virtual instance that runs the subroutine code invoking the nested program code, so that the running result of the nested program code can reach the first virtual instance, and the first virtual instance continues running the subroutine code based on the running result, thereby implementing program code nesting.
Optionally, the program code further includes main program code, and the subroutine code is invoked by the main program code. The method further includes the following steps: the cloud platform requests the first running result from the one or more first virtual instances when running the main program code to a location at which the subroutine code needs to be invoked; and the cloud platform continues running the main program code based on the first running result.
In this implementation, the cloud platform directly runs the main program code; and when running the main program code to the location at which the subroutine code is to be invoked, the cloud platform does not run the subroutine code, but requests the first running result from the first virtual instance running the subroutine code, and continues running the main program code based on the first running result obtained by the request. The cloud platform directly runs the main program code and communicates with the virtual instance running the subroutine code, so that the entire process of invoking the subroutine code by the main program code can be implemented, thereby ensuring that a programming habit of the tenant remains unchanged.
Optionally, the method further includes the following steps: the cloud platform provides an upload interface, where the upload interface is configured to receive the program code uploaded by the tenant; or the cloud platform provides a program editing screen, where the program editing screen is configured to receive the program code remotely input by the tenant.
In this implementation, after locally writing the program code, the tenant may upload the program code to the cloud platform through the upload interface, or the tenant may directly remotely input the program code on the program editing screen provided by the cloud platform, to implement online programming on the cloud platform.
The foregoing two manners may be simultaneously provided to the tenant, and the tenant may select one manner based on a programming habit of the tenant, to further improve user experience.
Optionally, the method further includes the following steps: the cloud platform provides a cloud service, and sets a cloud service application programming interface (API) for the cloud service, where the cloud service API is set in the subroutine code, and the cloud service API is configured to invoke the cloud service provided by the cloud platform.
In this implementation, when writing the subroutine code, the tenant may invoke the cloud service API provided by the cloud platform, to fully use cloud resources provided by the cloud service.
Optionally, the cloud service API includes one or any combination of an object storage service API, a database service API, a shared cache service API, and a message queue service API.
Optionally, the first tag and the second tag are annotations of the subroutine code, or the first tag and the second tag each are program code that uses a predetermined syntax and that is adjacent to the subroutine code.
In this implementation, the first tag and the second tag may be set as the annotations of the subroutine code, for example, before or after the program code, being @, \\, \, /, //, or another symbol tag pre-agreed with the cloud platform, and configuration information such as a type, a specification, and a number that are of the virtual instance is input in a predetermined format after the symbol. When detecting the symbol, the cloud platform creates a virtual instance based on the type, the specification, and the number that are of the virtual instance indicated after the symbol, and sends the subroutine code to the virtual instance for running. Through the annotation, a programming habit of the tenant does not need to be changed, and the tenant only needs to input the symbol before or after the subroutine code and input the configuration information after the symbol, so as to run the subroutine code by using the virtual instance on a cloud side.
The first tag and the second tag each may be set as the program code that uses the predetermined syntax and that is adjacent to the subroutine code. For example, the cloud platform agrees to use a function creatvirtualinstance (type,spec,N) of the predetermined syntax as the tag. In this case, in a process of writing the program code, the tenant may invoke creatvirtualinstance (type,spec,N) at an adjacent location of the subroutine code (that is, a location before or after the subroutine), and input one or any combination of a type type, a specification spec, and a number N that are of a virtual instance based on a requirement of the tenant. That is, the subroutine code may be tagged, so that the subroutine code runs in a virtual instance created or selected by the cloud platform based on one or any combination of the type type, the specification spec, and the number N.
According to a second aspect, this disclosure provides a cloud service-based program code processing method, including the following method: a cloud platform receives subroutine code and a first tag that are sent by a service virtual instance running main program code, where the subroutine code is invoked by the main program code, and the first tag is used to indicate configuration information of a virtual instance running the subroutine code; the cloud platform creates or selects one or more first virtual instances based on the first tag; the cloud platform sends the subroutine code to the one or more first virtual instances; and the cloud platform receives a first running result obtained by separately running the subroutine code by the one or more first virtual instances, and sends the first running result to the service virtual instance.
In comparison with the first aspect, the main program code can directly run on a service virtual machine of a tenant, and the service virtual machine sends the subroutine code invoked by the main program code and the first tag to the cloud platform. The cloud platform creates or selects, based on the first tag, at least one virtual instance to run the subroutine code, receives the first running result obtained by running the subroutine code by the at least one virtual instance, and sends the first running result to the service virtual instance, so that the service virtual instance can continue running the main program based on the first running result. Therefore, the tenant can indicate, based on the tag, the cloud platform to create a corresponding virtual instance and run the subroutine code, cloud resources can be effectively used to run the subroutine code without changing an existing programming habit, and user experience can be improved.
Optionally, the configuration information includes a virtual instance specification.
The virtual instance specification includes a processor core number, a primary frequency amplitude of a processor, and a memory size that are of the virtual instance.
In a programming process, the tenant adds a tag in the program code, and sets a specification of a to-be-created virtual instance in the configuration information indicated by the tag. When a computing capability required for running the subroutine code is high, the virtual instance specification may be set as a high specification; or when the computing capability required for running the subroutine code is low, the virtual instance specification may be set as a low specification, thereby achieving a technical effect of flexibly using cloud resources to run the subroutine code. Because the virtual instance specification is in direct proportion to a sale price of the virtual instance, the tenant can also properly set, by setting a tag, a virtual instance specification based on cloud resource computing power required by the tenant, thereby effectively reducing costs of purchasing cloud resources from the cloud platform.
Optionally, the configuration information includes a virtual instance type, and the virtual instance type is used to indicate any one of a virtual machine, a container, and a bare metal server.
In the programming process, the tenant adds a tag in the program code, and sets a type of a to-be-created virtual instance in configuration information indicated by the tag, and the type is, for example, the virtual machine, the container, or the bare metal server, thereby achieving a technical effect of flexibly using cloud resources to run the subroutine code. Because different virtual instance types, for example, the virtual machine, the container, and the bare metal server, have different sale prices, the tenant can also properly select, by setting a tag, a virtual instance type based on cloud resource computing power required by the tenant, thereby effectively reducing costs of purchasing cloud resources from the cloud platform.
For large-scale computing, the tenant may select the virtual machine or the bare metal server. These two virtual instances run stably. For small-scale computing, the tenant may select the container.
Optionally, the configuration information includes a virtual instance number N, where N is a positive integer.
In the programming process, the tenant adds a tag in the program code, and sets a number of to-be-created virtual instances in configuration information indicated by the tag. The number is used to indicate a number of virtual instances running the subroutine code. When N is set as a complex number, the subroutine code runs in a plurality of virtual instances. For a big data scenario, parallel computing is an important data processing method. The tenant may tag, in the program code, a number of virtual instances running subroutine code, so that the plurality of virtual instances run the subroutine code in parallel. Therefore, the cloud platform can provide a parallel programming capability for the tenant.
Optionally, the subroutine code is used to indicate the one or more first virtual instances to respectively obtain different to-be-processed data from a shared storage space and respectively perform data processing on the obtained to-be-processed data.
Based on a scenario in which the plurality of virtual instances run the subroutine code in parallel, the tenant writes the subroutine code, so that the subroutine code is used to indicate the one or more first virtual instances to respectively obtain the different to-be-processed data from the shared storage space and respectively perform data processing on the obtained to-be-processed data. Therefore, the one or more first virtual instances can run same subroutine code for the different to-be-processed data to implement same program logic and implement parallel computing.
Optionally, the method further includes the following step: the cloud platform receives nested program code and a second tag that are sent when the service virtual instance runs, where the second tag is used to indicate configuration information of a virtual instance running the nested program code, and the nested program code is invoked by the subroutine code; the cloud platform creates or selects one or more second virtual instances based on the second tag, and sends the nested program code to the one or more second virtual instances; and the cloud platform obtains, from the one or more second virtual instances, a second running result generated by running the second program code by the one or more second virtual instances, and sends the second running result to the first virtual instance.
In this implementation, when the subroutine code invokes another piece of subroutine code, the other piece of subroutine code is referred to the nested program code. The second tag indicates the configuration information of the virtual instance running the nested program code. The cloud platform creates or selects the one or more second virtual instances based on the configuration information indicated by the second tag, sends the nested program code to the one or more second virtual instances for running, and sends the second running result obtained through running to the first virtual instance. Therefore, in this implementation, when subroutine code nesting exists, the cloud platform obtains the running result from the virtual instance running the nested program code, and sends the running result to the virtual instance that runs the subroutine code invoking the nested program code, so that the running result of the nested program code can reach the first virtual instance, and the first virtual instance continues running the subroutine code based on the running result, thereby implementing program code nesting.
Optionally, the method further includes the following steps: the cloud platform provides a cloud service, and sets a cloud service API for the cloud service, where the cloud service API is set in the subroutine code, and the cloud service API is configured to invoke the cloud service provided by the cloud platform.
In this implementation, when writing the subroutine code, the tenant may invoke the cloud service API provided by the cloud platform, to fully use cloud resources provided by the cloud service.
Optionally, the cloud service API includes one or any combination of an object storage service API, a database service API, a shared cache service API, and a message queue service API.
Optionally, the first tag is an annotation of the subroutine code, or the first tag is program code that uses a predetermined syntax and that is adjacent to the subroutine code.
In this implementation, the first tag and the second tag may be set as annotations of the subroutine code, for example, before or after the program code, being @, \\, \, /, //, or another symbol tag pre-agreed with the cloud platform, and configuration information such as a type, a specification, and a number that are of the virtual instance is input in a predetermined format after the symbol. When detecting the symbol, the cloud platform creates a virtual instance based on the type, the specification, and the number that are of the virtual instance indicated after the symbol, and sends the subroutine code to the virtual instance for running. Through the annotation, a programming habit of the tenant does not need to be changed, and the tenant only needs to input the symbol before or after the subroutine code and input the configuration information after the symbol, so as to run the subroutine code by using the virtual instance on a cloud side.
The first tag and the second tag each may be set as program code that uses a predetermined syntax and that is adjacent to the subroutine code. For example, the cloud platform agrees to use a function creatvirtualinstance (type,spec,N) of the predetermined syntax as the tag. In this case, in a process of writing the program code, the tenant may invoke creatvirtualinstance (type,spec,N) at an adjacent location of the subroutine code (that is, a location before or after the subroutine), and input one or any combination of a type type, a specification spec, and a number N that are of a virtual instance based on a requirement of the tenant. That is, the subroutine code may be tagged, so that the subroutine code runs in a virtual instance created or selected by the cloud platform based on one or any combination of the type type, the specification spec, and the number N.
According to a third aspect, this disclosure provides a cloud platform, including: a cloud service providing unit, configured to obtain program code of a tenant, where the program code includes a first tag and subroutine code, and the first tag is used to indicate configuration information of a virtual instance running the subroutine code; and a cloud program execution unit, configured to: create or select one or more first virtual instances based on the first tag, separately send the subroutine code to the one or more first virtual instances, and receive a first running result obtained by separately running the subroutine code by the one or more first virtual instances.
Any one of the third aspect or the implementations of the third aspect is a method implementation corresponding to any one of the first aspect or the implementations of the first aspect. The description in any one of the first aspect or the implementations of the first aspect is applicable to any one of the third aspect or the implementations of the third aspect. Details are not described herein.
According to a fourth aspect, this disclosure provides a cloud platform, including: a cloud service providing unit, configured to create a service virtual instance, where the service virtual instance is used to run main program code; and a cloud program execution unit, configured to: receive subroutine code and a first tag that are sent by the service virtual instance, where the subroutine code is invoked by the main program code, and the first tag is used to indicate configuration information of a virtual instance running the subroutine code, create or select one or more first virtual instances based on the first tag, send the subroutine code to the one or more first virtual instances, receive a first running result obtained by separately running the subroutine code by the one or more first virtual instances, and send the first running result to the service virtual instance.
Any one of the fourth aspect or the implementations of the fourth aspect is a method implementation corresponding to any one of the second aspect or the implementations of the second aspect. The description in any one of the fourth aspect or the implementations of the fourth aspect is applicable to any one of the second aspect or the implementations of the second aspect. Details are not described herein.
According to a fifth aspect, this disclosure provides a computer device, where the computer device includes a processor and a memory. The memory is configured to store computer-executable instructions, and the processor is configured to execute the computer-executable instructions stored in the memory, to enable the computer device to implement the method disclosed in any one of the first aspect or the possible implementations of the first aspect, or enable the computer device to implement the method disclosed in any one of the second aspect or the possible implementations of the second aspect.
According to a sixth aspect, this disclosure provides a computer storage medium, including computer-readable instructions. When the computer-readable instructions are executed, the method disclosed in any one of the first aspect or the possible implementations of the first aspect is implemented, or the method disclosed in any one of the second aspect or the possible implementations of the second aspect is implemented.
According to a seventh aspect, this disclosure provides a computer program product including an instruction. When the computer program product runs on a computer, the computer is enabled to perform the method disclosed in any one of the first aspect or the possible implementations of the first aspect, or the computer is enabled to perform the method disclosed in any one of the second aspect or the possible implementations of the second aspect.
The following describes the technical solutions in embodiments of the present disclosure with reference to the accompanying drawings in embodiments of the present disclosure. It is clear that the described embodiments are merely a part rather than all of embodiments of the present disclosure. All other embodiments obtained by a person of ordinary skill in the art based on embodiments of the present disclosure without creative efforts shall fall within the protection scope of the present disclosure.
To facilitate understanding of embodiments of this disclosure, some terms in this disclosure are first explained and described.
Cloud platform: The cloud platform is configured to provide a cloud service-related screen for a tenant to remotely access a cloud service. The tenant may log in to the cloud platform on a cloud service access page by using a pre-registered account and password, and after successful login, select and purchase a corresponding cloud service on the cloud service access page. The cloud service is, for example, an object storage service, a virtual machine service, or a container service. In embodiments of the present disclosure, the cloud platform may provide a cloud service for processing program code of the tenant.
Service logic: The service logic is logic of a program, which describes what the program executes. A software engineer writes source code, and the service logic is executed during execution of the source code. Corresponding to a statically compiled programming language, the source code developed by the software engineer is usually compiled into executable binary-format target code by using a compiler, and then the target code is executed by a processor of a computer. For a parsable programming language, a script parser usually parses source code to generate target code, and the target code is executed by the processor of the computer. The service logic mentioned in this embodiment of the present disclosure is logic of software running, and is what the source code requires the computer to do.
Program code: In embodiments of the present disclosure, the program code may be source code or may be target code, which depends on different application scenarios (which are described in detail below).
Compilation: In embodiments of the present disclosure, included program code may be compiled according to a programming language used by the program code. When the program code is a scripting language, for example, is a scripting language such as python, java, or ruby, in Embodiment 1 described below, the program code is the source code, a tenant may directly upload uncompiled source code to a cloud platform, a cloud program execution agent in a main program execution unit 30 of the cloud platform dynamically compiles main program code, a cloud program execution agent of a virtual instance 1 dynamically compiles program code 1, and cloud program execution agents of virtual instances 2 to 5 separately dynamically compile program code 2. In Embodiment 2, a cloud program execution agent in a service virtual instance dynamically compiles the main program code, the cloud program execution agent of the virtual instance 1 dynamically compiles the program code 1, and the cloud program execution agents of the virtual instances 2 to 5 separately dynamically compile the program code 2. A script parser is set in the cloud program execution agent. Based on the foregoing dynamic compilation, the scripting language may be compiled into a bytecode file (that is, the target code) that can be run by the script parser.
Optionally, in Embodiment 1, the program code is the target code, and the tenant may locally compile the program code by using the script parser, compile the main program code, the program code 1, and the program code 2 into bytecode files, and then upload the bytecode files to the cloud platform. In Embodiment 2, the tenant may compile the program code on a service virtual machine by using the script parser, compile the main program code, the program code 1, and the program code 2 into the bytecode files, and send the bytecode files of the program code 1 and the program code 2 to the cloud platform. Then, the cloud platform sends the bytecode file of the program code 1 to a virtual machine 1 for running, and sends the bytecode file of the program code 2 to virtual machines 2 to 5 for running.
When the program code is a non-scripting language, for example, is C++, in Embodiment 1, the program code is the source code, the tenant may directly upload the uncompiled source code to the cloud platform, the cloud program execution agent in the main program execution unit 30 of the cloud platform statically compiles the main program code, the cloud program execution agent of the virtual instance 1 statically compiles the program code 1, and the cloud program execution agents of the virtual instances 2 to 5 separately statically compile the program code 2. In Embodiment 2, the cloud program execution agent in the service virtual instance statically compiles the main program code, the cloud program execution agent of the virtual instance 1 statically compiles the program code 1, and the cloud program execution agents of the virtual instances 2 to 5 separately statically compile the program code 2. A compiler is set in the cloud program execution agent. Based on the foregoing static compilation, the source code may be compiled into a binary executable file (that is, the target code).
Optionally, in Embodiment 1, the program code is the target code, and the tenant may locally compile the program code by using the compiler, compile the main program code, the program code 1, and the program code 2 into binary executable files, and then upload the binary executable files to the cloud platform. In Embodiment 2, the tenant may compile the program code on the service virtual machine by using the compiler, compile the main program code, the program code 1, and the program code 2 into the binary executable files, and send the binary executable files of the program code 1 and the program code 2 to the cloud platform. Then, the cloud platform sends the binary executable file of the program code 1 to the virtual machine 1 for running, and sends the binary executable file of the program code 2 to the virtual machines 2 to 5 for running.
It should be noted that the virtual machines 1 to 5, the main program execution unit 30, and the cloud program execution agent designed above are described in detail below.
Virtual instance: The virtual instance is configured by a cloud platform, and is set with a running environment. The running environment includes an operating system and an application. The virtual instance is, for example, a virtual machine, a container, or a bare metal server.
Service virtual instance: The service virtual instance is a virtual instance created by a tenant on a cloud platform. The tenant may remotely log in to the service virtual instance through a client and run program code on the service virtual instance. The service virtual instance may be used as a production environment or a test environment of the tenant.
Main program code: The main program code, a main program for short, is also referred to as a main function, and in many imperative programming languages, the main function (main function) serves as a place at which a program starts to run.
Subroutine code: The subroutine code is a part of code in a large-scale program, and includes one or more statement blocks. The subroutine code is responsible for completing a task and is relatively independent of other code. In some cases, an input parameter is included, and the subroutine code has a return value (that is, a running result). The subroutine code may be invoked by main program code, and the subroutine code may also be invoked by another piece of subroutine code. Nested program code: The nested program code is subroutine code called during calling of another piece of subroutine code by subroutine code.
Tag: The tag refers to a tag mode of program code that is pre-agreed by a cloud platform. The cloud platform may provide a use method and a format of the tag, so that a tenant can add the tag to program code when writing the program code.
The tag has a function of separating subroutine code. The tag is set adjacent to the subroutine code, and is used to identify that the subroutine code is program code that needs to be executed by a virtual instance having configuration information indicated by the tag. An implementation of the tag is an annotation of the subroutine code, for example, before or after the program code, being @, \\, \, /, //, or another symbol tag pre-agreed with the cloud platform, and configuration information such as a type, a specification, and a number that are of the virtual instance is input in a predetermined format after the symbol. When detecting the symbol, the cloud platform creates a virtual instance based on the type, the specification, and the number that are of the virtual instance indicated after the symbol, and sends the subroutine code to the virtual instance for running. Through the annotation, a programming habit of the tenant does not need to be changed, and the tenant only needs to input the symbol before or after the subroutine code and input the configuration information after the symbol, so as to run the subroutine code by using the virtual instance on a cloud side. The tag may alternatively be set as program code that uses a predetermined syntax and that is adjacent to subroutine code. For example, the cloud platform agrees to use a function creatvirtualinstance (type,spec,N) of the predetermined syntax as the tag. In this case, in a process of writing the program code, the tenant may invoke creatvirtualinstance (type,spec,N) at an adjacent location of the subroutine code (that is, a location before or after the subroutine), and input one or any combination of a type type, a specification spec, and a number N that are of a virtual instance based on a requirement of the tenant. That is, the subroutine code may be tagged, so that the subroutine code runs in a virtual instance created or selected by the cloud platform based on one or any combination of the type type, the specification spec, and the number N.
The client accesses the cloud platform, and the tenant operates the client to access a cloud service provided by the cloud platform.
The client may be, for example, a terminal device that can be operated by the tenant and that can access an internet, for example, a personal computer, a mobile phone, a tablet computer, or an in-vehicle host. The client accesses the data center by using an internet, and accesses the service provided by the cloud platform disposed in the data center.
Both the storage node and the computing node may be implemented by using a physical server. The storage node may provide a shared storage space, for example, an object storage service (OBS) bucket, a shared cache, or a shared database. The storage node is implemented by using a server set with a plurality of physical disks. The cloud platform may configure a virtual instance on the computing node. The virtual instance may be, for example, a virtual machine, a container, and a bare metal server.
The cloud platform is configured to provide a screen or an interface related to the cloud service for the tenant to remotely access the cloud service. The tenant may log in to the cloud platform by using a pre-registered account and password, and after successful login, select and purchase the corresponding cloud service on the cloud service access page provided by the cloud platform. The cloud service is, for example, the object storage service, the virtual machine service, or the container service. In embodiments of the present disclosure, the cloud platform may provide the cloud service for processing the program code of the tenant.
The following separately describes different embodiments in detail based on
In this embodiment, a tenant may upload program code to a cloud platform, or directly write the program code on the cloud platform. Configuration information of a virtual instance is annotated in a part of the program code. The cloud platform configures the virtual instance based on the configuration information, executes the part of program code by using the virtual instance, and obtains a running result of the part of program code from the virtual instance. Finally, the cloud platform notifies the tenant of the running result of the program code.
First, refer to
The cloud platform includes a cloud service providing unit 10, a cloud program execution unit 20, and a main program execution unit 30. The cloud service providing unit 10 is configured to provide a cloud service for the tenant, and the cloud service providing unit 10 includes a virtual instance service interface 101, a program code service interface 102, and a shared storage service interface 103. The client may access the virtual instance service interface 101 to indicate the cloud service providing unit 10 to create, in the data center, a virtual instance accessible to the tenant. In addition, the client may access the shared storage service interface 103 to indicate the cloud service providing unit 10 to create, in the data center, a shared storage space accessible to the tenant. The tenant may upload data to the shared storage space and download data from the shared storage space. The client may further access the program code service interface 102. The client may upload the program code of the tenant to the cloud platform through an upload interface provided by the program code service interface 102, and the cloud platform processes, on a data center side, the program code uploaded by the tenant. Alternatively, the tenant may operate the client to access a program editing screen provided by the program code service interface 102, to write the program code online on the cloud platform, and the cloud platform processes, on the data center side, the program code written by the tenant online.
For example, the shared storage space may be based on an OBS bucket, a shared cache, or a shared database. The virtual instance may be, for example, a virtual machine, a container, or a bare metal server. The program code may be, for example, Java, C++, Python, Ruby, or any other common program language.
The shared storage space may be provided by the storage nodes shown in
The main program execution unit 30 includes a cloud program execution agent. The main program execution unit 30 is configured to run main program code, and the cloud program execution agent is configured to communicate with another cloud program execution agent and execute program code tagged with an annotation.
Alternatively, the main program execution unit 30 may not be used, and the cloud platform may directly use a virtual instance set with a cloud program execution agent to run the main program code.
In this embodiment, the tenant may edit a program on the program editing screen provided by the program code service interface 102 or directly edit the program code locally, and send, by using the client, the edited program code to the upload interface provided by the program code service interface 102. The cloud platform provides a description for the tenant, so that the tenant notifies, in a process of editing the program code, the cloud platform by using a predetermined tag that a specified part of the program code needs to be executed by the virtual instance configured by the cloud platform. The program code service interface 102 may send the program code to the cloud program execution unit 20. The cloud program execution unit 20 sends the main program code in the program code to the main program execution unit 30 for execution; identifies the tag; configures a virtual instance based on configuration information indicated by the tag; and sends the part of program code tagged by the tag to the configured virtual instance for execution, to implement program code execution on a cloud. This can reduce computing load of the client without changing a programming habit of the tenant, thereby improving programming experience of the tenant.
The tag may be an annotation of a segment of program code, or program code that is adjacent to a segment of program code and that is set with a predetermined syntax.
The following uses a Java language as an example. It is assumed that the program code written by the tenant is as follows:
This embodiment of the present disclosure is mainly described with the foregoing program code. As shown in the foregoing program code, program code 1 is invoked in a running process of main program code: public static void main(String [ ]args). The program code 1 is a function runInCloud1(inputDir,outputDir). Program code 2, that is, a function runInCloud2(inputFileList,outputDir), is invoked in a running process of the program code 1, that is, the function runInCloud1(inputDir,outputDir).
Therefore, the program code 1 is subroutine code, the program code 2 is nested program code, and a tag @QtFun(taskNum=1,flavor=“s2.small.1”, type=VM, waitingForFinished=true) and a tag @QtFun(taskNum=4,cpu=1,memory=256, type=VM, waitingForFinished=true) may be used to indicate to the cloud platform that the program code 1 and the program code 2 are separated.
In addition, a tag @QtFun(taskNum=1,flavor=“s2.small.1”, type=VM, waitingForFinished=true) is set adjacent to the function runInCloud1(inputDir,outputDir). @QtFun is a preset tag in this embodiment of the present disclosure, and is used to indicate that the function runInCloud1(inputDir,outputDir) annotated by the tag needs to be executed by a virtual instance, a virtual instance type type is a virtual machine, a virtual machine specification flavor is s2.small.1, a virtual machine number taskNum is 1, and the main program needs to wait for finishing execution of the function to perform a next step (waitingForFinished=true).
Further, a tag @QtFun(taskNum=4,cpu=1,memory=256, type=VM, waitingForFinished=true) is set for the function runInCloud2(inputFileList,outputDir). @QtFun is the preset tag in this embodiment of the present disclosure, and is used to indicate that the function runInCloud2(inputFileList,outputDir) annotated by the tag needs to be executed by a virtual instance, a virtual instance type type is a virtual machine, a processor specification of the virtual machine is 1 core, a memory specification is 256 M, a virtual machine number taskNum is 1, and the main program needs to wait for finishing execution of the function to perform a next step (waitingForFinished=true).
The tag is used to separate different subroutine code. The cloud platform can determine the different subroutine code by detecting the tag.
In this embodiment of the present disclosure, the specification may be determined by a flavor predefined by the cloud platform. For example, a specification indicated by s2.small.1 described above is, for example, a 2-core processor and memory of 512 M. Optionally, the specification may alternatively directly specify a central processing unit (CPU) core number and a memory size. For example, cpu=1, memory=256 is specified in runInCloud2(inputFileList,outputDir). The cloud platform configures the virtual instance based on the configuration information by analyzing the configuration information indicated by the tag.
The program code service interface 102 of the cloud platform sends the program code to the cloud program execution unit 20, and the cloud program execution unit 20 configures the virtual instance based on the configuration information indicated by the tag. According to the foregoing program code, the cloud program execution unit 20 first creates 1 virtual machine to run the program code 1, and when the program code 1 runs to a location at which the program code 2 needs to be invoked, creates 4 virtual machines to run the program code 2 in parallel.
Refer to
Each subroutine code corresponds to a cloud program running area. As shown in
Optionally, the tag may also be //, and an implementation is as follows:
Therefore, @, //, \\, \, /, or another symbol tag pre-agreed with the cloud platform can be used as an implementation of the tag.
It should be noted that, in the foregoing instance code, the program code 1 is subroutine code, and the program code 2 is another subroutine code (that is, nested program code) invoked by the subroutine code. Optionally, in another implementation, it may alternatively be set that the main program code separately invokes two pieces of subroutine code, for example:
In the foregoing program code, the main program code first invokes the program code 2 to transcode data in the OBS bucket, and then invokes the program code 1 to perform a hash operation on H.265 data obtained based on transcoded data in the OBS bucket.
Step S101: A tenant writes program code on a client.
The tenant installs a code editor on the client to write the program code. In addition, the tenant may tag a part of the code in an annotation manner based on a syntax provided by the cloud platform, and indicate configuration information in the tag. The configuration information may be used to indicate one or any combination of a type, a specification, and a number of virtual instances running the part of code. The program code includes main program code, program code 1, and program code 2, which may be, for example, the Java code described above.
Optionally, if the tenant does not indicate the type, the specification, or the number in the tag, the cloud platform configures a virtual instance based on a default type, specification, or number.
Further, the tenant may send the program code written in another place to the client, provided that an annotation is tagged in the program code. A manner of generating the program code is not limited in this embodiment of the present disclosure.
Step S102: The client sends the program code to the cloud platform.
The client sends the program code to a program code service interface 102 in a cloud service providing unit 10.
The program code service interface 102 is implemented as an upload interface, and the upload interface is configured to receive the program code uploaded by the tenant. Optionally, the program code service interface 102 may be implemented as a program code editing screen. The tenant may remotely log in, by operating the client, to the program code editing screen provided by the cloud service providing unit 10, and write the program code online on the program code editing screen.
Step S103: The cloud service providing unit 10 sends the program code to a cloud program execution unit 20.
Step S104: The cloud program execution unit 20 sends the main program code to a main program execution unit 30.
The cloud program execution unit 20 sends the main program code to a program execution unit of the main program execution unit 30.
For example, the main program code is as follows:
Step S105: The cloud program execution unit 20 configures a virtual instance 1 according to a tag of the program code 1.
For example, the tag of the program code 1 is:
@QtFun(taskNum=1,flavor=“s2.small.1”, type=VM, waitingForFinished=true)
The cloud program execution unit 20 analyzes the tag to obtain the following configuration information: a virtual instance whose specification is s2.small.1, type is a virtual machine, and number is 1 needs to be created. When running to a location at which the program code 1 is invoked, the main program code needs to wait for finishing execution of the program code 1 to continue running.
VM indicates the type is a virtual machine. In another embodiment, the type may further include a container container and a bare metal server.
Step S106: The cloud program execution unit 20 sends the program code 1 adjacent to the tag to the configured virtual instance 1.
The program code 1 is:
Service logic of the program code 1 is as follows: a file list in an OBS bucket corresponding to a URL is read, and the program code 2 is invoked. The program code 2 separately performs transcoding processing on each file in the file list. After the program code 2 finishes transcoding, the program code 1 performs a hash operation on a transcoded file, and separately obtains a corresponding hash value for each transcoded file.
Each OBS bucket is located by using a Uniform Resource Locator (URL). After creating the OBS bucket, the cloud platform configures the URL for the OBS bucket and records the URL. The tenant can access the OBS bucket by using the URL.
It should be noted that the OBS bucket mentioned herein is the shared storage space shown in
In this embodiment of the present disclosure, the shared storage space is used to store to-be-processed data, and the to-be-processed data is, for example, a file in the OBS bucket.
In this embodiment of the present disclosure, program code that is disposed adjacent to the tag may be referred to as cloud program code. For example, both the program code 1 and the program code 2 may be referred to as the cloud program code. The cloud program code is executed by the virtual instance configured by the cloud program execution unit 20. In addition, the virtual instance 1 is set in a cloud program running area 1.
Step S107: The main program execution unit 30 executes the main program code to a location at which the program code 1 needs to be invoked, suspends execution of the main program code, and waits for finishing execution of the program code 1.
After executing the main program code to a statement String inputDir=args[2], a cloud program execution agent of the main program execution unit 30 needs to invoke the program code 1: runInCloud1(inputDir,outputDir). Because the program code 1 is tagged as running in the virtual instance, the cloud program execution agent of the main program execution unit 30 needs to request a running result of the program code 1 from the cloud program execution unit 20.
Step S108: The cloud program execution agent of the main program execution unit 30 requests the running result of the program code 1 from the cloud program execution unit 20.
Step S109: The cloud program execution unit 20 requests the running result of the program code 1 from the virtual instance 1.
Step S110: The virtual instance 1 executes the program code 1 to a location at which the program code 2 needs to be invoked, and starts to wait.
A cloud program execution agent of the virtual instance 1 executes the program code 1, and after finishing executing String [ ]inputFileList=Obs.readFileList(inputDir), finds that a next statement needs to invoke the program code 2: runInCloud2(inputFileList,outputDir). Because the program code 1 is tagged as that the program code 1 needs to run in the virtual instance, the cloud program execution agent of the virtual instance 1 needs to request a running result of the program code 2 from the cloud program execution unit 20.
Step S111: The cloud program execution agent of the virtual instance 1 requests the running result of the program code 2 from the cloud program execution unit 20.
Step S112: The cloud program execution unit 20 configures virtual instances 2 to 5 based on configuration information indicated by a tag of the program code 2.
The tag of the program code 2 is @QtFun(taskNum=4,cpu=1,memory=256, type=VM, waitingForFinished=true). The cloud program execution unit 20 creates, based on the configuration information, 4 virtual instances whose type is a virtual machine, and a specification of the virtual instances is 1 CPU core and a memory size of 256 M. In addition, when running to the location at which the program code 2 is invoked, the program code 1 needs to wait for finishing execution of the program code 2 to continue running.
It should be noted that, when waitingForFinished=false, and the program code 1 runs to the location at which the program code 2 is invoked, the program code 1 may directly skip the program code 2, and does not need to wait for finishing execution of the program code 2.
In addition, the virtual instances 2 to 5 are set in a cloud program running area 2.
Step S113: The cloud program execution unit 20 separately sends the program code 2 to the configured virtual instances 2 to 5.
Step S114: The virtual instances 2 to 5 separately execute the program code 2.
Cloud program execution agents of the virtual instances 2 to 5 separately execute the program code 2.
In this step, the virtual instances 2 to 5 execute the same program code 2, to run same service logic. The service logic of the program code is as follows:
Each of the virtual instances 2 to 5 obtains a task identifier taskId of each of the virtual instances 2 to 5 according to QtContext.getTaskIndex( ) When running QtContext.getTaskIndex( ), the virtual instance sends a request to the cloud program execution unit 20. The cloud program execution unit 20 returns taskId to the virtual instance based on the request, and taskIds of the virtual instances 2 to 5 are different and arranged in sequence, for example, taskId of the virtual instance 2 is 0, taskId of the virtual instance 3 is 1, taskId of the virtual instance 4 is 2, and taskId of virtual instance 5 is 3.
For each file in the file list, if a remainder obtained by performing a modulo operation on a sequence number i of the file and the virtual instance number 4 is equal to taskId of the virtual instance, the file whose sequence number is i is transcoded by the virtual instance, and transcodingToH265(fileList[i],outputDir+“/”+i+“.mp4”) is used to transcode an ith file in the file list to a file in an H265 format.
After finishing running the program code 2, each virtual instance records the running result of the program code 2. The running result is, for example, 1 or 0, where 1 indicates that running succeeds, and 0 indicates that running fails. In this embodiment, it is assumed that each virtual instance successfully runs the program code 2, and therefore, the running result of the program code 2 recorded by each of the virtual instances 2 to 5 is 1.
Therefore, in this step, the cloud platform provides the to-be-processed data, and the program code 2 is used to indicate the virtual instances 2 to 5 to obtain the to-be-processed data from the cloud platform and execute the service logic of the program code 2 based on the to-be-processed data.
Further, QtContext.getTaskIndex( ) is a message queue service API provided by the cloud platform, which is defined by the cloud program execution unit 20 of the cloud platform. When invoking QtContext.getTaskIndex( ), the virtual instance sends a request to the cloud program execution unit 20, and the cloud program execution unit 20 returns taskId to the virtual instance based on the request.
It should be noted that, the cloud program execution unit 20 of the cloud platform may further provide another cloud service besides a message queue service and set a cloud service API for the cloud service. When a corresponding cloud service API is set in the program code, the cloud service API may be configured to indicate the virtual instance to invoke the cloud service provided by the cloud platform when being invoked. The cloud service API further includes an object storage service API, a database service API, and a shared cache service API. For example, the object storage service API is Obs.readFileList(outputDir,URL).
When the virtual instance runs the object storage service API, the URL of the OBS bucket needs to be entered, so that the cloud program execution unit 20 locates a to-be-accessed OBS bucket according to the URL, and the virtual instance may access the OBS bucket by using the cloud program execution unit 20.
When the virtual instance runs the database service API, a name of a database, an account, and a password need to be entered, so that the cloud program execution unit 20 locates the database, and logs in to the database by using the account and the password, and the virtual instance may access the database by using the cloud program execution unit 20.
When the virtual instance runs the shared cache service API, a name of a shared cache needs to be entered, so that the cloud program execution unit 20 can locate the shared cache according to the name, and the virtual instance can share the cache by using the cloud program execution unit 20.
Step S115: The cloud program execution unit 20 separately requests the running result of the program code 2 from each of the virtual instances 2 to 5.
The cloud program execution unit 20 separately sends a request for the running result of the program code 2 to the cloud program execution agents of the virtual instances 2 to 5.
Step S116: The virtual instances 2 to 5 separately returns the running result of the program code 2 to the cloud program execution unit 20.
The cloud program execution agents of the virtual instances 2 to 5 separately return the running result of the program code 2 to the cloud program execution unit 20.
Step S117: The cloud program execution unit 20 returns the running result of the program code 2 to the virtual instance 1.
The cloud program execution unit 20 returns the running result of the program code 2 to the cloud program execution agent of the virtual instance 1.
Step S118: The virtual instance 1 continues running the program code 1.
The cloud program execution agent of the virtual instance 1 continues running the program code 1 based on the running result of the program code 2, and executes remaining statements:
After execution of the foregoing statements is finished, the running result of the program code 1 is recorded (it is assumed that execution is successful, and the running result is 1).
Step S119: The virtual instance 1 sends the running result of the program code 1 to the cloud program execution unit 20.
The cloud program execution agent of the virtual instance 1 sends the running result of the program code 1 to the cloud program execution unit 20. This step is used as a response to step 108.
Step S120: The cloud program execution unit 20 sends the running result of the program code 1 to the main program execution unit 30.
The cloud program execution unit 20 sends the running result of the program code 1 to the cloud program execution agent of the main program execution unit 30.
Step S121: The main program execution unit 30 continues executing the main program code.
The cloud program execution agent of the main program execution unit 30 continues executing the main program code based on a running result of the program code 1.
Step S122: Running of the main program code is finished.
Step S123: The cloud program execution agent of the main program execution unit 30 notifies the cloud service providing unit 10 that running of the main program code is finished.
Step S124: The cloud service providing unit 10 notifies the client that the main program code runs successfully.
The cloud service providing unit 10 notifies, by using the program code service interface 102, the client that running of the main program code is finished.
In this case, the tenant learns, from the program code service interface 102 by using the client, that running of the program code is finished, and transcoding and hash value operation processing are performed on the data in the OBS bucket.
It should be noted that, in the foregoing embodiment, the virtual instance number is not limited as long as a computing capability of the data center permits. For example, the tenant may select 1 to 1000 virtual instances to perform parallel computing on different to-be-processed data based on same program logic.
In addition, in Embodiment 1, only one data center is disclosed. In another embodiment of the present disclosure, there may be more than one data center. For a scenario of cross-data center cooperation, the tenant may select to configure more virtual instances.
Further, for step S105 and step S112 of configuring the virtual instance, the cloud platform may create a virtual instance on a physical server based on configuration information indicated by a tag; or the cloud platform pre-creates a plurality of virtual instances, and selects, from the plurality of virtual instances, a virtual instance that matches the configuration information indicated by the tag.
In addition, the tag is an annotation of the program code 1 or the program code 2. However, in another embodiment of the present disclosure, the tag may be other program code that uses a predetermined syntax and that is adjacent to the program code 1 or the program code 2.
Optionally, the tag may be any tag pre-agreed with the cloud platform.
In conclusion, according to this embodiment of the present disclosure, the program code of the tenant can be executed on the data center side. In addition, the tenant does not need to change the programming habit of the tenant, and can write the program code by using a programming language commonly used by the tenant. The tenant only needs to tag the part of program code that needs to be executed on the virtual instance, and set, in the tag, the configuration information of the virtual instance running the program code. The cloud platform creates or selects, according to the tag, the virtual instance matching the configuration information, sends the program code to the virtual instance for running, and obtains the running result from the virtual instance, so that the program code can run by using the virtual instance. For scenarios such as big data processing, a neural network, and large-scale application program development, because the computing capability of the data center is fully used, and an entry threshold is low (the tenant only needs to tag program code), convenience of performing large-scale parallel computing by using the cloud resource by the tenant can be greatly improved.
In this embodiment, a tenant may create a service virtual instance in a data center by using a cloud platform, and write program code on the service virtual instance or send the program code from another device to the service virtual instance. The program code runs in the service virtual instance, and configuration information of a virtual instance is annotated in a part of the program code. When running to the part of program code, the service virtual instance notifies the cloud platform to configure the virtual instance based on the configuration information, execute the part of program code by using the virtual instance, and obtain a running result of the part of program code from the virtual instance. Finally, the service virtual instance notifies the tenant of the running result of the program code.
For details, refer to
In comparison with Embodiment 1, in Embodiment 2, the program code directly runs in a production environment or a test environment (that is, the service virtual instance) of the tenant, and in a running process of the program code, a tagged part of the program code runs by using the virtual instance configured on the cloud platform, which can also improve convenience of performing large-scale parallel computing by using a cloud resource by the tenant. In addition, in Embodiment 2, the program code directly runs in the production environment, and in a scenario in which the tenant purchases the service virtual instance, the program code is directly executed on the service virtual instance, so that a use habit of the tenant can be better complied.
The program code exemplified in this embodiment is consistent with the Java code shown in Embodiment 1. The service virtual instance of the tenant is created by the tenant by using a client to access a virtual instance service interface 101 in a service providing unit of the cloud platform. After the service virtual instance is created, the tenant may remotely log in to the service virtual instance by using the client. After the tenant creates the service virtual instance, the cloud platform may provide an installation file of a cloud program execution agent, and the tenant may download the installation file and install the installation file in the service virtual instance.
Optionally, the cloud program execution agent may also be pre-installed in the service virtual instance.
The service virtual instance directly runs the program code. The cloud program execution agent of the service virtual instance may identify a tag, configure a virtual instance according to the tag, and send a part of program code set with the tag to the configured virtual instance for execution, to implement program code execution on a cloud. This can reduce computing load of the client without changing a programming habit of the tenant, thereby improving programming experience of the tenant.
Refer to
Refer to
Step S201: A client sends a service virtual instance creation request to a cloud platform.
A tenant operates the client to access a virtual instance service interface 101 of a cloud service providing unit 10, and selects a type and a specification of a service virtual instance in the virtual instance service interface 101. The cloud platform creates the service virtual instance corresponding to the type and the specification.
Step S202: The cloud platform creates the service virtual instance.
The cloud service providing unit 10 of the cloud platform creates the service virtual instance corresponding to the type and the specification.
Step S203: The tenant remotely logs in to the service virtual instance by using the client, and develops program code on the service virtual instance.
Optionally, the tenant may operate the service virtual instance to download the program code from another device.
Step S204: The service virtual instance runs main program code.
A cloud program execution agent of the service virtual instance runs the main program code:
Step S205: The service virtual instance runs the main program code to a location at which program code 1 needs to be invoked, and starts to wait.
After running a statement String inputDir=args[2], the cloud program execution agent of the service virtual instance starts to wait.
Step S206: The service virtual instance sends the program code 1 and program code 2 to a cloud program execution unit 20.
The cloud program execution agent of the service virtual instance identifies, according to a tag @QtFun(taskNum=1,flavor=“s2.small.1”, type=VM, waitingForFinished=true), that the program code 1 annotated by the tag is program code that needs to be executed by a virtual instance, and sends the program code 1 to the cloud program execution unit 20.
Similarly, the cloud program execution agent of the service virtual instance identifies, according to a tag @QtFun(taskNum=4,cpu=1,memory=256, type=VM, waitingForFinished=true), that the program code 2 annotated by the tag is program code that needs to be executed by a virtual instance, and sends the program code 2 to the cloud program execution unit 20.
Step S207: The cloud program execution unit 20 configures a virtual instance 1 according to the tag @QtFun(taskNum=1,flavor=“s2.small.1”, type=VM, waitingForFinished=true).
The cloud program execution unit 20 analyzes the tag to obtain the following information: a virtual instance whose specification is s2.small.1, type is a virtual machine, and number is 1 needs to be created. When running to the location at which the program code 1 is invoked, the main program code needs to wait for finishing execution of the program code 1 to continue running.
Step S208: The cloud program execution unit 20 sends the program code 1 to the configured virtual instance 1.
Step S209: The cloud program execution agent of the service virtual instance requests a running result of the program code 1 from the cloud program execution unit 20.
Step S210: The cloud program execution unit 20 requests the running result of the program code 1 from the virtual instance 1.
Step S211: A cloud program execution agent of the virtual instance 1 executes the program code 1 to a location at which the program code 2 needs to be invoked, and starts to wait.
Step S212: The virtual instance 1 requests a running result of the program code 2 from the cloud program execution unit 20.
Step S213: The cloud program execution unit 20 configures virtual instances 2 to 5 based on configuration information indicated by a tag of the program code 2.
Step S214: The cloud program execution unit 20 separately sends the program code 2 to the configured virtual instances 2 to 5.
Step S215: The virtual instances 2 to 5 separately execute the program code 2.
Step S216: The cloud program execution unit 20 requests the running result of the program code 2 from each of the virtual instances 2 to 5.
Step S217: Each of the virtual instances 2 to 5 sends the running result of the program code 2 to the cloud program execution unit 20.
Step S218: The cloud program execution unit 20 sends the running result of the program code 2 to the virtual instance 1.
Step S219: The cloud program execution agent of the virtual instance 1 receives the running result of the program code 2, and continues running the program code 1 based on the running result, to generate the running result of the program code 1.
Step S220: The virtual instance 1 sends the running result of the program code 1 to the cloud program execution unit 20.
Step S221: The cloud program execution unit 20 sends the running result of the program code 1 to the cloud program execution agent of the service virtual instance.
Step S222: The cloud program execution agent of the service virtual instance ends waiting based on the running result of the program code 1, and continues executing the main program code.
Step S223: The cloud program execution agent of the service virtual instance finishes running remaining main program code.
So far, the tenant logs in to the service virtual instance by using the client and learns, from the cloud program execution agent of the service virtual instance, that running of the program code is finished, and transcoding and hash value operation processing are performed on data in an OBS bucket.
In Embodiment 2, except that an execution body of a main program code is a service virtual machine, other aspects are basically the same as those in Embodiment 1. It should be noted that, similar to Embodiment 1, in this embodiment, a virtual instance number is not limited as long as a computing capability of a data center (depending on a number of idle physical servers) permits. For example, the tenant may select 1 to 1000 virtual instances to perform parallel computing on different to-be-processed data based on same program logic.
In addition, in Embodiment 2, only one data center is disclosed. In another embodiment of the present disclosure, there may be more than one data center. For a scenario of cross-data center cooperation, the tenant may select to configure more virtual instances.
Further, for step S207 and step S213 of configuring the virtual instance, the cloud platform may create the virtual instance on a physical server based on the configuration information indicated by the tag; or the cloud platform pre-creates a plurality of virtual instances, and selects, from the plurality of virtual instances, a virtual instance that matches the configuration information indicated by the tag.
In addition, the tag is an annotation of the program code 1 or the program code 2. However, in another embodiment of the present disclosure, the tag may be other program code that uses a predetermined syntax and that is adjacent to the program code 1 or the program code 2.
In conclusion, according to this embodiment of the present disclosure, the program code of the tenant can be executed on the data center side. In addition, the tenant does not need to change the programming habit of the tenant, and can write the program code by using a programming language commonly used by the tenant. The tenant only needs to tag the part of program code that needs to be executed on the virtual instance, and set, in the tag, the configuration information of the virtual instance running the program code. The cloud platform creates or selects, according to the tag, the virtual instance matching the configuration information, sends the program code to the virtual instance for running, and obtains the running result of the program code from the virtual instance, so that the program code can run by using the virtual instance. For scenarios such as big data processing, a neural network, and large-scale application program development, because the computing capability of the data center is fully used, and an entry threshold is low (the tenant only needs to tag program code), convenience of performing large-scale parallel computing by using the cloud resource by the tenant can be greatly improved.
In comparison with Embodiment 1, in Embodiment 2, the program code directly runs in a production environment or a test environment (that is, the service virtual instance) of the tenant, and in a running process of the program code, a tagged part of the program code runs in the virtual instance configured on the cloud platform, which can improve convenience of performing large-scale parallel computing by using the cloud resource by the tenant. In addition, in Embodiment 2, because the program code directly runs in the production environment, in a scenario in which the tenant purchases the service virtual instance, a use habit of the tenant can be better complied.
It should be noted that, in Embodiment 1 and Embodiment 2, the main program code invokes the program code 1, and then the program code 1 invokes the program code 2. However, it should be noted that embodiments of the present disclosure are not limited thereto. The main program code may separately invoke the program code 1 and the program code 2. The tenant may alternatively enable, based on an actual requirement, the main program code to invoke more program code 1, and the program code 1 may nest and invoke more layers of program code 2.
Further, in the foregoing embodiments, the virtual instances 2 to 5 configured by the cloud program execution unit 20 based on the configuration information indicated by the tag may be released after the virtual instances 2 to 5 return the running result of the program code 2 to the cloud program execution unit 20, and the virtual instance 1 may be released after the virtual instance 1 returns the running result of the program code 1 to the cloud program execution unit 20. Releasing means, for example, stopping running of the virtual instance, and de-registering the virtual instance from the physical server or clearing data recorded in a memory of the virtual instance. Releasing the virtual instance in time can improve a resource use efficiency of the virtual instance.
It should be noted that the cloud program execution agent in embodiments of the present disclosure is set in the virtual machine, the container, and the bare metal server. The cloud program execution unit 20 may communicate with the cloud program execution agent, to control the virtual machine, the container, and the bare metal server to execute the cloud program code.
Therefore, in embodiments of the present disclosure, a compilation technology enables a developer to keep a programming habit, and further the developer can directly use, in a programming process, computing power provided by a cloud environment, so that complex programming does not need to be learned, and subsequent design and development of an entire distributed system do not need to be performed.
Further, refer to
In addition, an embodiment of the present disclosure further provides a computer storage medium, including computer-readable instructions. When the computer-readable instructions are executed, the method performed by the cloud platform in Embodiment 1 and/or Embodiment 2 is implemented.
An embodiment of the present disclosure further provides a computer program product including instructions. When the computer program product runs on a computer, the computer is enabled to perform the method performed by the cloud platform in Embodiment 1 and/or Embodiment 2.
Based on the description of the foregoing implementations, a person skilled in the art may clearly understand that this disclosure may be implemented by software in addition to necessary universal hardware, or by dedicated hardware, including a dedicated integrated circuit, a dedicated CPU, a dedicated memory, a dedicated component, and the like. Generally, any functions that can be performed by a computer program can be easily implemented by using corresponding hardware. Moreover, a hardware structure used to achieve a same function may be in various forms, for example, in a form of an analog circuit, a digital circuit, or a dedicated circuit. However, as for this disclosure, software program implementation is a better implementation in most cases. Based on such an understanding, the technical solutions of this disclosure essentially or the part contributing to other technologies may be implemented in a form of a software product. The computer software product is stored in a readable storage medium, such as a floppy disk, a Universal Serial Bus (USB) flash drive, a removable hard disk, a read-only memory (ROM), a random-access memory (RAM), a magnetic disk, or an optical disc of a computer, and includes several instructions for instructing a computer device (which may be a personal computer, a training device, or a network device) to perform the methods in embodiments of this disclosure.
All or some of the foregoing embodiments may be implemented by using software, hardware, firmware, or any combination thereof. When software is used to implement the embodiments, all or some of the embodiments may be implemented in a 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 the computer, all or some of the procedures or functions in embodiments of this disclosure are generated. The computer may be a general-purpose computer, a dedicated computer, a computer network, or other programmable apparatuses. The computer instructions may be stored in a computer-readable storage medium or may be transmitted from a computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, training device, or data center to another website, computer, training device, or data center in a wired (for example, a coaxial cable, an optical fiber, or a digital subscriber line (DSL)) or wireless (for example, infrared, radio, or microwave) manner. The computer-readable storage medium may be any usable medium that can be stored by a computer, or a data storage device, such as a training device or a data center, integrating one or more usable media. The usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, or a magnetic tape), an optical medium (for example, a digital versatile disc (DVD)), a semiconductor medium (for example, a solid-state disk (SSD)), or the like.
Number | Date | Country | Kind |
---|---|---|---|
202011063410.2 | Sep 2020 | CN | national |
202110394141.6 | Apr 2021 | CN | national |
This is a continuation of International Patent Application No. PCT/CN2021/121245 filed on Sep. 28, 2021, which claims priority to Chinese Patent Application No. 202011063410.2 filed on Sep. 30, 2020 and Chinese Patent Application No. 202110394141.6 filed on Apr. 13, 2021. All of the aforementioned patent applications are hereby incorporated by reference in their entireties.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2021/121245 | Sep 2021 | US |
Child | 18192988 | US |