kvm虚拟机 nginx性能测试,由于经费,还有目前测


暂时停止对mongodb的性能测试,因为前端做负载均衡的Nginx性能提升不上去。由于经费,还有目前测试条件的限制,我们做的性能测试都是在KVM虚拟机里搭建的环境,nginx1.2.6 测试工具就是apache benchmark(ab) 操作系统是centos5.4(好老啊)。

测试准备:

主要是内核参数调优,常见的dmesg信息就是TCP: time wait bucket table overflow。

如果开启了iptables那么可能会遇到kernel: ip_conntrack: table full, dropping packet

net.ipv4.tcp_max_tw_buckets = 65535
net.ipv4.tcp_sack = 1 
net.ipv4.tcp_window_scaling = 1 
net.ipv4.tcp_rmem = 4096 87380 4194304  
net.ipv4.tcp_wmem = 4096 16384 4194304  
net.core.wmem_default = 8388608 
net.core.rmem_default = 8388608 
net.core.rmem_max = 16777216 
net.core.wmem_max = 16777216 
net.core.netdev_max_backlog = 262144 
net.core.somaxconn = 262144 
net.ipv4.tcp_max_orphans = 3276800 
net.ipv4.tcp_max_syn_backlog = 262144 
net.ipv4.tcp_timestamps = 0 
net.ipv4.tcp_synack_retries = 1 
net.ipv4.tcp_syn_retries = 1 
net.ipv4.tcp_tw_recycle = 1 
net.ipv4.tcp_tw_reuse = 1 
net.ipv4.tcp_mem = 94500000 915000000 927000000  
net.ipv4.tcp_fin_timeout = 1 
net.ipv4.tcp_keepalive_time = 30 
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 90
net.ipv4.ip_local_port_range = 1024 65000 
fs.file-max = 102400

测试页面就是简单的html,内容是hello world,虚拟机配置:2cpu 2GB memory。

虚拟机内部搭建单个nginx实例,work process的值我们开始设置的很高。比如2个cpu 我们给它设定的值为8或者16,在跑ab测试的时候,运行vmstat 监控状态,会发现等待运行的进程数>5,当这个数值上升时,可以明显感觉到ab的速度在下滑。但是调整到和cpu个数一致。等待运行的进程数有明显的降低。

ok 在虚拟机内部压nginx rps可以达到1w左右,感觉还算比较正常。相比物理上的测试结果,我觉得这个rps还是比较满意的,但是通过另外一台物理机,经过网络来压它 峰值只能到2k rps左右,我们的网络连接是100M,ab中的平均传输率在250K左右。用了一个工具dstat 来查看网络,磁盘io 网络传输在1M左右。显然没有达到峰值。哎 肯定是网络的问题了,查了kvm的相关资料。然后对比自己虚拟机选择的NIC omg。我们使用的是默认的NIC。推荐使用virtio 用virtio几乎可以达到物理NIC的效率,调整后测试。可以达到9k-1w rps 在GBit网络模式下,虚拟机的网络配置也推荐使用virtio。

相关内容