一次壓力測試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. -
設置參數后,重新測試,不再出現異常情況。
5. 長連接服務器的性能測試中, 修改以上兩個參數可以解決問題。但是在並發短連接情況下,還不足以解決問題。比如短連接10ms的情況下,仍然會出現端口號用盡的情況,這個需要修改TIME_WAIT時間,需要進一步調研。
