Shell script implementation balances process load into multi-core CPUs _linux Shell

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.