Process priority determination method and system based on JavaScript
By introducing priority management and process scheduling modules in JavaScript, the SylixOS API interface is used to dynamically adjust process priorities, solving the performance bottleneck of JavaScript's multi-process concurrent processing in mission-critical systems, and improving the system's real-time and responsiveness capabilities .
Patent Information
- Application Number
- CN202410109918.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-26
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2044-01-26
AI Technical Summary
JavaScript technology lacks multi-process concurrent processing functions in mission-critical systems, resulting in performance bottlenecks and interface lags when processing multiple tasks, and the process priority setting cannot be directly implemented.
By introducing priority management module, process management module and priority mapping module in JavaScript, the SylixOS system API interface is used to obtain real-time status information, dynamically adjust process priorities, and schedule based on priority to realize process scheduling in the process pool.
It effectively improves the real-time and response speed of the system, alleviates the performance bottlenecks and resource competition caused by multi-task execution, and meets the real-time requirements of mission-critical systems.
Smart Images

Figure CN117851019B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of process scheduling, and in particular relates to a method and system for determining process priority based on JavaScript. Background Art
[0002] Mission-critical systems refer to those systems that require high availability, high stability, and high real-time performance in critical scenarios. In such systems, real-time performance is often one of the most important factors, because its processing speed will directly affect the efficiency and performance of the system. Currently, common JavaScript technologies often only provide single-process execution and lack multi-process concurrent processing capabilities, which means that it can only execute one task at the same time, resulting in significant limitations in processing multiple tasks. For example, when a large number of computationally intensive tasks need to be run, the interface will freeze or even crash. In some scenarios, we need to process multiple tasks at the same time, and then we need to implement multiple processes. There are some related technologies for this problem, such as Web Worker, Shared Worker, and Service Worker. These technologies can implement multi-process concurrent processing, but their process scheduling mechanism is relatively simple, which is difficult to meet the requirements of mission-critical systems with high real-time requirements. In systems with high real-time requirements, a common implementation method is to use the real-time scheduler provided by the operating system to control the execution order and time slice allocation of tasks. However, there is no corresponding API support in the JavaScript language, so it is impossible to directly implement the priority setting of JavaScript operation processes. Summary of the invention
[0003] In view of the above technical problems, the present invention proposes a process priority determination solution based on JavaScript.
[0004] The first aspect of the present invention proposes a method for determining a process priority based on JavaScript. The method comprises: step S1, calling a priority management module of JavaScript, and assigning an initial priority to each process by calling an API function when starting a JavaScript process; step S2, calling a process management module of JavaScript, and obtaining the initial priority by parsing a priority parameter when starting a Sylix operating system, and creating a JavaScript process with the initial priority, and executing the JavaScript process.
[0005] When the priority parameter is updated: the priority mapping module of JavaScript is called, the real-time status information of the Sylix operating system is obtained through the API interface of the Sylix operating system, and the real-time status information is mapped to the JavaScript process; the priority management module of JavaScript is called, and the priority parameter of the JavaScript process is updated based on the real-time status information; the process management module of JavaScript is called, and priority-based scheduling is performed on each JavaScript process in the process pool based on the updated priority parameter.
[0006] According to the method of the first aspect of the present invention, in step S2, when creating the JavaScript process, a JavaScript engine and a JavaScript application are introduced into the JavaScript process.
[0007] According to the method of the first aspect of the present invention, when executing the JavaScript process, the JavaScript engine is started to load the JavaScript application, the JavaScript engine parses the JavaScript application, converts it into executable code, and schedules each JavaScript process in the process pool based on the updated priority parameter when running the JavaScript application.
[0008] According to the method of the first aspect of the present invention, the updating of the priority parameter occurs before the creation of the JavaScript process, or after the creation of the JavaScript process and before the execution of the JavaScript process, or during the execution of the JavaScript process.
[0009] The second aspect of the present invention proposes a process priority determination system based on JavaScript. The system includes a JavaScript priority management module, a JavaScript process management module and a JavaScript priority mapping module, wherein: the JavaScript priority management module is configured to: assign an initial priority to each process by calling an API function when starting a JavaScript process; the JavaScript process management module is configured to: obtain the initial priority by parsing a priority parameter when starting the Sylix operating system, create a JavaScript process with the initial priority, and execute the JavaScript process.
[0010] When the system updates the priority parameter: the priority mapping module of the JavaScript is called, the real-time status information of the Sylix operating system is obtained through the API interface of the Sylix operating system, and the real-time status information is mapped to the JavaScript process; the priority management module of the JavaScript is called, and the priority parameter of the JavaScript process is updated based on the real-time status information; the process management module of the JavaScript is called, and priority-based scheduling is performed on each JavaScript process in the process pool based on the updated priority parameter.
[0011] According to the system of the second aspect of the present invention, when creating the JavaScript process, the JavaScript process management module introduces a JavaScript engine and a JavaScript application into the JavaScript process.
[0012] According to the system of the second aspect of the present invention, when executing the JavaScript process, the JavaScript process management module starts the JavaScript engine to load the JavaScript application, the JavaScript engine parses the JavaScript application, converts it into executable code, and schedules each JavaScript process in the process pool based on the updated priority parameter when running the JavaScript application.
[0013] According to the system of the second aspect of the present invention, the updating of the priority parameter occurs before the creation of the JavaScript process, or after the creation of the JavaScript process and before the execution of the JavaScript process, or during the execution of the JavaScript process.
[0014] The third aspect of the present invention discloses an electronic device. The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps in the JavaScript-based process priority determination method described in the first aspect of the present disclosure are implemented.
[0015] The fourth aspect of the present invention discloses a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the JavaScript-based process priority determination method described in the first aspect of the present disclosure are implemented.
[0016] In summary, the technical solution proposed in the present invention supports returning the runtime priority by utilizing the SylixOS system API interface, thereby improving the real-time performance of the JavaScript operation process. In the specific implementation process, the following difficulties and technical problems need to be overcome:
[0017] Communication between different processes: Since each process is independent, a way is needed to implement communication between processes. You can use the postMessage() function to send messages and receive responses.
[0018] Synchronization of shared resources: If multiple processes need to access a shared resource at the same time, locks or other synchronization mechanisms are needed to avoid race conditions.
[0019] Cross-domain access restrictions: Since Web Workers in browsers follow the same-origin policy, JavaScript code on other websites cannot be accessed across domains.
[0020] The technical solution proposed in the present invention implements process scheduling management in JavaScript, controls the priority of the process and schedules it according to the priority of different tasks, realizes the reasonable allocation of system resources and improves the real-time responsiveness of the application. This method effectively alleviates the performance bottleneck and resource competition problems caused by the simultaneous execution of multiple tasks in the application, improves the system's ability to respond quickly and handle various events, and better meets the real-time requirements of mission-critical systems. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0022] Figure 1 The figure is a flowchart of a method for determining a process priority based on JavaScript according to an embodiment of the present invention.
[0023] Figure 2 The figure is a structural diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0025] The first aspect of the present invention provides a method for determining process priority based on JavaScript. Figure 1 As shown, the method includes: step S1, calling the priority management module of JavaScript, and assigning an initial priority to each process by calling an API function when starting the JavaScript process; step S2, calling the process management module of JavaScript, when starting the Sylix operating system, obtaining the initial priority by parsing the priority parameter, creating a JavaScript process with the initial priority, and executing the JavaScript process.
[0026] like Figure 1 As shown, when the priority parameter is updated: the priority mapping module of JavaScript is called, the real-time status information of the Sylix operating system is obtained through the API interface of the Sylix operating system, and the real-time status information is mapped to the JavaScript process; the priority management module of JavaScript is called, and the priority parameter of the JavaScript process is updated based on the real-time status information; the process management module of JavaScript is called, and priority-based scheduling is performed on each JavaScript process in the process pool based on the updated priority parameter.
[0027] Specifically, this method uses the SylixOS system API interface to support returning the runtime priority, thereby improving the real-time performance of the JavaScript operation process. This method mainly needs to overcome the following difficulties and technical challenges: (1) Communication between different processes: Since each process is independent, a way is needed to achieve communication between processes. The postMessage() function can be used to send messages and receive responses. (2) Synchronization of shared resources: If multiple processes need to access a shared resource at the same time, locks or other synchronization mechanisms are needed to avoid race conditions. (3) Cross-domain access restrictions: Since Web Workers in the browser follow the same-origin policy, JavaScript code on other websites cannot be accessed across domains.
[0028] Specifically, the method provides a new API function that can set the priority of the JavaScript operation process. In the JavaScript code, the API function is used to set the priority of the operation process. The SylixOS system dynamically adjusts the execution order of the process according to the priority of the JavaScript process and the requirements of other system resources, thereby ensuring that mission-critical systems can respond quickly to events.
[0029] According to the method of the first aspect of the present invention, in step S2, when creating the JavaScript process, a JavaScript engine and a JavaScript application are introduced into the JavaScript process.
[0030] According to the method of the first aspect of the present invention, when executing the JavaScript process, the JavaScript engine is started to load the JavaScript application, the JavaScript engine parses the JavaScript application, converts it into executable code, and schedules each JavaScript process in the process pool based on the updated priority parameter when running the JavaScript application.
[0031] According to the method of the first aspect of the present invention, the updating of the priority parameter occurs before the creation of the JavaScript process, or after the creation of the JavaScript process and before the execution of the JavaScript process, or during the execution of the JavaScript process.
[0032] Specifically, the JavaScript process management module is responsible for managing JavaScript processes, including operations such as creation, destruction, suspension and resumption. When the system starts, the module will create a JavaScript process pool to handle JavaScript tasks in the system.
[0033] Specifically, the priority management module is responsible for dynamically managing the priority of JavaScript operation processes. When a JavaScript process starts, the module will assign it an initial priority and adjust it according to the real-time requirements of the system. The module supports multiple priority setting methods, including static priority setting and dynamic priority setting. This method provides an API function to initially set the priority.
[0034] Specifically, the API interface of the SylixOS system is used to interact with the SylixOS system and obtain the real-time information of the current system. SylixOS is an embedded operating system based on a real-time operating system (RTOS) and provides a rich API interface that can be used to obtain system status, scheduling information, etc.
[0035] Specifically, the priority mapping module is responsible for mapping the real-time information returned by the SylixOS system to the priority of the JavaScript operation process. When the priority management module needs to update the priority of the JavaScript operation process, it will call this module to obtain the real-time information of the current system and convert it into a specific priority value.
[0036] Specifically, for general JavaScript, when creating an application or a process, there is no concept of priority at runtime. The present invention supports setting different priorities for different processes. For embedded systems, especially multi-tasking scenarios, by allocating more processing time to high-priority tasks, the system response time can be reduced and the real-time performance of the system can be improved; at the same time, reasonable setting of priorities can effectively utilize the system resources and ensure that resources are maximized. Ordinary Node. processes can be created directly on the operating system, and the process has no priority. In addition to an ordinary process, the JavaScript process of the present invention also introduces a JavaScript engine during initialization. This JavaScript application can be loaded through the JavaScript engine.
[0037] Specifically, the priority of the JavaScript operation process is adjusted dynamically. When the system starts, the JavaScript process management module will create a process pool to handle JavaScript tasks in the system. Each JavaScript operation process is assigned an initial priority, and during runtime, the priority management module will adjust it according to the real-time requirements of the system. Specifically, when the response speed of the JavaScript operation process needs to be improved, the priority management module will increase its priority so that it can obtain a higher execution priority in the system.
[0038] Specifically, in the SylixOS system, the scheduling and priority of tasks are managed by the kernel. The priority management module obtains the real-time information of the current system through the SylixOS system API interface, converts it into a specific priority value, and then assigns the value to the JavaScript operation process. If the real-time performance of the system changes (for example, the execution time or delay of the task changes), the priority management module will recalculate the priority of the JavaScript operation process and make corresponding adjustments. In this way, the priority management module can help the system effectively manage the execution order of tasks, ensure that important tasks can be processed in a timely manner, and thus improve the response speed and stability of the system.
[0039] Specifically, the process of implementing priority when JavaScript is started is as follows. First, the parameter is parsed, the shell command of the process is started, and the parameter is parsed to obtain the priority of the process. Based on this priority, an OS process can be created and the priority of the process can be set. Then the JavaScript engine is started, the JavaScript application is loaded and parsed.
[0040] An optional / alternative embodiment specifically includes:
[0041] System initialization: When the system starts, the system initialization operation will be performed first, including loading the system kernel, driver, etc.
[0042] Parse the startup parameters: Next, parse the startup parameters to obtain the path of the JS application and the priority of the process. You can use the API function Javascript -p io <path>The priority is initially specified, and then the runtime priority mapping module analyzes and processes this information to determine the priority that the JavaScript operation process should currently have. For example, if the CPU occupancy rate is high, the priority of the JavaScript operation process needs to be lowered to prevent it from over-consuming CPU resources and affecting the normal execution of other tasks. After determining the priority that the JavaScript operation process should have, the runtime priority mapping module converts it into a specific priority value and returns it to the priority management module. This priority value is usually an integer, which represents the priority level of the JavaScript operation process. The larger the integer, the higher the priority.
[0043] Create OS process: Create a new OS process according to the requirements of the JS engine and specify the path of the JS application.
[0044] Setting priority: The priority management module will update the priority of the JavaScript operation process according to the priority value returned by the runtime priority mapping module. This ensures that the JavaScript operation process is always at the appropriate priority level, ensuring the real-time and stability of the system. According to the parameters parsed above, set the priority of the process. This can be done by scheduling the process on the operating system.
[0045] Start JS engine: Start the JS engine to provide an execution environment for JS applications.
[0046] Load JS application: Use the JS engine to load the JS application and prepare it for running.
[0047] Parsing the application: The JS engine parses the JS application and converts it into executable code.
[0048] Run the application: The JS engine executes the JS application and schedules the execution of the process according to the priority set previously.
[0049] It can be seen that by managing application and process priorities, basic process scheduling functions can be implemented in JavaScript.
[0050] In summary, the above method can: (1) improve the real-time performance of mission-critical systems: by allowing JavaScript programmers to obtain and set the priority of the operation process, the real-time performance of the operation process is improved. Provide a more flexible priority control method: support dynamic adjustment of priority and priority inheritance, making priority control more precise and flexible. (2) Improve the programming experience of developers: by directly controlling the priority of the operation process in JavaScript, developers can better grasp and manage the real-time performance of the system.
[0051] The present invention solves the limitation problem of JavaScript in terms of real-time performance by providing JavaScript operation process priority technology, which can better meet the real-time requirements of mission-critical systems. It also provides new possibilities for the application of JavaScript in the fields of industrial automation control, medical equipment, transportation, etc.
[0052] The second aspect of the present invention proposes a process priority determination system based on JavaScript. The system includes a JavaScript priority management module, a JavaScript process management module and a JavaScript priority mapping module, wherein: the JavaScript priority management module is configured to: assign an initial priority to each process by calling an API function when starting a JavaScript process; the JavaScript process management module is configured to: obtain the initial priority by parsing a priority parameter when starting the Sylix operating system, create a JavaScript process with the initial priority, and execute the JavaScript process.
[0053] When the system updates the priority parameter: the priority mapping module of the JavaScript is called, the real-time status information of the Sylix operating system is obtained through the API interface of the Sylix operating system, and the real-time status information is mapped to the JavaScript process; the priority management module of the JavaScript is called, and the priority parameter of the JavaScript process is updated based on the real-time status information; the process management module of the JavaScript is called, and priority-based scheduling is performed on each JavaScript process in the process pool based on the updated priority parameter.
[0054] According to the system of the second aspect of the present invention, when creating the JavaScript process, the JavaScript process management module introduces a JavaScript engine and a JavaScript application into the JavaScript process.
[0055] According to the system of the second aspect of the present invention, when executing the JavaScript process, the JavaScript process management module starts the JavaScript engine to load the JavaScript application, the JavaScript engine parses the JavaScript application, converts it into executable code, and schedules each JavaScript process in the process pool based on the updated priority parameter when running the JavaScript application.
[0056] According to the system of the second aspect of the present invention, the updating of the priority parameter occurs before the creation of the JavaScript process, or after the creation of the JavaScript process and before the execution of the JavaScript process, or during the execution of the JavaScript process.
[0057] The third aspect of the present invention discloses an electronic device. The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps in the JavaScript-based process priority determination method described in the first aspect of the present disclosure are implemented.
[0058] Figure 2 is a structural diagram of an electronic device according to an embodiment of the present invention, such as Figure 2 As shown, the electronic device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the electronic device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, near field communication (NFC) or other technologies. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.
[0059] Those skilled in the art will understand that Figure 2 The structure shown in the figure is only a structural diagram of the part related to the technical solution of the present disclosure, and does not constitute a limitation on the electronic device to which the technical solution of the present application is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0060] The fourth aspect of the present invention discloses a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the JavaScript-based process priority determination method described in the first aspect of the present disclosure are implemented.
[0061] In summary, the technical solution proposed in the present invention supports returning the runtime priority by utilizing the SylixOS system API interface, thereby improving the real-time performance of the JavaScript operation process. In the specific implementation process, the following difficulties and technical problems need to be overcome:
[0062] Communication between different processes: Since each process is independent, a way is needed to implement communication between processes. You can use the postMessage() function to send messages and receive responses.
[0063] Synchronization of shared resources: If multiple processes need to access a shared resource at the same time, locks or other synchronization mechanisms are needed to avoid race conditions.
[0064] Cross-domain access restrictions: Since Web Workers in browsers follow the same-origin policy, JavaScript code on other websites cannot be accessed across domains.
[0065] The technical solution proposed in the present invention implements process scheduling management in JavaScript, controls the priority of the process and schedules it according to the priority of different tasks, realizes the reasonable allocation of system resources and improves the real-time responsiveness of the application. This method effectively alleviates the performance bottleneck and resource competition problems caused by the simultaneous execution of multiple tasks in the application, improves the system's ability to respond quickly and handle various events, and better meets the real-time requirements of mission-critical systems.
[0066] Please note that the technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification. The above-mentioned embodiments only express several implementation methods of the present application, and their descriptions are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, without departing from the concept of the present application, several variations and improvements can be made, which all belong to the scope of protection of the present application. Therefore, the scope of protection of the patent in this application shall be based on the attached claims.< / path>
Claims
1. A method for determining process priority based on JavaScript, characterized in that: The method comprises: Step S1, calling the priority management module of JavaScript, and assigning an initial priority to each process by calling an API function when starting the JavaScript process; Step S2, calling the JavaScript process management module, when starting the Sylix operating system, obtaining the initial priority by parsing the priority parameter, creating a JavaScript process with the initial priority, and executing the JavaScript process; When the priority parameter is updated: Calling the priority mapping module of JavaScript, obtaining the real-time status information of the Sylix operating system through the API interface of the Sylix operating system, and mapping the real-time status information to the JavaScript process; Calling the priority management module of the JavaScript to update the priority parameter of the JavaScript process based on the real-time status information; The process management module of the JavaScript is called to perform priority-based scheduling on each JavaScript process in the process pool based on the updated priority parameter.
2. A method for determining process priority based on JavaScript according to claim 1, characterized in that: In the step S2, when the JavaScript process is created, a JavaScript engine and a JavaScript application are introduced into the JavaScript process.
3. The method for determining process priority based on JavaScript according to claim 2, characterized in that: When executing the JavaScript process, the JavaScript engine is started to load the JavaScript application, the JavaScript engine parses the JavaScript application, converts it into executable code, and schedules each JavaScript process in the process pool based on the updated priority parameter when running the JavaScript application.
4. The method for determining process priority based on JavaScript according to claim 3, characterized in that: The updating of the priority parameter occurs before the JavaScript process is created, or after the JavaScript process is created and before the JavaScript process is executed, or during the execution of the JavaScript process.
5. A JavaScript-based process priority determination system, characterized in that: The system includes a JavaScript priority management module, a JavaScript process management module and a JavaScript priority mapping module, wherein: The JavaScript priority management module is configured to: Assign an initial priority to each process by calling an API function when starting a JavaScript process; The JavaScript process management module is configured as follows: When starting the Sylix operating system, the initial priority is obtained by parsing the priority parameter, a JavaScript process is created with the initial priority, and the JavaScript process is executed; When the system updates the priority parameter: Calling the priority mapping module of the JavaScript, obtaining the real-time status information of the Sylix operating system through the API interface of the Sylix operating system, and mapping the real-time status information to the JavaScript process; Calling the priority management module of the JavaScript to update the priority parameter of the JavaScript process based on the real-time status information; The process management module of the JavaScript is called to perform priority-based scheduling on each JavaScript process in the process pool based on the updated priority parameter.
6. A JavaScript-based process priority determination system according to claim 5, characterized in that: When creating the JavaScript process, the JavaScript process management module introduces a JavaScript engine and a JavaScript application program into the JavaScript process.
7. A JavaScript-based process priority determination system according to claim 6, characterized in that: When executing the JavaScript process, the JavaScript process management module starts the JavaScript engine to load the JavaScript application. The JavaScript engine parses the JavaScript application and converts it into executable code, and schedules each JavaScript process in the process pool based on the updated priority parameter when running the JavaScript application.
8. A JavaScript-based process priority determination system according to claim 7, characterized in that: The updating of the priority parameter occurs before the JavaScript process is created, or after the JavaScript process is created and before the JavaScript process is executed, or during the execution of the JavaScript process.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps in the JavaScript-based process priority determination method described in any one of claims 1 to 4 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the JavaScript-based process priority determination method described in any one of claims 1 to 4 are implemented.
