本文共 1818 字,大约阅读时间需要 6 分钟。
@Date 2018.12.09
# 调大接收窗口缓存大小net.ipv4.tcp_rmem = "40960 873800 41943040"net.core.rmem_max = 41943040net.core.rmem_default = 873800# 打开win scalenet.ipv4.tcp_window_scaling = 1
# 优化拥塞窗口的初始大小
# 调整TIME_WAIT的回收时间$ vi /etc/sysctl.confnet.ipv4.tcp_syncookies = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_fin_timeout = 30net.core.somaxconn = 2048net.core.rmem_default = 262144net.core.wmem_default = 262144net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.somaxconn = 10000net.core.netdev_max_backlog = 20000net.ipv4.tcp_rmem = 7168 11264 16777216net.ipv4.tcp_wmem = 7168 11264 16777216net.ipv4.tcp_mem = 786432 2097152 3145728net.ipv4.tcp_max_syn_backlog = 16384net.ipv4.tcp_fin_timeout = 15net.ipv4.tcp_max_syn_backlog = 16384net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_max_orphans = 131072net.ipv4.tcp_max_tw_buckets=180000fs.file-max = 1000000
# 查看是否数量很多,代码不同不同请求连接过多,Syn队列溢出,丢弃连接$ netstat -anp | grep SYN_RECV/TIME_WAIT
# 前面数字一直快速增长,客户端大量请求,造成accept队列满,之后来syn包也会丢弃# 服务端接收到syn后,先看syn队列,再看accept队列,有一个满则丢弃syn$ netstat -s | grep -i listen
# 四元组:源ip、目的ip、源port、目的port# 一个客户端连接一个server只能使用固定端口范围# TIME_WAIT状态的socket不能复用
# 调动端口使用范围$ --net.ipv4.ip_local_port_range="1024 65535"# 复用time_out状态端口$ --net.ipv4.tcp_tw_reuse=1$ net.ipv4.tcp_timestamp =1# 加快TIME_OUT状态端口释放速度$ net.ipv4.tcp_tw_recyle=1$ net.ipv4.tcp_timestamp=1
# 用户程序没有调用close函数,不会自动释放--程序异常$ netsata -anp | grep CLOSE_WAIT
转载地址:http://efgjx.baihongyu.com/