单机单网卡最大 tcp 长连接数是 65535 吗

在Linux里,如果是作为客户端或者负载均衡器的节点连接多个服务器,在connect()服务器之前,
调用bind()先绑定IP地址(通常是在多网卡的场景),即使使用bind(IP, port=0),
Kernel也会帮你选定一个端口。这样就会出现只能使用~65k的连接。

直到Kernel 4.2版本,一个新的socket option IP_BIND_ADDRESS_NO_PORT的引入,这个问题才算解决。
IP_BIND_ADDRESS_NO_PORT (since Linux 4.2)     

Inform the kernel to not reserve an ephemeral port when

usingbind(2) with a port number of 0. The port will later be auto‐ matically

chosen at connect(2) time, in a way that allows

sharing a source port as long as the 4-tuple is unique.

1.7版的haproxy开启了IP_BIND_ADDRESS_NO_PORT支持 ,即可以复用source port,这样可以从更基础的内核层面解决这个问题,唯一不足是需要将内核升级到4.2以上版本才可以。

特殊网络设备

/dev/net/tun

参考:
http://www.haproxy.org/download/1.7/src/CHANGELOG
https://kernelnewbies.org/Linux_4.2#head-8ccffc90738ffcb0c20caa96bae6799694b8ba3a
http://blog.sina.com.cn/s/blog_704836f40101jv9h.html

关于 TCP 并发连接的几个思考题与试验



猜你喜欢

转载自www.cnblogs.com/yuyutianxia/p/10274361.html