将进程绑定到指定的CPU上运行,这样可以避免大量的进程切换产生的无效时间。
先看看都有哪些httpd进程:
[root@localhost image]# pgrep -l httpd
10929 httpd
10931 httpd
10932 httpd
10933 httpd
11281 httpd
11283 httpd
11284 httpd
11317 httpd
11326 httpd
11359 httpd
12145 httpd
我们实时观测这些httpd进程都运行在哪些CPU上
[root@localhost ~]#watch -n 0.5 'ps -e -o psr,pid,cmd | grep httpd'
然后我们把11317,11326的httpd绑定在CPU 2上
[root@localhost ~]# taskset -p -c 2 11317
pid 11317's current affinity list: 0-3
pid 11317's new affinity list: 2
[root@localhost ~]# taskset -p -c 2 11326
pid 11326's current affinity list: 0-3
pid 11326's new affinity list: 2
执行请求使得内存切换
[root@localhost ~]# ab -n 10000 -c 1000 http://192.168.100.24/index.html
然后我们在watch下看到这2个PID一直不会再切换了