一、網卡調優
1、開啟網卡中斷分離
sudo echo "options ixgbe rss=0,0" >> /etc/modprobe.d/ixgbe.conf
sudo echo "options ixgbevf rss=0,0" >> /etc/modprobe.d/ixgbevf.conf
2、開啟接收端零拷貝(RX Zero Copy)
sudo ethtool -K eth0 rx off
sudo ethtool --offload eth0 rx off tx off
sudo ethtool -K eth0 gso off
sudo ethtool -K eth0 gro off
3、關閉TCP 的延遲確認
sudo sysctl -w net.ipv4.tcp_sack=1
sudo sysctl -w net.ipv4.tcp_timestamps=1
sudo sysctl -w net.ipv4.tcp_window_scaling=1
sudo sysctl -w net.ipv4.tcp_no_metrics_save=1
sudo sysctl -w net.core.netdev_max_backlog=3000000
二、內核參數優化
1、增加可用端口(Ipeen Ports)
sudo sysctl -w net.ipv4.ip_local_port_range="10000 64000"
2、減少重試超時(Retries Timeouts)
sudo sysctl -w net.ipv4.tcp_retries2=5
sudo sysctl -w net.ipv4.tcp_syn_retries=3
sudo sysctl -w net.ipv4.tcp_synack_retries=3
3、增加文件描述符上限
sudo ulimit -n 65535
sudo echo "* - nofile 65535" >> /etc/security/limits.conf
三、TCP協議棧優化
1、增加TCP 最大接收窗口(TCP Max Window Size)
sudo sysctl -w net.core.rmem_max=26214400
sudo sysctl -w net.core.rmem_default=26214400
sudo sysctl -w net.core.wmem_max=26214400
sudo sysctl -w net.core.wmem_default=26214400
sudo sysctl -w net.ipv4.tcp_rmem='4096 87380 26214400'
sudo sysctl -w net.ipv4.tcp_wmem='4096 65536 26214400'
2、啟用BBR擁塞控制算法(Bottleneck Bandwidth and Round-trip propagation time)
sudo modprobe tcp_bbr
sudo echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
sudo echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
3、增加TCP 連接隊列長度(TCP Connection Queue)
sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65535
sudo sysctl -w net.ipv4.tcp_max_tw_buckets=2000000
以上是一些提高Linux網絡性能的有效方法的代碼示例。除此之外,常見的網絡性能優化還包括優化接口的緩存區、使用TCP/IP協議棧超時時間、優化MTU以及增加物理內存等。在實際應用中,需要根據不同的環境和需求來進行網絡性能的優化。
原創文章,作者:SYWL,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/142600.html