Linux performance optimization ideas

Performance Optimization

Core performance optimization is to identify bottlenecks point of the system, the problem is found, the optimization of the work is done half; performance optimization presented here mainly to introduce two levels: system level and program level.

top

After entering the interactive mode:

  • Input M, the process list sorted by descending size memory usage, for us to observe the biggest memory consumers use a problem (to detect memory leaks)
  • Input P, ​​the list of processes by CPU usage size in descending order, for us to observe users consuming the most CPU resources if there are problems

The third top line shows the current system, in which there are two critical values:

  • % Id: percentage of CPU idle time, and if this value is too low, the system indicates a bottleneck CPU
  • % Wa: waiting for I / O percentage of CPU time, if this value is too high, indicating the presence of IO bottleneck
Memory bottleneck analysis

Check whether the memory bottleneck, using the top command to see more trouble, more intuitive command and free.

top tool displays the first line free tool all the information, but the real memory available, you also need to know their own computing; the actual system memory available for the free tool output of the second row free + buffer + cached.

If it is because of lack of memory, slow system response obviously, because it makes the system stop doing swapped out of work.

IO bottleneck analysis

If the IO performance bottleneck, top tool% wa will be high.

  • If the value of% iowait too high, indicates the presence of the hard disk I / O bottlenecks
  • If% util close to 100%, indicating that the generated I / O requests too, I / O system has been at full capacity, the disk may be a bottleneck
  • If svctm close to await, for I / O is almost no waiting time
  • If the svctm await much larger than, for I / O queue is too long, too slow IO response is necessary to optimize the required
  • If avgqu-sz relatively large, also said there is a lot of waiting for io
Analysis process calls

pstack和pstrace。

pstack used to track the process stack, this command is useful when troubleshooting process issues, such as we find that a service has been in work status (such as suspended animation, like an infinite loop), use this command can easily locate the problem; you can over a period of time inside, execute it several times pstack, if found code stack is always parked in the same location, that location will need to focus on, it is likely to go wrong.

Strace used to track and process the system call; system call and the received signal when the tool can be performed dynamically tracing process. It is a very effective detection, guidance and debugging tools. System administrators can easily solve the problem by the program command.

gprof use the steps
  • By gcc, g ++, when the compiler xlC using -pg parameters, such as: g ++ -pg -o test.exe test.cpp compiler automatically inserted in the object code snippet for performance testing, the program code runs when the relationship between the collection and call functions and number of calls and records the execution time of the execution time of the function itself and the called function.
  • After compiling an executable program execution, such as: ./ test.exe. Runtime executable program running time of this step will be slightly slower than a normal compilation. After the run, where the program is generated in the default file path to a file named gmon.out of this document is to record the performance of the program is running, call the relationship, call the data file information such as number of times.
  • Use gprof command to analyze the record running information gmon.out file, such as: gprof test.exe gmon.out you can see on the display the function call-related statistics, analysis information. The above information may be used gprof test.exe gmon.out> gprofresult.txt redirected to a text file for subsequent analysis.
Other Tools
  • valgrind
  • OProfile
  • sar

To be learned. . .

Published 162 original articles · won praise 7 · views 30000 +

Guess you like

Origin blog.csdn.net/LU_ZHAO/article/details/104950768