您的位置:首页 > 其它

一次压力测试Loadrunner经验分享

2015-06-30 14:38 537 查看

一次压力测试Loadrunner经验分享

http://blog.csdn.net/lxlmj/article/category/553431

loadrunner测试socketstcpserver服务器

Action.c(4): Error -27796: Failed to connect to server "stadig.ifeng.com:80": [10048] Address already in use

Try changing the registry value

HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/tcpip/Parameters/TcpTimedWaitDelay to 30

and HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/tcpip/Parameters/MaxUserPort to 65534

and rebooting the machine

See the readme.doc file for more information

压测目标是一个简单的js,服务器处理很快。LR压力测试遇到如上错误,跟据提示在注册表中已将TcpTimedWaitDelay 改为 1;MaxUserPort 改为 65534;并且重启电脑。运行后仍出现上面的错误。后来在 run-time setting/browser emulation中

将simulate a new user on each iteration 选项去掉(默认是选中的)。重新运行一切正常,没有错误出现。

猜测原因,客户端性能比较好,发出压力太快,所以把tcp/ip的连接或端口占满。在网上查了一下,xp好像默认开启15个tcp/ip

去掉这个选项的意思是,始终使用一个tcp/ip链接,不断开,也就是开发人员所说的长链接或持久连接。
短连接:建立连接-----发送和接收报文1-------关闭连接
长连接:建立连接-----发送和接收报文1.。。。2.。。。3-----关闭连接

有大量ESTABLISHED 状态的TCP6连接,并且有若干TIME_WAIT的状态。

端口占用大概在5W6以上。
qatest@db-62:~$ netstat -an|wc -l
56179

而测试机端口数为:
qatest@db-62:~$ cat /proc/sys/net/ipv4/ip_local_port_range
8192 65535

可见,端口基本被用尽。

4. 问题解决

根据TCP/IP协议,连接断开之后,端口不会立刻被释放,而是处于TIME_WAIT状态,等待60s后(貌似/proc/sys/net/ipv4/tcp_fin_timeout配置),才会被释放掉,才能被新连接使用。
而性能测试并发了3W连接,每个连接关闭后,grinder又迅速创建新的连接,这时已关闭的连接所占用的端口实际是TIME_WIAT状态,未被释放,不能为新的连接所使用,当所有的端口号均被占用之后,新建连接因为无法分配到端口号而失败。

修改tpc/ip协议配置,通过配置TCP_TW_REUSE参数,来释放TIME_WAIT状态的端口号给新连接使用
/proc/sys/net/ipv4/tcp_tw_reuse
(boolean, default: 0)

Note: The tcp_tw_reuse setting is particularly useful in environments where numerous short connections are open and left in TIME_WAIT state, such as web servers. Reusing the sockets can be very effective in reducing server load.

同时修改   /proc/sys/net/ipv4/tcp_tw_recycle
(boolean, default: 0)

TCP_TW_RECYCLE
It enables fast recycling of TIME_WAIT sockets. The default value is 0 (disabled). The sysctl documentation incorrectly states the default as enabled. It can be changed to 1 (enabled) in many cases. Known to cause some issues with hoststated (load balancing and fail over) if enabled, should be used with caution.

参考资料:
http://www.speedguide.net/articles/linux-tweaking-121

设置参数后,重新测试,不再出现异常情况。

5. 长连接服务器的性能测试中, 修改以上两个参数可以解决问题。但是在并发短连接情况下,还不足以解决问题。比如短连接10ms的情况下,仍然会出现端口号用尽的情况,这个需要修改TIME_WAIT时间,需要进一步调研。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: