-
-
Save rainly/53e0324db7591b22945c0fdf266691f9 to your computer and use it in GitHub Desktop.
指定nginx工作在第二个cpu上,跟php错开cpu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
公司一台2个CPU共8核的服务器访问量上来后top里load高达8到17,但cpu占用却只有Cpu(s): 50%us,可能是static模式下启动php-fpm全起在第一个cpu上了,尝试把nginx的进程指定到第二个cpu上,负载马上降到2左右了: | |
有8个核心的话可以把nginx分到第二个cpu的1,3,5,7这4个核上, php5-fpm则默认跑在第一个cpu的0,2,4,6核心, 在nginx.conf里: | |
worker_processes 4; | |
worker_cpu_affinity 00000010 00001000 00100000 10000000; #不要用worker_cpu_affinity 10101010; 不均衡 | |
sudo service nginx restart | |
第二个cpu的具体核心序号要先看看核心分布: | |
grep -P '^physical id' /proc/cpuinfo | |
比如4*2核不超线程的可能是:01 01 01 01 也可能是 00 11 00 11, 还可能是10 10 10 10(奇怪的是这些机器不论01先后,0号cpu的负载总是比1号大得多) | |
4*2核超线程的可能是:0000 1111 0000 1111 | |
看nginx进程的cpu核心分布: | |
top -p$(pgrep nginx |awk 'BEGIN{ORS=","}{print $0}' |sed 's/.$//') | |
再敲"f,j,回车" | |
top里敲"1"看每个cpu核心的占用情况 | |
至于php5-fpm, 有人写了个定时任务来均衡cpu(https://gist.github.com/israelshirk/5889922): | |
for i in `ps auxw | grep php-fpm | awk ' { print $2; } '`; do echo $i; taskset -pc 1-7 $i; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment