我有一個HAProxy + NodeJS + Rails安裝程序,我使用NodeJS服務器進行文件上傳。HAProxy + NodeJS卡住TCP重傳
我面臨的問題是,如果我通過haproxy上傳到nodejs,並且由於丟失數據包而發生「TCP(快速)重傳」,則客戶端上的TX速率會降至零,持續時間爲5-10秒並且被TCP重新傳輸充斥。
這不會發生,如果我直接上傳到NodeJS(TCP重傳發生了太多,但它不會卡住幾十次重發嘗試)。
我的測試設置是一個簡單的帶有單個文件輸入字段的HTML4 FORM(方法POST)。 NodeJS服務器只讀取傳入數據,不做其他事情。
我在多臺機器,網絡,瀏覽器上測試過這個問題,總是出現同樣的問題。
這裏從客戶端同時上載文件是一個TCP流量轉儲:
.....
TCP 1506 [TCP segment of a reassembled PDU]
>> everything is uploading fine until:
TCP 1506 [TCP Fast Retransmission] [TCP segment of a reassembled PDU]
TCP 66 [TCP Dup ACK 7392#1] 63265 > http [ACK] Seq=4844161 Ack=1 Win=524280 Len=0 TSval=657047088 TSecr=79373730
TCP 1506 [TCP Retransmission] [TCP segment of a reassembled PDU]
>> the last message is repeated about 50 times for >>5-10 secs<< (TX drops to 0 on client, RX drops to 0 on server)
TCP 1506 [TCP segment of a reassembled PDU]
>> upload continues until the next TCP Fast Retransmission and the same thing happens again
的haproxy.conf(HAProxy的v1.4.18穩定)如下:
global
log 127.0.0.1 local1 debug
maxconn 4096 # Total Max Connections. This is dependent on ulimit
nbproc 2
defaults
log global
mode http
option httplog
option tcplog
frontend http-in
bind *:80
timeout client 6000
acl is_websocket path_beg /node/
use_backend node_backend if is_websocket
default_backend app_backend
# Rails Server (via nginx+passenger)
backend app_backend
option httpclose
option forwardfor
timeout server 30000
timeout connect 4000
server app1 127.0.0.1:3000
# node.js
backend node_backend
reqrep ^([^\ ]*)\ /node/(.*) \1\ /\2
option httpclose
option forwardfor
timeout queue 5000
timeout server 6000
timeout connect 5000
server node1 127.0.0.1:3200 weight 1 maxconn 4096
感謝您的閱讀! :)
Simon