CPU load management method and device of Unix system and computer readable storage medium
By registering SIGURG signal processing function in Unix system and periodically reading CPU processor activity information, dynamically managing the CPU load of Unix system, solving the problem of high CPU load management cost and inability to dynamically adjust in the prior art, and achieving the effect of low-cost and dynamic adjustment of CPU load.
Patent Information
- Application Number
- CN202411469409.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-03-07
AI Technical Summary
The CPU load management method of existing Unix systems is expensive and cannot achieve dynamic adjustment of CPU usage, making it difficult to effectively manage CPU load, preventing server performance degradation and service crashes.
When creating thread tasks for applications in Unix systems, register SIGURG signal processing functions, and periodically read CPU processor activity information in system files to calculate the actual CPU usage rate. When the usage rate exceeds the preset threshold, send a SIGURG signal to the target thread task to make it fall asleep and reduce the CPU load; when the usage rate is normal, sending a wake-up condition variable to keep the thread task running.
Dynamic management of CPU processor load is realized, reducing CPU load, avoiding the need for hardware expansion and increasing servers, and the cost is low.
Smart Images

Figure CN119576526A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the technical field of Unix systems, and in particular to a CPU load management method, device and computer-readable storage medium for a Unix system. Background Art
[0002] If the CPU processor load of the Unix system is too high, it will lead to a decline in the overall performance of the server, slow application response time, delays and freezes; in addition, if the CPU processor is at full load for a long time, some key processes may not be able to obtain sufficient resources, resulting in service crashes or interruptions, reduced system stability, and prone to errors; for this reason, Unix systems usually need to ensure that the system's CPU processor load is maintained below 70%.
[0003] There are three main methods for CPU load management in Unix systems: the first method is to adopt a load balancing strategy to distribute tasks to multiple servers to reduce the pressure on a single server. However, this strategy requires additional server support, which increases the cost accordingly; the second method is to increase the number of CPU cores in the Unix system, upgrade the CPU model or expand the memory capacity to relieve the CPU pressure; similarly, this method requires hardware upgrades, which also increases the cost; the third method is to use control group technology (cgroups) to limit the CPU occupancy rate of each thread task in the Unix system, thereby limiting the CPU load of the system to a certain extent. However, this method only provides static restrictions with coarse granularity and cannot be dynamically adjusted according to the actual system load. Summary of the invention
[0004] The technical problem to be solved by the embodiment of the present invention is to provide a CPU load management method for a Unix system, which has low cost and can realize dynamic adjustment of CPU usage.
[0005] A further technical problem to be solved by the embodiments of the present invention is to provide a CPU load management device for a Unix system, which has low cost and can realize dynamic adjustment of CPU usage.
[0006] A further technical problem to be solved by an embodiment of the present invention is to provide a computer-readable storage medium for storing a computer program with low storage cost and capable of dynamically adjusting CPU usage.
[0007] In order to solve the above technical problems, the embodiment of the present invention provides the following technical solution: a CPU load management method of a Unix system, comprising the following steps: When an application program running in a CPU processor of a Unix system creates a thread task according to usage requirements, the application program registers a SIGURG signal processing function corresponding to a target thread task to be monitored based on the type of the thread task; Periodically reading a predetermined system file in the Unix system, and calculating an actual utilization rate of the CPU processor in a recent period based on CPU processor activity information in the system file; Compare the actual usage rate with a preset threshold value. When the actual usage rate is greater than the threshold value, send a SIGURG signal to the target thread task to make the target thread task enter a SIGURG signal processing function and go into a sleep state. When the actual usage rate is less than or equal to the threshold value, send a wake-up condition variable to the target thread task to make the target thread task run normally.
[0008] Furthermore, the step of registering a SIGURG signal processing function corresponding to the thread task to be monitored according to the type of the thread task specifically includes: Analyze the types of the thread tasks, and determine the computationally intensive and non-real-time thread tasks as target thread tasks that need to be monitored; and Register the process identifier of the target thread task with the SIGURG signal processing function.
[0009] Furthermore, the pthread_kill system function is used to send the SIGURG signal or the wake-up condition variable to the target thread task.
[0010] Furthermore, the system file is a stat file in the proc directory of the Unix system, and the stat file contains the following CPU processor activity information: time in user state, system state and idle state.
[0011] Furthermore, the calculating the actual usage rate of the CPU processor in the most recent cycle based on the CPU processor activity information in the system file specifically includes: Parsing the system file to obtain the total running time and the total idle time of the CPU processor after the Unix system is started; The duration T of the most recent cycle is calculated based on the total running time and the total idle time respectively obtained by parsing the system file for the last two times. 总 And the idle time T of the CPU processor in the most recent cycle 闲 ;as well as The actual usage rate Usr is calculated based on the following formula: Usr = (T 总 -T 闲 ) / T 总 100%.
[0012] On the other hand, in order to solve the above further technical problems, an embodiment of the present invention provides the following technical solution: a CPU load management device for a Unix system, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the CPU load management method for a Unix system as described in any one of the above items when executing the computer program.
[0013] On the other hand, in order to solve the above-mentioned further technical problems, an embodiment of the present invention provides the following technical solutions: a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the CPU load management method of the Unix system as described in any one of the above items.
[0014] After adopting the above technical scheme, the embodiment of the present invention has at least the following beneficial effects: when the application program running in the CPU processor of the Unix system creates a thread task according to the use demand, the embodiment of the present invention registers the SIGURG signal processing function corresponding to the target thread task to be monitored based on the type of the thread task, and calculates the actual usage rate of the CPU processor of the Unix system by periodically reading the CPU processor activity information in the system file predetermined by the Unix system, and then compares the calculated actual usage rate with the preset threshold value. When the actual usage rate is greater than the preset usage rate threshold value, it indicates that the load of the CPU processor is too high and needs to be controlled. At this time, a SIGURG signal is sent to the target thread task to control the target thread task to enter the SIGURG signal processing function and stop running and enter a sleep state, thereby reducing the load of the CPU processor. Otherwise, it indicates that the load of the CPU processor is normal. At this time, a wake-up condition variable is sent to the target thread task to prompt the target thread task in the sleep state to continue running or to prompt the thread task in the running state to keep running, thereby realizing dynamic management of the CPU processor load, without the need for hardware expansion or adding servers, and the cost is also low. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 The following is a flowchart of an optional embodiment of the CPU load management method for a Unix system according to the present invention.
[0016] Figure 2 The figure is a principle block diagram of an optional embodiment of the CPU load management device for a Unix system of the present invention.
[0017] Figure 3 This is a functional module diagram of an optional embodiment of the CPU load management device for a Unix system of the present invention. DETAILED DESCRIPTION
[0018] The present application is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the following illustrative embodiments and descriptions are only used to explain the present invention and are not intended to limit the present invention. In addition, the embodiments and features in the embodiments of the present application may be combined with each other without conflict.
[0019] like Figure 1 As shown, an optional embodiment of the present invention provides a CPU load management method for a Unix system, comprising the following steps: S1: When an application program running in a CPU processor of a Unix system creates a thread task according to usage requirements, the application program registers a SIGURG signal processing function corresponding to a target thread task to be monitored based on the type of the thread task; S2: periodically reading a predetermined system file in the Unix system, and calculating an actual utilization rate of the CPU processor in a recent period based on the CPU processor activity information in the system file; S3: Compare the actual usage rate with a preset threshold (for example, 70%). When the actual usage rate is greater than the threshold, send a SIGURG signal to the target thread task to enable the target thread task to enter a SIGURG signal processing function and enter a sleep state. When the actual usage rate is less than or equal to the threshold, send a wake-up condition variable to the target thread task to enable the target thread task to operate normally.
[0020] In the embodiment of the present invention, when an application program running in a CPU processor of a Unix system creates a thread task according to usage requirements, a SIGURG signal processing function is correspondingly registered for a target thread task to be monitored based on the type of the thread task, and after the actual usage rate of the CPU processor of the Unix system is calculated by periodically reading the CPU processor activity information in a system file predetermined by the Unix system, the calculated actual usage rate is compared with a preset threshold value. When the actual usage rate is greater than the preset usage rate threshold value, it indicates that the load of the CPU processor is too high and needs to be controlled. At this time, a SIGURG signal is sent to the target thread task to control the target thread task to enter the SIGURG signal processing function and stop running and enter a sleep state, thereby reducing the load of the CPU processor. Otherwise, it indicates that the load of the CPU processor is normal. At this time, a wake-up condition variable is sent to the target thread task to prompt the target thread task in the sleep state to continue running or to prompt the thread task in the running state to keep running, thereby realizing dynamic management of the CPU processor load, without the need for hardware expansion or adding servers, and with low cost.
[0021] In an optional embodiment of the present invention, the step of registering a SIGURG signal processing function corresponding to the target thread task to be monitored based on the type of the thread task specifically includes: Analyze the types of the thread tasks, and determine the computationally intensive and non-real-time thread tasks as target thread tasks that need to be monitored; and Register the process identifier of the target thread task with the SIGURG signal processing function.
[0022] In this embodiment, during the running of the application, many thread tasks need to be created, among which computationally intensive thread tasks have a high demand for the utilization rate of the CPU processor and have a great impact on the CPU load, while non-real-time thread tasks can be suspended and turned into a sleep state when necessary. Therefore, computing-intensive and non-real-time thread tasks are determined as target thread tasks, which can more accurately manage the thread tasks and control the CPU load within a reasonable range without affecting the overall normal operation of the application.
[0023] In an optional embodiment of the present invention, the pthread_kill system function is used to send the SIGURG signal or the wake-up condition variable to the target thread task. In this embodiment, the pthread_kill system function is a common function for sending signals to thread tasks in Unix systems. Using this function to send the SIGURG signal or the wake-up condition variable is conducive to improving the adaptability of the method of the present invention and simplifying data processing.
[0024] In an optional embodiment of the present invention, the system file is a stat file in the proc directory of the Unix system, and the stat file contains the following CPU processor activity information: user state, system state and idle state time. In this embodiment, the value of the first line of the system / proc / stat file content represents the detailed information of the system CPU processor activity, such as the user state, system state and idle state time, and the above time is accumulated from the start of the Unix system to the current time, that is, the total running time and the total idle time.
[0025] In an optional embodiment of the present invention, the calculating the actual usage rate of the CPU processor in the most recent cycle based on the CPU processor activity information in the system file specifically includes: Parsing the system file to obtain the total running time and the total idle time of the CPU processor after the Unix system is started; The duration T of the most recent cycle is calculated based on the total running time and the total idle time respectively obtained by parsing the system file for the last two times. 总 And the idle time T of the CPU processor in the most recent cycle闲 ;;as well as The actual usage rate Usr is calculated based on the following formula: Usr = (T 总 -T 闲 ) / T 总 100%.
[0026] In this embodiment, the total operating time and total idle time of the CPU processor are obtained by parsing, and then the time length T of the most recent cycle is calculated based on the results of the two most recent parsing passes. 总 And the idle time T of the CPU processor in the most recent cycle 闲 , so that the actual utilization rate can be calculated according to the relevant formula, the calculation efficiency is high, and the actual utilization rate obtained is relatively accurate, which is conducive to precise management.
[0027] On the other hand, Figure 2 As shown, an embodiment of the present invention provides a CPU load management device 3 for a Unix system, which is connected to a vehicle-mounted radar 1. The device 3 includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the CPU load management method for the Unix system as described in any one of the above items is implemented.
[0028] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 32 and executed by the processor to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the CPU load management device 3 of the Unix system. For example, the computer program may be divided into Figure 3 The functional modules in the CPU load management device 3 of the Unix system, wherein the function registration module 41, the usage rate calculation module 42 and the thread control module 43 respectively execute the above steps S1 to S3.
[0029] The CPU load management device 3 of the Unix system may be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The CPU load management device 3 of the Unix system may include, but is not limited to, a processor 30 and a memory 32. Those skilled in the art may understand that the schematic diagram is only an example of the CPU load management device 3 of the Unix system, and does not constitute a limitation on the CPU load management device 3 of the Unix system, and may include more or less components than shown in the figure, or combine certain components, or different components, for example, the CPU load management device 3 of the Unix system may also include input and output devices, network access devices, buses, etc.
[0030] The processor 30 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor 30 is the control center of the CPU load management device 3 of the Unix system, and uses various interfaces and lines to connect various parts of the CPU load management device 3 of the entire Unix system.
[0031] The memory 32 can be used to store the computer program and / or module. The processor 30 realizes various functions of the CPU load management device 3 of the Unix system by running or executing the computer program and / or module stored in the memory 32 and calling the data stored in the memory 32. The memory 32 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a graphic recognition function, a graphic overlay function, etc.), etc.; the data storage area can store data (such as graphic data, etc.) created according to the use of the control device, etc. In addition, the memory 32 can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0032] If the functions described in the embodiments of the present invention are implemented in the form of software function modules or units and sold or used as independent products, they can be stored in a storage medium readable by a computing device. Based on this understanding, the embodiments of the present invention implement all or part of the processes in the above-mentioned embodiments, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor 30, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0033] On the other hand, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the CPU load management method of the Unix system as described in the above embodiment.
[0034] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0035] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the enlightenment of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, which all belong to the protection scope of the present invention.
Claims
1. A CPU load management method for a Unix system, characterized in that: The method comprises the following steps: When an application program running in a CPU processor of a Unix system creates a thread task according to usage requirements, the application program registers a SIGURG signal processing function corresponding to a target thread task to be monitored based on the type of the thread task; Periodically reading a predetermined system file in the Unix system, and calculating an actual utilization rate of the CPU processor in a recent period based on CPU processor activity information in the system file; and Compare the actual usage rate with a preset threshold value. When the actual usage rate is greater than the threshold value, send a SIGURG signal to the target thread task to make the target thread task enter a SIGURG signal processing function and go into a sleep state. When the actual usage rate is less than or equal to the threshold value, send a wake-up condition variable to the target thread task to make the target thread task run normally.
2. The CPU load management method of a Unix system according to claim 1, characterized in that: The registering of the SIGURG signal processing function corresponding to the target thread task to be monitored based on the type of the thread task specifically includes: Analyze the types of the thread tasks, and determine the computationally intensive and non-real-time thread tasks as target thread tasks that need to be monitored; and Register the process identifier of the target thread task with the SIGURG signal processing function.
3. The CPU load management method of a Unix system according to claim 1, characterized in that: The pthread_kill system function is used to send the SIGURG signal or the wake-up condition variable to the target thread task.
4. The CPU load management method of a Unix system according to claim 1, characterized in that: The system file is a stat file in the proc directory of the Unix system, and the stat file contains the following CPU processor activity information: time in user state, system state and idle state.
5. The CPU load management method of a Unix system as claimed in claim 1 or 4, characterized in that: The calculating the actual usage rate of the CPU processor in the most recent cycle based on the CPU processor activity information in the system file specifically includes: Parsing the system file to obtain the total running time and the total idle time of the CPU processor after the Unix system is started; The duration T of the most recent cycle is calculated based on the total running time and the total idle time respectively obtained by parsing the system file for the last two times. 总 And the idle time T of the CPU processor in the most recent cycle 闲 ;as well as The actual usage rate Usr is calculated based on the following formula: Usr = (T 总 -T 闲 ) / T 总 100%.
6. A CPU load management device for a Unix system, characterized in that: The device includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and the processor implements the CPU load management method of the Unix system according to any one of claims 1 to 5 when executing the computer program.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the CPU load management method for a Unix system according to any one of claims 1 to 5.