性能优化-优化nginx服务对CPU亲和力worker_cpu_affinity

默认情况下可能多个进程跑在一个CPU上或某一核上,导致Nginx进程使用硬件资源不均匀,此次优化是尽可能地分配不同的Nginx进程给不同的CPU处理

放置位置:主标签段,不在任何区块

配置方法案例:  

两颗CPU参数配置

   worker_processes  2;

   worker_cpu_affinity 0101 1010;

四颗CPU参数配置

   worker_processes  4;

   worker_cpu_affinity 0001 0010 0100 1000;

八颗CPU参数配置

   worker_processes  8;

   worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

八颗CPU参数配置

   worker_processes  8;

   worker_cpu_affinity 0001 0010 0100 1000 0001 0010 0100 1000;

 

在主配置文件nginx.conf中配置

[root@web01 conf]# cat /application/nginx/conf/nginx.conf
worker_processes  2;
worker_cpu_affinity 0101 1010;   #添加的
error_log logs/error.log;
 
#配置Nginx worker进程最大打开文件数
worker_rlimit_nofile 65535;
 
user www www;
events {
    #单个进程允许的客户端最大连接数
    worker_connections  20480;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    #访问日志配置
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
 
    #虚拟主机
    include /application/nginx/conf/extra/www.conf;
    include /application/nginx/conf/extra/blog.conf;
    include /application/nginx/conf/extra/bbs.conf;
    include /application/nginx/conf/extra/edu.conf;
    include /application/nginx/conf/extra/phpmyadmin.conf;
    include /application/nginx/conf/extra/status.conf;
 
    #隐藏版本号
    server_tokens on;
}