为什么要绑定 Nginx 进程到不同的 CPU 上 :默认情况下,Nginx 的多个进程有可能跑在某一个 CPU 或 CPU 的某一核上,导致 Nginx 进程使用硬件的资源不均,因此绑定 Nginx 进程到不同的 CPU 上是为了充分利用硬件的多 CPU 多核资源的目的。
[[email protected] ~]# grep -c processor /proc/cpuinfo # 查看CPU核数 2
worker_processes 2; # 2核CPU的配置 worker_cpu_affinity 01 10;
worker_processes 4; # 4核CPU的配置 worker_cpu_affinity 0001 0010 0100 1000;
worker_processes 8; # 8核CPU的配置 worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 1000000;
[[email protected] ~]# /usr/local/nginx/sbin/nginx -t [[email protected] ~]# /usr/local/nginx/sbin/nginx -s reload
[[email protected] ~]# cd /usr/local/src/ # 进行压力测试,教程:http://os.51cto.com/art/201202/317803.htm [[email protected] src]# wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz [[email protected] src]# tar -zxvf webbench-1.5.tar.gz [[email protected] src]# cd webbench-1.5 [[email protected] src]# yum install -y ctags gcc [[email protected] src]# mkdir -m 644 -p /usr/local/man/man1 [[email protected] src]# make && make install [[email protected] src]# webbench -c 10000 -t 60 http://192.168.5.131/
[[email protected] ~]# top # 按1查看CPU调度结果,这里是虚拟机测试,效果并不太明显 top - 14:44:46 up 4:40, 3 users, load average: 0.01, 0.32, 0.24 Tasks: 85 total, 1 running, 84 sleeping, 0 stopped, 0 zombie Cpu0 : 0.8%us, 0.8%sy, 0.0%ni, 97.9%id, 0.3%wa, 0.0%hi, 0.2%si, 0.0%st Cpu1 : 0.6%us, 0.7%sy, 0.0%ni, 98.1%id, 0.0%wa, 0.0%hi, 0.5%si, 0.0%st Mem: 1534840k total, 304824k used, 1230016k free, 3932k buffers Swap: 204792k total, 0k used, 204792k free, 191364k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 4319 root 20 0 98308 3932 2964 S 3.2 0.3 0:15.76 sshd 18989 root 20 0 15016 1292 1008 R 1.6 0.1 0:00.04 top 1 root 20 0 19232 1388 1112 S 0.0 0.1 0:02.19 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.08 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:00.61 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.60 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.50 watchdog/0
时间: 2024-10-13 06:52:18