Sometimes, because of the architectural design or other business itself characteristics, resulting in some applications using CPU is very uneven, so business processing concentrated on one CPU, while the other CPU idle sleep. Here is a simple optimization scheme that binds individual threads to multiple CPUs to achieve performance improvements.
Although the CPU is a good idea, but is not the killer, its performance can improve how much depends on the performance of each thread is evenly distributed, so the best way is to optimize your program architecture.
Share a shell script here (bindcpu2p.sh), through which the process can be evenly loaded onto each CPU.
Copy Code code as follows:
#!/bin/sh
Pids= '/sbin/pidof $ '
Cpunum= ' Cat/proc/cpuinfo | grep Processor | Wc-l '
Cpuidx=0
For PID in $pids
Todo
/USR/BIN/TASKSET-CP ${cpuidx} ${pid}
cpuidx=$ (($cpuidx + 1))
cpuidx=$ (($cpuidx% $cpunum))
Echo $cpuidx
Done
Use method $>./bindcpu2p.sh progressname
Note: Please check the code of the brothers, can help debug under the best.