Process priority adjustment method and device, storage medium and electronic equipment
By dynamically calculating and adjusting process priorities, the problem in existing technologies of being unable to respond to dynamic CPU usage changes in real time is solved, system performance and user experience are improved, and more intelligent and efficient process scheduling is achieved.
Patent Information
- Application Number
- CN202410977616.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-10-15
Smart Images

Figure CN118779083A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the computer field, and specifically, to a method and device for adjusting process priority, a storage medium, and an electronic device. Background Art
[0002] Process scheduling is a critical process in modern operating systems. The operating system manages the computer's central processing unit (CPU) resources through the process scheduler to ensure that each process can use the CPU fairly in time, thereby improving system performance and user experience. The process scheduler in the open source operating system (Linux system) uses the Completely Fair Scheduler (CFS), which is a process scheduling algorithm introduced since Linux version 2.6.23. CFS ensures that each process gets a fair CPU time slice by simulating an ideal, multi-tasking fair system.
[0003] As the complexity of applications increases, some processes may need different CPU resources in different time periods. For example, background tasks can occupy more resources when the CPU is idle, but foreground interactive tasks need to quickly obtain more CPU resources to respond to user operations. However, in related technologies, CFS mainly allocates CPU time based on static priorities, lacks sufficient adaptability to dynamic changes in CPU usage, and cannot adjust the priority of processes according to dynamic changes to adjust the allocation of CPU resources in real time.
[0004] With regard to the problem in the related art that the system cannot dynamically adjust the priority of the process, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present application provide a method and device for adjusting the priority of a process, a storage medium, and an electronic device, so as to at least solve the problem that the system cannot dynamically adjust the priority of a process.
[0006] According to one embodiment of the present application, a method for adjusting process priority is provided, comprising: obtaining process information of N processes when a condition for adjusting process priority is met, wherein the N processes are processes currently running in the system; determining priority information of the N processes based on the process information of the N processes; and sending indication information to a designated kernel module of the system so that the system adjusts the priority of the N processes based on the priority information of the N processes.
[0007] In an exemplary embodiment, the method also includes: determining whether the priority adjustment condition is met in the following manner: when the CPU usage rate of the system's central processing unit is greater than a first preset threshold or less than a second preset threshold, determining that the priority adjustment condition is met, wherein the first preset threshold is greater than the second preset threshold; and / or when the time interval between the current moment and the target moment is less than a third preset threshold, determining that the priority adjustment condition is met, wherein the target moment is the moment when the indication information was last sent to the specified kernel module of the system.
[0008] In an exemplary embodiment, determining the priority information of the N processes according to the process information of the N processes includes: determining the priority of the i-th process among the N processes in the following manner: determining a first parameter value according to the process type of the i-th process, wherein the process type includes: user process and kernel process; when the i-th process is a user process, the first parameter value is equal to 1, and when the i-th process is a kernel process, the first parameter value is equal to 0; and determining a second parameter value according to the current state of the i-th process, wherein the current state includes: foreground state, background state; and determining a second parameter value according to the current state of the i-th process. The third parameter value is determined by the number of file descriptors corresponding to the ith process; and the fourth parameter value is determined according to the CPU usage time of the ith process, wherein the CPU usage time includes: CPU time in kernel state and CPU time in user state; and the priority adjustment strategy of the process is determined, and the priority calculation method is determined from the preset configuration information according to the priority adjustment strategy, wherein the preset configuration information includes priority calculation methods corresponding to different priority adjustment strategies; using the priority calculation method, the priority of the ith process is determined according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value.
[0009] In an exemplary embodiment, the priority calculation method is used to determine the priority of the ith process according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value, including: when the priority calculation method is to use a target formula to calculate the priority, the target formula is used to determine the priority of the ith process according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value; wherein the target formula is: P = α×sigmoid(β×Q_ppid+θ×(Q_tty+Q_files) / W_time)+z, p is the priority of the ith process, Q_ppid is the first parameter value, W_tty is the second parameter value, Q_files is the third parameter value, W_time is the fourth parameter value, and α, β, θ and z are preset weight parameters.
[0010] In an exemplary embodiment, after determining the priority of the ith process according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value, the method further includes: when the process name of the ith process is a preset name, adjusting the priority of the ith process according to the priority adjustment information corresponding to the preset name; and / or when the program file path corresponding to the ith process is a preset path, adjusting the priority of the ith process according to the priority adjustment information corresponding to the preset path.
[0011] In an exemplary embodiment, before obtaining the process information of N processes, the method also includes: monitoring multiple processes running in the system according to a preset monitoring frequency, and storing the process information of the monitored processes in a target database; obtaining the process information of N processes includes: obtaining the process information of the N processes from the target database.
[0012] In an exemplary embodiment, the method further includes: obtaining the monitoring frequency, the priority adjustment conditions, and the priority adjustment strategy through an interactive interface, wherein the monitoring frequency is the monitoring frequency for monitoring multiple processes running in the system; or obtaining the monitoring frequency, the priority adjustment conditions, and the priority adjustment strategy through a hypertext transfer protocol HTTP.
[0013] According to another embodiment of the embodiment of the present application, a device for adjusting process priority is also provided, including: an acquisition module, used to obtain process information of N processes when the adjustment conditions of process priority are met, wherein the N processes are processes currently running in the system; a determination module, used to determine the priority information of the N processes based on the process information of the N processes; and an adjustment module, used to send indication information to a specified kernel module of the system, so that the system adjusts the priority of the N processes according to the priority information of the N processes.
[0014] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.
[0015] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0016] According to another embodiment of the present application, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0017] Through the present application, under the conditions of meeting the process priority adjustment, the process information of N processes is obtained, and the priority information of the N processes is determined based on the obtained process information, thereby sending instruction information to the specified kernel module of the system to instruct the system to adjust the priority of the N processes according to the priority information of the N processes, thereby solving the problem that the system cannot dynamically adjust the priority of the process. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1 It is a hardware structure block diagram of a server device according to a method for adjusting process priority in an embodiment of the present application;
[0020] Figure 2 is a flow chart of a method for adjusting process priority according to an embodiment of the present application;
[0021] Figure 3 is a schematic diagram of an optional priority adjustment process according to an embodiment of the present application;
[0022] Figure 4 is another optional system architecture schematic diagram according to an embodiment of the present application;
[0023] Figure 5 is a structural block diagram of a device for adjusting process priority according to an embodiment of the present application;
[0024] Figure 6 It is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0027] The process priority adjustment method embodiment provided in the embodiment of the present application can be executed in a server device or a similar computing device. Taking running on a server device as an example, Figure 1 1 is a hardware structure block diagram of a server device of a method for adjusting process priority in an embodiment of the present application. Figure 1 As shown, the server device may include one or more ( Figure 1 Only one is shown in the figure) processor 102 (processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned server device may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0028] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for adjusting the process priority in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0029] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0030] In order to solve the above problem, a method for adjusting process priority is provided in this embodiment. Optionally, the execution subject of the method may be a process priority adjustment program, which is a user program, such as Figure 2 As shown, the method includes the following steps S202-S206:
[0031] Step S202: When the adjustment condition of the process priority is met, process information of N processes is obtained, wherein the N processes are processes currently running in the system;
[0032] Optionally, the process information of a process includes but is not limited to: the process name, the program file path corresponding to the process, the process type (user process, kernel process), the current state (foreground state, background state), the number of file descriptors and the CPU usage time of the process (including kernel state CPU time and user state CPU time).
[0033] In an exemplary embodiment, before the above step S202, the method further includes the following steps: monitoring multiple processes running in the system according to a preset monitoring frequency, and storing process information of the monitored processes in a target database;
[0034] Optionally, the monitoring frequency is preset to 100 milliseconds to ensure that the system can continuously monitor the characteristics of each process and update the data in the database in a timely manner.
[0035] Optionally, the process monitoring module in the process priority adjustment program can monitor the system, determine the process information of all processes currently running in the system, and then preprocess the monitored process information and store the preprocessed information in the target database.
[0036] Optionally, preprocessing the data includes: cleaning and formatting the collected raw data to ensure the consistency and integrity of the data.
[0037] Optionally, the process monitoring module may store the process information in the target database using the process name and program file path as the database primary key.
[0038] In an exemplary embodiment, the obtaining process information of the N processes includes: obtaining the process information of the N processes from the target database.
[0039] Step S204: determining priority information of the N processes according to the process information of the N processes;
[0040] Optionally, after determining the priority information of the N processes, the priority information of the N processes is stored in the target database.
[0041] Optionally, the above step S204 may be executed by a scheduling decision module in a process priority adjustment program.
[0042] Step S206: Sending instruction information to a designated kernel module of the system so that the system adjusts the priorities of the N processes according to the priority information of the N processes.
[0043] It should be noted that after sending the instruction information to the designated kernel module of the system, the system will obtain the priority information of N processes from the target database.
[0044] Through the above steps, when the conditions for adjusting the process priority are met, the process information of N processes is obtained, and the priority information of the N processes is determined based on the obtained process information, so as to send instruction information to the specified kernel module of the system to instruct the system to adjust the priority of the N processes according to the priority information of the N processes, thereby solving the problem that the system cannot dynamically adjust the priority of the process.
[0045] In an exemplary embodiment, the above step S202 may determine whether the priority adjustment condition is met by the following steps S11 and / or S12:
[0046] Step S11: when the CPU usage rate of the system is greater than a first preset threshold or less than a second preset threshold, determining an adjustment condition that satisfies the priority, wherein the first preset threshold is greater than the second preset threshold;
[0047] Optionally, the first preset threshold is set to 80%, that is, when the CPU usage of the system is greater than 80%, the priority of the process needs to be adjusted to prevent excessive consumption of system resources; the second preset threshold is set to 10%, when the CPU usage of the system is less than 10%, the priority of the process needs to be adjusted to ensure the rational use of system resources.
[0048] Step S12: when the time interval between the current moment and the target moment is less than a third preset threshold, determining an adjustment condition that satisfies the priority, wherein the target moment is the moment when the indication information was last sent to the designated kernel module of the system.
[0049] That is, the priority of the process may be adjusted once every time interval of the third preset threshold.
[0050] It should be noted that the present application proposes an algorithm for dynamically adjusting process priority based on process characteristics. Compared with the traditional static priority setting, the present application can dynamically adjust the process priority according to the real-time CPU usage, thereby achieving more intelligent and efficient process scheduling.
[0051] In an exemplary embodiment, the above step S204 includes: determining the priority of the i-th process among the N processes through the following steps S21-S26:
[0052] Step S2 1: determining a first parameter value according to a process type of the i-th process, wherein the process type includes: a user process and a kernel process; when the i-th process is a user process, the first parameter value is equal to 1, and when the i-th process is a kernel process, the first parameter value is equal to 0;
[0053] Optionally, the process type is determined according to the parent process identification (PPID) to determine the first parameter value. The first parameter value is W_ppid. If the PPID of the i-th process is 0, the i-th process is a kernel process, and W_ppid is equal to 0; if the PPID of the i-th process is not 0, the i-th process is a user process, and W_ppid is equal to 1.
[0054] It should be noted that the kernel process refers to the process used by the system when executing privileged instructions or accessing protected resources. The kernel process has higher permissions and can directly access the kernel space of the operating system; the user process refers to the process used by the system when executing ordinary instructions or accessing user space. At this time, the process can only access its own user space and cannot directly access the kernel space of the operating system.
[0055] Step S22: determining a second parameter value according to the current state of the i-th process, wherein the current state includes: a foreground state and a background state;
[0056] Optionally, the current state of the i-th process may be judged according to the tty information in the task-struct of the process control block, thereby determining the second parameter value.
[0057] Step S23: determining a third parameter value according to the number of file descriptors corresponding to the i-th process;
[0058] Optionally, the number of file descriptors corresponding to the ith process may be determined according to the file Files information in the process control block task-struct, thereby determining the third parameter value.
[0059] Step S24: determining a fourth parameter value according to the CPU usage time of the i-th process, wherein the CPU usage time includes: CPU time in kernel state and CPU time in user state;
[0060] Optionally, the CPU usage time of the ith process is equal to the CPU time in kernel mode plus the CPU time in user mode.
[0061] Optionally, the CPU time in kernel state refers to the running time of a process in kernel state during the entire execution cycle of a process, and the CPU time in user state refers to the running time of a process in user state during the entire execution cycle of a process.
[0062] It should be noted that kernel state refers to the state of a process when a kernel process is executing, and user state refers to the state of a process when a user process is executing. During execution, the system process will continuously switch between kernel processes and user processes. This switching is called context switching.
[0063] Step S25: determining a priority adjustment strategy for the process, and determining a priority calculation method from preset configuration information according to the priority adjustment strategy, wherein the preset configuration information includes priority calculation methods corresponding to different priority adjustment strategies;
[0064] Optionally, the priority adjustment strategy includes but is not limited to: dynamic adjustment and conservative adjustment.
[0065] It should be noted that there is no requirement for the order in which the above steps S21-S25 are executed when executing the embodiment of the present application.
[0066] Step S26: using the priority calculation method, determining the priority of the i-th process according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value.
[0067] It should be noted that, through the above steps, the first parameter value, the second parameter value, the third parameter value and the fourth parameter value of the i-th process are determined, so that the priority of the i-th process can be determined quickly and accurately, the CPU resources can be allocated rationally, and the system performance can be optimized.
[0068] In an exemplary embodiment, the above-mentioned step S26 can be implemented by the following steps: when the priority calculation method is to use a target formula to calculate the priority, use the target formula to determine the priority of the i-th process according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value; wherein the target formula is: P = α×sigmoid(β×W_ppid+θ×(W_tty+W_files) / W_time)+z, p is the priority of the i-th process, W_ppid is the first parameter value, W_tty is the second parameter value, W_files is the third parameter value, W_time is the fourth parameter value, α, β, θ and z are preset weight parameters, and sigmoid is an activation function used to map the calculation results of the above parameters.
[0069] Optionally, W_tty and W_files are positively correlated with process priority; W_time is negatively correlated with process priority.
[0070] It should be noted that, through the above steps, the priority of the i-th process can be accurately determined to reasonably allocate the CPU resources of the system.
[0071] In an exemplary embodiment, after the above step S26, the method further includes the following steps S31 and / or S32:
[0072] Step S31: when the process name of the i-th process is a preset name, adjusting the priority of the i-th process according to the priority adjustment information corresponding to the preset name;
[0073] Step S32: when the program file path corresponding to the i-th process is a preset path, adjusting the priority of the i-th process according to the priority adjustment information corresponding to the preset path.
[0074] That is to say, if a process is a specific process, it is necessary to additionally adjust the priority of the process.
[0075] In an exemplary embodiment, the method further includes the following step S41 or step S42:
[0076] Step S41: obtaining a monitoring frequency, a priority adjustment condition, and a priority adjustment strategy through an interactive interface, wherein the monitoring frequency is a monitoring frequency for monitoring multiple processes running in the system;
[0077] Optionally, the interactive interface is an interactive interface in a process priority adjustment program, which uses a graphical user interface (GUI) to present information and functions through graphic elements such as windows, icons, buttons, menus, etc. The user can interact with it through input devices such as a mouse, keyboard or touch screen. The interactive interface includes the following parameter setting options: Monitoring frequency setting: Provide a slider or drop-down menu to allow the user to adjust the monitoring frequency. The user can select an appropriate monitoring frequency according to the system load to ensure timely acquisition of process status information; Priority adjustment condition setting: The user can set high and low thresholds by inputting a text box or a slider to determine whether the CPU usage of the process exceeds or is lower than the preset threshold; Priority adjustment policy setting: Provide a list of optional items or a check box to allow the user to select different priority adjustment strategies.
[0078] Step S42: Obtain the monitoring frequency, the priority adjustment condition, and the priority adjustment strategy through the hypertext transfer protocol HTTP.
[0079] Optionally, the system provides a Representational State Transfer Application Programming Interface (RESTful API) that allows external access in the form of Hypertext Transfer Protocol (HTTP). Users call the RESTful API by sending HTTP requests to specific endpoints to dynamically adjust monitoring parameters. The API supports the following operations: setting monitoring frequency, setting high and low thresholds, and priority adjustment strategies. The monitoring frequency is set by sending HTTP POST requests to specific endpoints and passing monitoring frequency parameters.
[0080] It should be noted that an interactive interface and API interface are provided in the implementation of this application, allowing administrators to flexibly set and adjust monitoring parameters and priority adjustment strategies, making the system more adaptable and configurable, thereby better meeting the needs of different users.
[0081] Optionally, in an embodiment of the present application, the priority of the process is set by extending the Berkeley Packet Filter (eBPF for short), loading the written eBPF program into the kernel space, and associating it with a specific system (e.g., the creation of a new process) call, so that these system calls trigger the corresponding eBPF program logic when executed. For example, when a new process is created, the eBPF program intercepts the relevant system calls and checks whether the name of the new process in the target database is assigned a Priority field (i.e., whether the newly created process is a previously run process, and if it is a previously run process, the target database must store the priority of the process). If so, the priority of the process is set according to the priority of the process stored in the database, thereby realizing the setting of the priority of the new process. If not, the priority of the process is set to the default priority.
[0082] Obviously, the above-described embodiments are only embodiments of a part of the present invention, rather than all embodiments. In order to better understand the above method, the above process is described below in conjunction with embodiments, but it is not intended to limit the technical solutions of the embodiments of the present invention, specifically:
[0083] The present invention aims to provide a scheduling method that can periodically obtain process features and flexibly adjust their priorities, thereby improving system resource utilization and task processing efficiency. The basic idea of the present invention is to periodically obtain process features through a process monitoring module, process the collected data and store it in a local target database, and then the scheduling decision module calculates the priority of the process according to its running time and other features, and then the agent program in the Linux kernel modifies the priority of the running or newly created process.
[0084] The present invention is mainly implemented based on the following three modules: process monitoring module, scheduling decision module, and user configuration interface (these three modules are located in the above-mentioned process priority adjustment program). Figure 3 As shown, the process monitoring module of the system polls to obtain process characteristics, processes and stores the data, and the scheduling decision module reads data from the database to determine whether the set threshold rule is triggered (such as when the CPU usage rate of the central processing unit of the system is greater than the first preset threshold or less than the second preset threshold, it is determined that the priority adjustment condition is met). If so, the priority is adjusted. The specific system architecture is as follows Figure 4 shown.
[0085] 1. Process monitoring module;
[0086] The process monitoring module is designed to provide accurate data collection and analysis by regularly sampling the CPU usage of each process in the system. This module includes three key parts: data collection, data processing and storage, and periodic triggering.
[0087] 1. Data collection: In the data collection phase, system calls are used to obtain process information, including each process’s tty information, file descriptors, and CPU time in user mode and kernel mode.
[0088] 2. Data processing and storage: In the data processing and storage stage, the collected data is preprocessed and analyzed to obtain the process information of each process within a certain time window. The specific steps are as follows:
[0089] (1) Preprocessing: Clean and format the collected raw data to ensure data consistency and integrity;
[0090] (2) Data storage: The processed data is stored in the database, using the process name and program file path as the database primary key. Other fields contain information such as the tty, file descriptor, and CPU usage time of each process. The data process name can be used for indexing and sorting to facilitate subsequent query and analysis;
[0091] 3. Periodic triggering: The data collection and processing process needs to be triggered at a fixed sampling period. For example, the sampling period is set to 100 milliseconds, and data collection and processing are performed once at the end of each period. Through periodic triggering, it is ensured that the system can continuously monitor the characteristics of each process and update the data in the database in a timely manner.
[0092] 2. Scheduling decision module;
[0093] The scheduling decision module aims to provide a flexible and efficient process scheduling mechanism, support users to define and modify scheduling rules and trigger thresholds, and dynamically adjust process priorities based on real-time data collection. The module includes three main parts: threshold setting, scheduling strategy, and priority setting:
[0094] 1. Threshold setting: Users can set high and low thresholds for CPU usage to trigger scheduling policies for dynamic adjustment. For example, the high threshold is set to 80% and the low threshold is set to 10%. When the CPU usage of a process reaches or exceeds the high threshold, the scheduling policy is triggered to dynamically adjust the process priority to prevent excessive consumption of system resources. When the usage is lower than the low threshold, the recovery policy is triggered to adjust the process priority to ensure the rational use of system resources.
[0095] 2. Scheduling strategy: This module divides the priorities according to the relevant characteristics of the process. Its consideration characteristics are as follows:
[0096] (1) Determine whether the PPID of the process is 0 to determine whether it is a user-created process. This parameter is marked as W_ppid. If the PPID is not 0, it is a user process and W_ppid is 1. Otherwise, it is a kernel process and W_ppid is 0.
[0097] (2) Obtain tty information in the process control block task_struct to determine whether it is a program running through tty. The weight W_tty is calculated based on the information. The weight is positively correlated with the process priority.
[0098] (3) Obtain the files information in the task_struct of the process control block to obtain the number of file descriptors related to the process, and calculate the weight Q_files based on the information. The weight is positively correlated with the process priority.
[0099] (4) Obtain the kernel state and user state running time within the process cycle, and calculate the weight W_time based on this information. The weight is negatively correlated with the process priority;
[0100] Calculate the priority P of the process based on the above 4 parameters:
[0101] P = α×sigmoid(β×W_ppid+θ×(W_tty+W_files) / W_time)+z, where sigmoid is an activation function used to map the calculation results of the above parameters and mark the priority field of the process name field in the database as the Priority value.
[0102] 3. Process priority setting;
[0103] This patent sets the priority of the process through eBPF, and intercepts related system calls (such as clone, fork, etc.) when the process is created through the eBPF software. The written eBPF program is loaded into the kernel and associated with specific system calls, so that these system calls will trigger the corresponding eBPF program logic when executed. When a new process is created, the eBPF program will intercept the relevant system calls and check whether the process name in the database is assigned a Priority field. If so, the priority parameters of the new process are modified, thereby setting the priority of the new process.
[0104] 3. User configuration interface module;
[0105] This application provides a user configuration interface module for flexibly adjusting process priorities to improve system resource utilization and task processing efficiency. The following is a description of the specific implementation method:
[0106] 1. User interface: The user interface of this system adopts GUI, and users can set and adjust parameters through intuitive operations such as clicking buttons and dragging sliders. The interface includes the following parameter setting options:
[0107] (1) Monitoring frequency setting: Provide a slider or drop-down menu to allow users to adjust the monitoring frequency. Users can select an appropriate monitoring frequency based on system load to ensure timely acquisition of process status information.
[0108] (2) Threshold setting: Users can set high and low thresholds by inputting text boxes or sliding bars to determine whether the CPU usage of the process exceeds or falls below the preset threshold.
[0109] (3) Priority adjustment strategy setting: Provide a list of options or check boxes to allow users to select different priority adjustment strategies. Provide "dynamic adjustment", "conservative adjustment", and other strategies for users to choose.
[0110] 2. API interface: This system provides a RESTful API that allows external access in the form of HTTP protocol. Users and developers call the API by sending HTTP requests to dynamically adjust monitoring parameters. The API supports the following operations: setting monitoring frequency, setting high and low thresholds, and priority adjustment strategies. The monitoring frequency is set by sending HTTP POST requests to a specific endpoint and passing the monitoring frequency parameters.
[0111] 3. Real-time effect: After the user adjusts the parameters on the interface or through the API, the system takes effect immediately without restarting or waiting. The system can automatically adjust the parameters according to the preset rules.
[0112] (1) It should be noted that the process monitoring module can regularly sample the characteristics of each process in the system and provide real-time feedback to the scheduling decision module so as to dynamically adjust the process priority.
[0113] (2) It should be noted that the scheduling decision module can dynamically adjust the priority of the process based on the data provided by the process monitoring module and the eBPF function using a flexible adjustment strategy. This module can effectively determine the priority of the process.
[0114] (3) It should be noted that the user configuration interface module provides a graphical user interface and an API interface, allowing administrators to flexibly set and adjust monitoring parameters and priority adjustment strategies. This module makes the system more adaptable and configurable, thereby better meeting the needs of different users.
[0115] It should be noted that the system can adjust the priority of the process in real time according to the priority determined by the scheduling decision module, maintain the load balance of the system, and improve the utilization of system resources and task processing efficiency.
[0116] It should be noted that the present application also has the following advantages: (1) Improving system resource utilization: By dynamically adjusting process priorities, the system can allocate CPU resources more intelligently and give priority to high-priority tasks, thereby improving system resource utilization. By lowering the priority of processes with high CPU occupancy, resource waste can be effectively avoided and the overall efficiency of the system can be improved; (2) Improving user experience: By optimizing system resource allocation, the system response time is reduced, the user experience is improved, and users can operate more smoothly; (3) Strong adaptability: Supporting dynamically configured user interfaces and API interfaces, the system can be flexibly adjusted according to different workloads and usage scenarios, and has strong adaptability. The user interface is intuitive and easy to use, and the API interface is flexible and convenient, allowing users to easily manage and adjust system resources, simplifying system management work.
[0117] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0118] In this embodiment, a device for adjusting process priority is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the modules described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0119] Figure 5 : is a structural block diagram of a device for adjusting process priority according to an embodiment of the present application, the device comprising:
[0120] The acquisition module 502 is used to acquire process information of N processes when the adjustment condition of the process priority is met, wherein the N processes are processes currently running in the system;
[0121] A determination module 504, configured to determine priority information of the N processes according to process information of the N processes;
[0122] The adjustment module 506 is used to send instruction information to a designated kernel module of the system so that the system adjusts the priorities of the N processes according to the priority information of the N processes.
[0123] The above-mentioned device, when the conditions for adjusting the process priority are met, obtains the process information of N processes, and determines the priority information of the N processes based on the obtained process information, thereby sending instruction information to the specified kernel module of the system to instruct the system to adjust the priority of the N processes based on the priority information of the N processes, thereby solving the problem that the system cannot dynamically adjust the priority of the process.
[0124] In an exemplary embodiment, the acquisition module 502 is also used to determine whether the priority adjustment condition is met in the following manner: when the CPU usage rate of the central processing unit (CPU) of the system is greater than a first preset threshold or less than a second preset threshold, determine that the priority adjustment condition is met, wherein the first preset threshold is greater than the second preset threshold; and / or when the time interval between the current moment and the target moment is less than a third preset threshold, determine that the priority adjustment condition is met, wherein the target moment is the moment when the indication information was last sent to the specified kernel module of the system.
[0125] In an exemplary embodiment, the determination module 504 is also used to determine a first parameter value according to the process type of the i-th process, wherein the process type includes: user process and kernel process; when the i-th process is a user process, the first parameter value is equal to 1, and when the i-th process is a kernel process, the first parameter value is equal to 0; and determine a second parameter value according to the current state of the i-th process, wherein the current state includes: foreground state and background state; and determine a third parameter value according to the number of file descriptors corresponding to the i-th process; and determine a fourth parameter value according to the CPU usage time of the i-th process, wherein the CPU usage time includes: CPU time in kernel state and CPU time in user state; and determine a priority adjustment strategy of the process, and determine a priority calculation method from preset configuration information according to the priority adjustment strategy, wherein the preset configuration information has priority calculation methods corresponding to different priority adjustment strategies; using the priority calculation method, determine the priority of the i-th process according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value.
[0126] In an exemplary embodiment, the determination module 504 is also used to determine the priority of the i-th process using the target formula when the priority calculation method is to use a target formula to calculate the priority; wherein the target formula is: P = α×sigmoid(β×W_ppid+θ×(W_tty+W_files) / W_time)+z, p is the priority of the i-th process, W_ppid is the first parameter value, W_tty is the second parameter value, W_files is the third parameter value, W_time is the fourth parameter value, and α, β, θ and z are preset weight parameters.
[0127] In an exemplary embodiment, the determination module 504 is also used to, after determining the priority of the ith process according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value, adjust the priority of the ith process according to the priority adjustment information corresponding to the preset name when the process name of the ith process is a preset name; and / or adjust the priority of the ith process according to the priority adjustment information corresponding to the preset path when the program file path corresponding to the ith process is a preset path.
[0128] In an exemplary embodiment, the above-mentioned device also includes: a monitoring module, which is used to monitor multiple processes running in the system according to a preset monitoring frequency before obtaining the process information of N processes, and store the process information of the monitored processes in a target database; the acquisition module 502β is also used to obtain the process information of the N processes from the target database.
[0129] In an exemplary embodiment, the acquisition module 502 is also used to obtain the monitoring frequency, the priority adjustment conditions, and the priority adjustment strategy through an interactive interface, wherein the monitoring frequency is the monitoring frequency for monitoring multiple processes running in the system; or to obtain the monitoring frequency, the priority adjustment conditions, and the priority adjustment strategy through the hypertext transfer protocol HTTP.
[0130] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0131] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0132] Optionally, in this embodiment, the computer program may be configured to perform the following steps by means of the computer program:
[0133] S1, when a process priority adjustment condition is met, obtaining process information of N processes, wherein the N processes are processes currently running in the system;
[0134] S2, determining priority information of the N processes according to the process information of the N processes;
[0135] S3, sending instruction information to a designated kernel module of the system, so that the system adjusts the priorities of the N processes according to the priority information of the N processes.
[0136] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0137] The embodiment of the present application also provides an electronic device, such as Figure 6 As shown, the electronic device includes a memory 602 and a processor 604. The memory 602 stores a computer program, and the processor 604 is configured to execute the steps in any of the above method embodiments through the computer program.
[0138] Optionally, in this embodiment, the processor 604 may be configured to perform the following steps through a computer program:
[0139] S1, when a process priority adjustment condition is met, obtaining process information of N processes, wherein the N processes are processes currently running in the system;
[0140] S2, determining priority information of the N processes according to the process information of the N processes;
[0141] S3, sending instruction information to a designated kernel module of the system, so that the system adjusts the priorities of the N processes according to the priority information of the N processes.
[0142] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0143] Alternatively, a person skilled in the art may understand that: Figure 6 The structure shown is for illustration only. Figure 6 The structure of the electronic device is not limited. For example, the electronic device may also include Figure 6 More or fewer components (such as network interfaces, etc.) as shown in, or with Figure 6 Different configurations are shown.
[0144] Among them, the memory 602 can be used to store software programs and modules, such as the program instructions / modules corresponding to the process priority adjustment method and the process priority adjustment device in the embodiment of the present application. The processor 604 executes various functional applications and data processing by running the software programs and modules stored in the memory 602, that is, realizing the above-mentioned process priority adjustment method. The memory 602 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 602 may further include a memory remotely located relative to the processor 604, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Among them, the memory 602 can be specifically, but not limited to, used to store information such as system configuration files. As an example, such as Figure 6 As shown, the memory 602 may include, but is not limited to, the acquisition module 502, the determination module 504, and the adjustment module 506 in the process priority adjustment device. In addition, other module units in the process priority adjustment device may also be included but are not limited to the above, which will not be repeated in this example.
[0145] Optionally, the transmission device 606 is used to receive or send data via a network. Specific examples of the network may include a wired network and a wireless network. In one example, the transmission device 606 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 606 is a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0146] In addition, the electronic device further includes: a display 608; and a connection bus 610, which is used to connect various module components in the electronic device.
[0147] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0148] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0149] The embodiments of the present application also provide a computer program, which includes computer instructions, which are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any one of the above method embodiments.
[0150] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0151] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for adjusting process priority, characterized in that: include: When the adjustment condition of the process priority is met, process information of N processes is obtained, wherein the N processes are processes currently running in the system; Determining priority information of the N processes according to the process information of the N processes; Sending instruction information to a designated kernel module of the system so that the system adjusts the priorities of the N processes according to the priority information of the N processes.
2. The method according to claim 1, characterized in that The method further comprises: Whether the priority adjustment conditions are met is determined in the following way: When the CPU usage rate of the system is greater than a first preset threshold or less than a second preset threshold, determining that the priority adjustment condition is met, wherein the first preset threshold is greater than the second preset threshold; and / or When the time interval between the current moment and the target moment is less than a third preset threshold, determining that the adjustment condition of the priority is met, wherein the target moment is the moment when the indication information was last sent to the designated kernel module of the system.
3. The method according to claim 1, characterized in that: The determining the priority information of the N processes according to the process information of the N processes includes: The priority of the i-th process among the N processes is determined in the following manner: determining a first parameter value according to a process type of the i-th process, wherein the process type includes: a user process and a kernel process; when the i-th process is a user process, the first parameter value is equal to 1, and when the i-th process is a kernel process, the first parameter value is equal to 0; and Determining a second parameter value according to a current state of the i-th process, wherein the current state includes: a foreground state and a background state; and Determine a third parameter value according to the number of file descriptors corresponding to the i-th process; and Determine a fourth parameter value according to the CPU usage time of the i-th process, wherein the CPU usage time includes: CPU time in kernel state and CPU time in user state; and Determine a priority adjustment strategy for the process, and determine a priority calculation method from preset configuration information according to the priority adjustment strategy, wherein the preset configuration information includes priority calculation methods corresponding to different priority adjustment strategies; Using the priority calculation method, the priority of the i-th process is determined according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value.
4. The method according to claim 3, characterized in that The using the priority calculation method to determine the priority of the i-th process according to the first parameter value, the second parameter value, the third parameter value, and the fourth parameter value includes: In a case where the priority calculation method is to use a target formula to calculate the priority, using the target formula, determining the priority of the i-th process according to the first parameter value, the second parameter value, the third parameter value, and the fourth parameter value; Among them, the target formula is: P = α×sigmoid(β×W_ppid+θ×(W_tty+W_files) / W_time)+z, p is the priority of the i-th process, W_ppid is the first parameter value, W_tty is the second parameter value, W_files is the third parameter value, W_time is the fourth parameter value, and α, β, θ and z are preset weight parameters.
5. The method according to claim 3, characterized in that: After determining the priority of the i-th process according to the first parameter value, the second parameter value, the third parameter value and the fourth parameter value, the method further includes: When the process name of the i-th process is a preset name, adjusting the priority of the i-th process according to the priority adjustment information corresponding to the preset name; and / or In a case where the program file path corresponding to the i-th process is a preset path, the priority of the i-th process is adjusted according to the priority adjustment information corresponding to the preset path.
6. The method according to claim 1, characterized in that Before obtaining the process information of the N processes, the method further includes: monitoring the multiple processes running in the system according to a preset monitoring frequency, and storing the process information of the monitored processes in a target database; The obtaining process information of the N processes includes: obtaining the process information of the N processes from the target database.
7. The method according to claim 1, characterized in that The method further comprises: Acquiring a monitoring frequency, a priority adjustment condition, and a priority adjustment strategy through an interactive interface, wherein the monitoring frequency is a monitoring frequency for monitoring multiple processes running in the system; or The monitoring frequency, the priority adjustment condition, and the priority adjustment strategy are obtained through the hypertext transfer protocol HTTP.
8. A device for adjusting process priority, characterized in that: include: An acquisition module, used for acquiring process information of N processes when a process priority adjustment condition is met, wherein the N processes are processes currently running in the system; A determination module is used to determine the priority information of the N processes according to the process information of the N processes; an adjustment module is used to send instruction information to a specified kernel module of the system so that the system adjusts the priority of the N processes according to the priority information of the N processes.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Processing method and device of processor, storage medium and electronic equipment
CN121597427A
