一. 優化
1. TPC接收窗口
- 問題 : 當TCP的接收窗口隊列阻塞 -> 發送方繼續發 -> 接受方丟掉 -> 發送方重傳 -> 網絡變糟糕
- 解決 : 接收方把接收緩存的大小告訴發送方 -> 接收緩存滿了 -> 發送方不能發送
net.ipv4.tcp_rmem = "40960 873800 41943040"
net.core.rmem_max = 41943040
net.core.rmem_default = 873800
net.ipv4.tcp_window_scaling = 1
2. TCP擁塞窗口
3. TIME_WAIT狀態的回收
$ vi /etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.core.somaxconn = 2048
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.somaxconn = 10000
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_rmem = 7168 11264 16777216
net.ipv4.tcp_wmem = 7168 11264 16777216
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_max_tw_buckets=180000
fs.file-max = 1000000
二. 問題
1. 連接超時
$ netstat -anp | grep SYN_RECV/TIME_WAIT
- 解決 : 更改配置文件數量,打開syncookie
$ netstat -s | grep -i listen
- 解決 : 增加accept隊列長度--配置文件, net.core.somaxconn=8192. 計算公式:Len of accept queue = min(backlog + 1,somaxconn)
$ --net.ipv4.ip_local_port_range="1024 65535"
$ --net.ipv4.tcp_tw_reuse=1
$ net.ipv4.tcp_timestamp =1
$ net.ipv4.tcp_tw_recyle=1
$ net.ipv4.tcp_timestamp=1
2. too many open files
$ netsata -anp | grep CLOSE_WAIT