您好:
章老师好,打扰您了,想请教您个问题! 关于单机C1000K的优化经验! 目前我用Nginx开发了一个Proxy, 用Upstream模块开发的!
单核的QPS在2w多, 2核的QPS在4w左右, 4核心的QPS在6w左右, 6核心的QPS在8w左右....
目前的情况是:
目前我的是千兆网卡, 每秒读写吞吐也就在70M左右, 通过dstat 查询的, 并且内存, 以及upstream后端服务器CPU也都不是瓶颈。
声明下,我的upstream模块里面并没有用mmap之类的共享内存, 也没有锁之类的东西。
Nginx CPU差不多快跑满了, 但是增加核数, 没线性增长
问题1: 当我线性的增加Nginx配置文件里面的CPU核数, 相应的QPS应该是线性增长, 不求非常精确, 但是也不至于,相差太多。
目前我的Nginx绑定了CPU情缘性10核心,但是QPS在13w多
问题2: 关于高性能Nginx服务器的C1000k的优化经验, 非常感谢大家的分享经验
Nginx配置文件如下:
user root;
worker_processes 10;
#daemon off;
#master_process off;
worker_cpu_affinity
#000000000001
#000000000010
000000000100
000000001000
000000010000
000000100000
000001000000
000010000000
000100000000
001000000000
010000000000
100000000000
;
#error_log logs/error.log debug;
error_log logs/error.log;
worker_rlimit_core 200m;
working_directory /tmp;
pid logs/nginx.pid;
events {
worker_connections 204800;
use epoll;
accept_mutex off;
multi_accept on;
}
http {
sendfile on;
tcp_nodelay on;
tcp_nopush on;
access_log off;
server_tokens off;
reset_timedout_connection on;
keepalive_timeout 120;
keepalive_requests 100000;
client_max_body_size 20m;
client_body_buffer_size 1024k;
client_body_temp_path /tmp;
upstream redis_cluster {
testupstream_node $node_ip;
server 0.0.0.0;
keepalive 1024;
}
server {
listen 80;
server_name localhost backlog=204800;
set $backserver "redis_cluster";
set $node_ip "";
location ~* "^/hdp/kvstore/" {
testupstream_pass $backserver;
testupstream_next_upstream error timeout invalid_response;
}
}
}
内核参数:
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_max_tw_buckets = 262144
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 200000
net.core.rmem_default = 67108864
net.core.wmem_default = 67108864
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.ipv4.tcp_rmem = 4096 87380 6291456
net.ipv4.tcp_wmem = 4096 65536 4194304
net.ipv4.tcp_mem = 3097431 4129911 6194862
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.ip_forward = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_keepalive_time = 120
vm.overcommit_memory = 1
fs.file-max = 1048576