HAProxy + NodeJS卡住TCP重传

我有一个HAProxy + NodeJS + Rails安装程序,我使用NodeJS服务器进行file upload。

我面对的问题是,如果我通过haproxy上传到nodejs,并且由于丢失的数据包而发生“TCP(快速)重传”,客户端上的TX速率将下降到零,持续约5-10秒,并被淹没与TCP重传。

如果我直接上传到NodeJS,则不会发生这种情况(TCP重传也发生,但不会因为几十次重传而停滞)。

我的testing设置是一个简单的HTML4 FORM(方法POST),具有单个文件input字段。 NodeJS服务器只读取传入的数据,不做其他事情。

我已经在多台机器,networking,浏览器上testing过这个问题。

这是上传文件时客户端的TCPstream量转储:

..... 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 

谢谢阅读! 🙂

西蒙