压力测试TCP参数优化TIME_WAIT

 

一、环境

RHEL 6.5, Nginx 1.8.1

RHEL 6.5, Websphere 7.0

 

二、问题

1.nginx报错

connect() failed (110: Connection timed out) while connecting to upstream

 

2.压力大时,nginx服务器和was服务器有大量TIME_WAIT连接,达到几万

linux查看TCP连接数量

扫描二维码关注公众号,回复: 347783 查看本文章

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

 

三、优化方法

1.nginx性能优化配置长连接

nginx反向代理upstream默认使用短连接,可以采用长连接,效果十分明显,TIME_WAIT只剩几百了

http://happyqing.iteye.com/blog/2384283

 

2.linux TCP参数优化

vi /etc/sysctl.conf 添加

net.core.somaxconn = 2048

net.ipv4.tcp_fin_timeout = 30

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_timestamps = 0 #不验证时间戳

(如果有多台服务器,时间不一致,需要加上此参数,否则有的连接请求会被抛弃)

 

#立即生效

/sbin/sysctl -p 

 

四、压测试机调整

产生压力的测试机(win7 )也会有大量的TIME_WAIT连接

windows查看TIME_WAIT连接

cmd

netstat -ano

netstat -ano > d:/port.txt 导出到文件

 

1、修改注册表中的tcpip的参数:TIMEWAIT回收时间

在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters,添加名为TcpTimedWaitDelay的DWORD键,设置为十进制1,以缩短TIME_WAIT的等待时间。

 

2.MaxUserPort 改为 65534

 

猜你喜欢

转载自happyqing.iteye.com/blog/2384342