Background
With the progress of science and technology, various WEB applications are developed endlessly, and the occupied system resources of the WEB applications are more and more, so that how to efficiently support the operation of the WEB applications is a technical problem which needs to be solved urgently at present.
At present, a mode of improving hardware capability, such as increasing a memory, increasing a CPU running hertz, and the like, is often used to support the problem that the WEB application occupies too many system resources, and although the mode can effectively support the WEB application running, too many hardware resources are consumed at the same time, which causes a problem of hardware resource waste.
Content of application
In order to solve the technical problems or at least partially solve the technical problems, the application provides a method, an apparatus, an electronic device and a computer-readable storage medium for running a WEB-based application, which can avoid the problem of hardware resource waste caused by excessive consumption of hardware resources.
In a first aspect, the present application provides a method for running an application based on WEB, where the method includes:
receiving a WEB operation instruction, addressing a corresponding WEB application according to the WEB operation instruction, and starting a pre-constructed WEB service container;
taking the WEB service container as the operation environment of the WEB application to obtain a WEB application container;
establishing a WEB middleware according to the WEB application container, and connecting a pre-constructed application container engine by using the WEB middleware;
when the WEB middleware is successfully connected with the application container engine, mirroring the operating system where the WEB application container is located by using the application container engine to obtain a mirroring system;
and binding the mirror image system and a bottom layer interface of the operating system, generating a WEB operating environment corresponding to the WEB application, starting the WEB application container by utilizing the WEB operating environment, and completing the operation of the WEB application.
It can be seen that, in the embodiment of the present application, an operating environment belonging to a WEB application is mainly constructed first, so as to obtain a WEB application container, but since the WEB application container and an operating system where the WEB application is located cannot perform information interaction, an application container engine pre-installed in the operating system and a WEB middleware are used as a bridge for information interaction, and a mirror system corresponding to the WEB application container is constructed at the same time, and a support is provided for the operation of the WEB application under the dual support of the mirror system and the operating system.
In a possible implementation manner of the first aspect, the creating a WEB middleware according to the WEB application container includes:
analyzing the programming language corresponding to the WEB application container to obtain an analysis language;
generating a test instruction according to the analysis language, and calling the application container engine to generate a language analysis container;
and testing the WEB application container by using the test instruction and the language analysis container, and if the test is passed, generating the WEB middleware according to the language analysis container.
In a possible implementation manner of the first aspect, the testing the WEB application container by using the test instruction and the language parsing container, and if the test is passed, generating the WEB middleware according to the language parsing container includes:
capturing the running state parameters of the WEB application container in real time;
taking the language analysis container as a carrier, and transmitting the running state parameters to the application container engine;
when the application container engine successfully receives the running state parameters, closing the WEB application container by using the test instruction within preset time, and judging whether the language analysis container can successfully release system resources of the WEB application container or not;
if the language analysis container can not release the system resources of the WEB application container, generating error reporting information to developers of the WEB application container;
and if the language analysis container can successfully release the system resources of the WEB application container, generating the WEB middleware by using the language analysis container.
In a possible implementation manner of the first aspect, the mirroring an operating system in which the WEB application container is located by using the application container engine to obtain a mirroring system includes:
acquiring system version information of an operating system in which the WEB application container is located;
generating mirror image system information by using the system version information and the application container engine;
and generating the mirror image system according to the mirror image system information and the mirror image instruction corresponding to the application container engine.
In a possible implementation manner of the first aspect, the generating, by using the system version information and the application container engine, mirrored system information includes:
performing a mirror marking and an ID marking on the system version information by using the application container engine;
indexing a version size of the system version information with the application container engine;
and generating the mirror image system information according to the version size and the marked system version information.
In a possible implementation manner of the first aspect, the building process of the pre-built WEB service container includes:
in the operating system, finding and obtaining the application container engine;
creating a namespace process using the application container engine;
and according to the operating system, the name space process is assigned to be referred to, and the WEB service container is obtained.
In a possible implementation manner of the first aspect, the assigning, according to the operating system, the namespace process to obtain the WEB service container includes:
according to the configuration file of the operating system, limiting the resource upper limit of the name space process in the operating system, and setting the priority of the name space process to obtain a resource space process;
and documenting the resource space process in the operating system to obtain the WEB service container.
In a second aspect, the present application provides a WEB-based application running apparatus, where the apparatus is applied to one master browser among multiple browsers, and includes:
the WEB service container starting module is used for receiving a WEB operation instruction, addressing the corresponding WEB application according to the WEB operation instruction and starting a pre-constructed WEB service container;
the WEB application container generating module is used for taking the WEB service container as the running environment of the WEB application to obtain a WEB application container;
the connection module is used for creating a WEB middleware according to the WEB application container and connecting a pre-constructed application container engine by using the WEB middleware;
and the WEB application running module is used for mirroring the operating system where the WEB application container is located by using the application container engine to obtain a mirroring system when the WEB middleware is successfully connected with the application container engine, binding the mirroring system and a bottom layer interface of the operating system, generating a WEB operating environment corresponding to the WEB application, and starting the WEB application container by using the WEB operating environment to finish the running of the WEB application.
In a third aspect, the present application provides an electronic device, comprising:
at least one processor; and a memory communicatively coupled to the at least one processor;
wherein the memory stores computer programs executable by the at least one processor to enable the at least one processor to perform the WEB-based application execution method according to any of the first aspects.
In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program, which when executed by a processor implements the WEB-based application execution method according to any one of the first aspects.
It is understood that the beneficial effects of the second to fourth aspects can be seen from the description of the first aspect, and are not described herein again.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
A method for running a WEB-based application according to an embodiment of the present application is described with reference to a flowchart shown in fig. 1. The method comprises the following steps:
and S1, receiving a WEB operation instruction, addressing the corresponding WEB application according to the WEB operation instruction, and starting a pre-constructed WEB service container.
In the embodiment of the application, the WEB operation instruction includes a pre-constructed graphical display button, a programming character instruction and the like, if a user wants to start a WEB application constructed based on the WEB, the user includes WEB applications such as a browser and an APP, and then directly clicks the graphical display button of the browser and the APP, so that the WEB operation instruction can be automatically generated and addressed to the WEB application corresponding to the WEB operation instruction.
Further, after the WEB operation instruction is generated, in order to ensure the security of the user using the WEB application, the WEB application is not directly started according to the operating system where the WEB application is located, but the pre-constructed WEB service container is started first. The WEB service container is constructed based on an application container engine and is a process capable of realizing independent constraint and independent modification.
In an embodiment of the present invention, referring to fig. 2, the constructing of the pre-constructed WEB service container includes:
s11, finding an application container engine in an operating system where the WEB application is located;
s12, creating a namespace process by utilizing the application container engine;
and S13, according to the operating system, assigning reference to the namespace process to obtain the WEB service container.
In the embodiment of the invention, the operating system comprises a Windows system, a Linux system and the like. The application container engine may use Docker, which is an application container engine developed based on Go language and apache2.0 protocol.
The operating system where the browser to be started is located is a Linux system, and after a Docker is installed in the Linux system, an instruction is created through a namespace of the Docker: and creating the namespace process by using the 'docker run-it busybox/bin/sh'.
Further, because the basic configuration of the operating environment of the WEB service container needs to be the same as the operating system where the WEB application is located to ensure the normal operation of the WEB application, the assigning reference to the namespace process according to the operating system to obtain the WEB service container includes:
according to the configuration file of the operating system, limiting the resource upper limit of the name space process in the operating system, and setting the priority of the name space process to obtain a resource space process;
and documenting the resource space process in the operating system to obtain the WEB service container.
For example, in the Linux operating system, the upper limit of the resources that can be used by the namespace process is limited to include a CPU, a memory, a disk, a network bandwidth, and the like, and for the convenience of user operation, the resource space process needs to be exposed, that is, the WEB service container exists in the Linux operating system in a file and directory manner.
Further, the starting of the pre-built WEB services container includes:
searching a file path where the WEB service container is located;
in the file path, a database to be mounted by the WEB service container and a configuration file of the WEB service container are specified;
and starting the WEB service container according to the database and the configuration file of the WEB service container.
If the file path of the WEB service container is/bin/sh, the database corresponding to the WEB service container is mounted in the/bin/sh by using a database mounting instruction of a Docker, a configuration file is extracted from the Docker, and the WEB service container can be started through the configuration file and the mounted database.
And S2, taking the WEB service container as the operation environment of the WEB application to obtain a WEB application container.
In the embodiment of the present invention, two WEB service containers are created at the same time, which are a first WEB service container and a second WEB service container, respectively, and the first WEB service container is used as the operating environment of the browser, and the second WEB service container is used as the operating environment of the APP, so that a browser application container and an APP application container can be obtained, respectively.
Furthermore, the WEB application containers run independently, exist independently, do not interfere with each other, and depend on the same operating system, such as the browser application container and the APP application container, which work together without interfering with each other, but depend on the Linux operating system.
And S3, creating WEB middleware according to the WEB application container, and connecting a pre-constructed application container engine by using the WEB middleware.
Since the WEB application container is generally directly interfaced with the user, receives the user operation instruction, and returns a corresponding response result in response to the user operation instruction, it can be seen from the above that, since the WEB application container is constructed based on the application container engine and depends on the operating system, the application container engine and the operating system are required to cooperate with the WEB application container to complete the response of the user operation.
Therefore, in the embodiment of the present invention, a WEB middleware needs to be further created to assist information communication between a WEB application container and an application container engine and an operating system, and in detail, referring to fig. 3, the creating a WEB middleware according to the WEB application container includes:
s31, analyzing the programming language corresponding to the WEB application container to obtain an analysis language;
s32, generating a test instruction according to the analysis language, and calling the application container engine to generate a language analysis container;
and S33, testing the WEB application container by using the test instruction and the language analysis container, and if the test is passed, generating the WEB middleware according to the language analysis container.
Because there is an information transmission obstacle between the WEB applications in different programming languages and the operating system and the application container engine, for example, the browser is constructed based on the HTML language, the APP is constructed based on the JAVA language, and the operating system and the application container engine cannot be analyzed in real time, the WEB middleware is required to analyze information in different programming languages and transmit the information to the operating system and the application container engine.
In the embodiment of the invention, the application container engine such as Docker can generate corresponding language analysis containers such as HTML language analysis containers and JAVA language analysis containers according to different programming languages.
Furthermore, after the language analysis container is generated, it is necessary to perform a test function by using the language analysis container to check whether the language analysis container has the functions of information analysis and transmission.
In detail, the testing the WEB application container by using the test instruction and the language parsing container, and if the test is passed, generating the WEB middleware according to the language parsing container includes:
capturing the running state parameters of the WEB application container in real time;
taking the language analysis container as a carrier, and transmitting the running state parameters to the application container engine;
when the application container engine successfully receives the running state parameters, closing the WEB application container by using the test instruction within preset time, and judging whether the language analysis container can successfully release system resources of the WEB application container or not;
if the language analysis container can not release the system resources of the WEB application container, generating error reporting information to developers of the WEB application container;
and if the language analysis container can successfully release the system resources of the WEB application container, generating the WEB middleware by using the language analysis container.
In the embodiment of the invention, the application container engine is pre-installed in the operating system, so that whether the information communication between the application container engine and the WEB application container is wrong or not only needs to be tested, and when the information communication between the application container engine and the WEB application container is correct, the language analysis container is the WEB middleware.
It can be understood that, after the WEB middleware is utilized to test the executable information communication between the application container engine and the WEB application container, the WEB middleware and the application container engine can be naturally and smoothly connected.
And S4, when the WEB middleware is successfully connected with the application container engine, mirroring the operating system where the WEB application container is located by using the application container engine to obtain a mirroring system.
As can be seen from the above, the WEB application container is only a WEB service container created by the application container engine, and supports the WEB application to perform data transmission, and thus the stability is poor, and therefore, a mirror system needs to be installed in the WEB application container, and the stability of the WEB application container is improved.
In detail, referring to fig. 4, the mirroring system obtained by mirroring the operating system where the WEB application container is located by using the application container engine includes:
s41, acquiring system version information of the operating system where the WEB application container is located;
s42, generating mirror image system information by using the system version information and the application container engine;
and S43, generating the mirror image system according to the mirror image system information and the mirror image instruction corresponding to the application container engine.
As described above, the operating system in which the WEB application container is located is the Linux operating system, and the corresponding system version information includes ubuntu, version number 12.04, and the like.
After obtaining the system version information, generating mirror image system information by using the system version information and the application container engine, including:
performing a mirror marking and an ID marking on the system version information by using the application container engine;
indexing a version size of the system version information with the application container engine;
and generating the mirror image system information according to the version size and the marked system version information.
Further, the mirror instruction corresponding to the application container engine is different according to the different types of the application container engines, for example, the mirror instruction of Docker includes: a sudo docker registry.
And S5, binding the mirror image system and the bottom layer interface of the operating system, generating a WEB operating environment corresponding to the WEB application, and starting the WEB application container by using the WEB operating environment to complete the operation of the WEB application.
In the embodiment of the present invention, if the operating system where the browser is located is a Linux operating system, the corresponding mirror system is also a Linux operating system, and the mirror system is bound to an underlying interface, such as a CPU, a video memory, and other interfaces, so that the mirror system can serve a WEB application, that is, the WEB operating environment is generated.
Furthermore, in the embodiment of the invention, the corresponding WEB application container can be started by utilizing the WEB operation environment, so that the support for WEB application operation is realized.
It can be seen that, in the embodiment of the present application, an operating environment belonging to a WEB application is mainly constructed first, so as to obtain a WEB application container, but since the WEB application container and an operating system where the WEB application is located cannot perform information interaction, an application container engine pre-installed in the operating system and a WEB middleware are used as a bridge for information interaction, and a mirror system corresponding to the WEB application container is constructed at the same time, and a support is provided for the operation of the WEB application under the dual support of the mirror system and the operating system.
Fig. 5 is a functional block diagram of the WEB-based application execution apparatus according to the present invention.
The WEB-based application execution apparatus 500 according to the present application may be installed in an electronic device. According to the realized functions, the WEB-based application execution device may include a WEB service container starting module 501, a WEB application container generating module 502, a connecting module 503, and a WEB application execution module 504. A module according to the present invention, which may also be referred to as a unit, refers to a series of computer program segments that can be executed by a processor of an electronic device and that can perform a fixed function, and that are stored in a memory of the electronic device.
In the present embodiment, the functions regarding the respective modules/units are as follows:
the WEB service container starting module 101 is configured to receive a WEB operation instruction, address a corresponding WEB application according to the WEB operation instruction, and start a pre-constructed WEB service container;
the WEB application container generating module 102 is configured to use the WEB service container as an operating environment of the WEB application to obtain a WEB application container;
the connection module 103 is configured to create a WEB middleware according to the WEB application container, and connect a pre-constructed application container engine by using the WEB middleware;
the WEB application running module 104 is configured to, when the WEB middleware is successfully connected to the application container engine, mirror an operating system where the WEB application container is located by using the application container engine to obtain a mirror system, bind the mirror system and a bottom layer interface of the operating system, generate a WEB operating environment corresponding to the WEB application, and start the WEB application container by using the WEB operating environment to complete running of the WEB application.
In detail, when the modules in the WEB-based application running apparatus 500 in the embodiment of the present application are used, the same technical means as the WEB-based application running method described in fig. 1 and fig. 4 are used, and the same technical effect can be produced, and details are not described here again.
Fig. 6 is a schematic structural diagram of an electronic device for implementing the WEB-based application running method according to the present application.
The electronic device 6 may include a processor 60, a memory 61, a communication bus 62 and a communication interface 63, and may further include a computer program, such as a WEB-based application execution program, stored in the memory 61 and executable on the processor 60.
In some embodiments, the processor 60 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 60 is a Control Unit (Control Unit) of the electronic device, connects various components of the whole electronic device by using various interfaces and lines, and executes various functions and processes data of the electronic device by executing or executing programs or modules (e.g., executing WEB-based application execution programs and the like) stored in the memory 61 and calling data stored in the memory 61.
The memory 61 includes at least one type of readable storage medium including flash memory, removable hard disks, multimedia cards, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disks, optical disks, etc. The memory 61 may in some embodiments be an internal storage unit of the electronic device, for example a removable hard disk of the electronic device. The memory 61 may also be an external storage device of the electronic device in other embodiments, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the electronic device. Further, the memory 61 may also include both an internal storage unit and an external storage device of the electronic device. The memory 61 may be used not only to store application software installed in the electronic device and various types of data, such as codes of WEB-based application execution programs, etc., but also to temporarily store data that has been output or is to be output.
The communication bus 62 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is arranged to enable connection communication between the memory 61 and at least one processor 60 or the like.
The communication interface 63 is used for communication between the electronic device and other devices, and includes a network interface and a user interface. Optionally, the network interface may include a wired interface and/or a wireless interface (e.g., WI-FI interface, bluetooth interface, etc.), which are typically used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a Display (Display), an input unit such as a Keyboard (Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable, among other things, for displaying information processed in the electronic device and for displaying a visualized user interface.
Fig. 6 shows only an electronic device having components, and those skilled in the art will appreciate that the structure shown in fig. 6 does not constitute a limitation of the electronic device, and may include fewer or more components than those shown, or some components may be combined, or a different arrangement of components.
For example, although not shown, the electronic device may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 60 through a power management device, so that functions of charge management, discharge management, power consumption management and the like are realized through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The electronic device may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
The WEB-based application run 62 stored in the memory 61 of the electronic device 6 is a combination of a plurality of computer programs, which when run in the processor 60, can implement:
receiving a WEB operation instruction, addressing a corresponding WEB application according to the WEB operation instruction, and starting a pre-constructed WEB service container;
taking the WEB service container as the operation environment of the WEB application to obtain a WEB application container;
establishing a WEB middleware according to the WEB application container, and connecting a pre-constructed application container engine by using the WEB middleware;
when the WEB middleware is successfully connected with the application container engine, the application container engine is used for mirroring the operating system where the WEB application container is located to obtain a mirroring system, the mirroring system and a bottom layer interface of the operating system are bound to generate a WEB operating environment corresponding to the WEB application, and the WEB application container is started by using the WEB operating environment to complete the operation of the WEB application.
Specifically, the processor 60 may refer to the description of the relevant steps in the embodiment corresponding to fig. 1 for a specific implementation method of the computer program, which is not described herein again.
Further, the integrated modules/units of the electronic device 6, if implemented in the form of software functional units and sold or used as separate products, may be stored in a non-volatile computer-readable storage medium. The computer readable storage medium may be volatile or non-volatile. For example, the computer-readable medium may include: any entity or device capable of carrying said computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM).
The present application also provides a computer-readable storage medium, storing a computer program that, when executed by a processor of an electronic device, may implement:
receiving a WEB operation instruction, addressing a corresponding WEB application according to the WEB operation instruction, and starting a pre-constructed WEB service container;
taking the WEB service container as the operation environment of the WEB application to obtain a WEB application container;
establishing a WEB middleware according to the WEB application container, and connecting a pre-constructed application container engine by using the WEB middleware;
when the WEB middleware is successfully connected with the application container engine, mirroring the operating system where the WEB application container is located by using the application container engine to obtain a mirroring system;
and binding the mirror image system and a bottom layer interface of the operating system, generating a WEB operating environment corresponding to the WEB application, starting the WEB application container by utilizing the WEB operating environment, and completing the operation of the WEB application.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus, device and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the present application is not limited to the details of the foregoing illustrative embodiments, and that the present application may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the application being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The above description is merely exemplary of the present application and is presented to enable those skilled in the art to understand and practice the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.