我有一个 HAProxy + NodeJS + Rails 设置,我使用 NodeJS 服务器进行文件上传。
我面临的问题是,如果我通过 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 stable)如下:
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
谢谢阅读!:)
西蒙