Over the weekend, SSH login to the server is too slow, top view system load, more than 12. The trail found that other colleagues ran a bunch of programs over the weekend.
Slow system response. What should I do?
Two methods:
(1) Reduce the priority of other user programs.
Run the TOP command:
1 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND2 20211 lix 20 0 5703m 3.4g 558m S 473.4 43.6 662:41.75 datai3 5748 zhangren 20 0 133m 45m 2324 R 56.8 0.6 2572:29 nxagent4 2684 kdm 20 0 261m 3380 2184 S 6.3 0.0 45:46.62 kdm_greet5 28597 zhangren 30 10 31388 1772 1432 S 6.3 0.0 0:03.75 fuzzyflakes6 28610 root 20 0 23292 1596 1092 R 6.3 0.0 0:00.01 top7 1 root 20 0 10636 24 0 S 0.0 0.0 0:13.57 init
Explanation:
User: the identity of the performer.
PID: indicates the code of the process.
PR: indicates the priority of the process to be executed. The smaller the value, the earlier the execution.
NI: indicates the nice value of the process.
The first two pieces of information are easy to understand, but the last two strange pieces of information are PR and NI. What exactly is this? Relatively speaking, PR is also better understood, that is, the priority of the process, or the general point is the sequence in which the program is executed by the CPU. The smaller the value, the higher the priority of the process. What about NI? That is, the nice value that we want to talk about. It indicates the value of the priority that the process can be executed. As mentioned above, the smaller the prvalue, the faster it will be executed. After adding the nice value, the PR will be changed to: PR (new) = PR (old) + nice. In this way, when the nice value is negative, the program will have a smaller priority value, that is, the higher the priority, the faster the program will be executed.
So far, we need to emphasize that,The nice value of a process is not the priority of a process. They are not a concept, but the nice value of a process affects the priority of a process.
There are two commands for modifying the process priority: nice and renice.
1. Specify the nice value as soon as the program is executed: nice
Nice-n-5/usr/local/mysql/bin/mysqld_safe &
Nice command details
Function Description: sets priority.
Syntax: nice [-n <priority level>] [-- help] [-- version] [Execute Command]
Note: nice commands can change the priority level of program execution.
Parameter quantity:-n <priority level> or-adjustment = <priority level> sets the priority level of the command to be executed. The range of the level is-20-19, of which-20 is the highest and 19 is the lowest. Only the system administrator can set a negative level.
-Help Online help.
-Version: displays the version information.
-------------------------
2.1 adjust nice: renice of an existing process
Renice-5-p 5200
# Nice process with PID 5200Set-5(WhileNot in the original value-5)
Renice command details
Function Description: Adjust the priority.
Syntax: renice [priority level] [-g <Program Group Name>...] [-p <program identification code>...] [-u <User Name>...]
Note: The renice command can reset the priority level of program execution. The priority of a program is specified by the program identification code. You can also specify a program group or user name to adjust the priority level and modify the priority of all programs belonging to the program group or user. The level ranges from-20 to 19. Only the system administrator can change the priority of other user programs, and only the system administrator can set a negative number level.Note: The larger the nice value, the larger the process priority value, the smaller the chance of running on the CPU.
Parameters:
-G <Program Group Name> uses the program group name to modify the priority of all programs belonging to the program group.
-P <program identifier> changes the priority level of the program. This parameter is a preset value.
-U <User Name> specifies the user name to modify the priority of all programs belonging to the user.
Http://blog.csdn.net/codestinity/article/details/7496962
Run the following command to reduce the priority of all programs of a user:
renice +20 -u zhangrenxxxxx
Restore to normal:
renice 0 -u zhangrenxxxxx
(2) After lowering the priority of other user programs, the system load has not been downgraded for a short period of time, so I tried to use skill to suspend all processes of other users.
skill -STOP -u zhangrenxxxx
Pause all processes of zhangrenxxxx.
skill -CONT -u zhangrenxxxxx
Recover all processes of zhangrenxxxx.
References: http://www.jb51.net/LINUXjishu/57935.html
Now, the system load returns normal.
Note: Do not forget to restore the normal status of other user programs.
Linux uses sed to intercept files:
Sed-n' start row number, end row number P' file name
Note: the starting line number starts from 1 rather than 0.
Example: sed-N '1, 2000p' a.txt