將進程綁定到指定的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一直不會再切換了