我有一个带有Erlang应用程序的Linux服务器,它显示了一个奇怪的限制,即只有65536个最大的tcp传入连接。
Erlang应用程序是用牛仔框架编写的。
我以这种方式调优了内核参数:
/etc/sysctl.conf:
# Increase system file descriptor limit
fs.file-max = 300000
# Discourage Linux from swapping idle processes to disk (default = 60)
vm.swappiness = 10
# Increase Linux autotuning TCP buffer limits
# Set max to 16MB for 1GE and 32M (33554432) or 54M (56623104) for 10GE
# Don't set tcp_mem itself! Let the kernel scale it based on RAM.
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.rmem_default = 16777216
net.core.wmem_default = 16777216
net.core.optmem_max = 40960
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
# Make room for more TIME_WAIT sockets due to more clients,
# and allow them to be reused if we run out of sockets
# Also increase the max packet backlog
net.core.netdev_max_backlog = 50000
net.ipv4.tcp_max_syn_backlog = 30000
net.ipv4.tcp_max_tw_buckets = 2000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 10
# Disable TCP slow start on idle connections
net.ipv4.tcp_slow_start_after_idle = 0
# Disable source routing and redirects
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
# Log packets with impossible addresses for security
net.ipv4.conf.all.log_martians = 1/etc/安全/有限公司:
* soft nofile 300000
* hard nofile 300000我还检查了Erlang进程的最大数量,但这似乎不是限制因素:
1> erlang:system_info(process_limit).
262144测试连接由来自4个不同IP地址的4台客户端计算机进行(因此这不是客户端限制的问题),在进行初始身份验证后,连接被闲置,因此服务器CPU利用率低于50%,内存利用率也低于35%。
编辑:我不确定这是否重要: Erlang服务器应用程序正在监听端口8000,我让它也可以在端口80上监听,使用这个iptables规则:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000为了消除65536连接限制,我还应该考虑其他什么?
发布于 2015-09-30 10:11:08
在查看dmesg输出之后,我发现了这个问题:
nf_conntrack: table full, dropping packet因此,问题是在TCP重定向80 => 8000使用iptables。
我删除了iptables规则,并让Erlang直接监听端口80和8000,并取消了65k限制。
发布于 2015-09-22 15:53:01
检查如何编码您的应用程序。有一个65535端口的限制,在这个范围内的那些: 0-1024是保留的.
如果您的应用程序使用临时端口;来自RFC-6056
2.1。传统的临时端口范围因特网分配数字管理局( IANA )分配Internet工程任务组(IETF)开发的协议中使用的唯一Internet参数和值,包括著名的端口IANA. IANA,保留了对TCP和UDP 16位端口范围的下列使用:O是著名的端口,0到1023。注册端口,1024到49151 o动态端口和/或专用端口,49152到65535 IANA定义的动态端口范围由49152-65535范围组成,用于选择临时端口。
在最后一步中,询问供应商是否是硬编码的值。( int_16)
发布于 2015-09-22 16:09:17
如果您的4个不同客户端从同一台主机连接到服务器,则不能同时拥有超过65536个活动传入连接,因为您只能为相同的传入IP地址生成65536个端口。
https://serverfault.com/questions/724048
复制相似问题