Linux 网卡性能优化设置

在高速网络传输中,每秒传输的数据量非常大。网络设备设置有一种缓存机制,即"缓存区",在 Linux 系统中,网卡缓冲分为两种类型:软件缓冲区和硬件缓冲区。

要提高网络吞吐率,首先当然是升级linux kernel。其次是设置linux系统参数和网卡驱动参数。

查看当前linux系统参数

$ cat /etc/sysctl.conf

vm.swappiness = 0

net.ipv4.neigh.default.gc_stale_time = 120

see details in https://help.aliyun.com/knowledge_detail/39428.html

net.ipv4.conf.all.rp_filter = 0

net.ipv4.conf.default.rp_filter = 0

net.ipv4.conf.default.arp_announce = 2

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.all.arp_announce = 2

see details in https://help.aliyun.com/knowledge_detail/41334.html

net.ipv4.tcp_max_tw_buckets = 5000

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_max_syn_backlog = 1024

net.ipv4.tcp_synack_retries = 2

net.ipv6.conf.all.disable_ipv6 = 1

net.ipv6.conf.default.disable_ipv6 = 1

net.ipv6.conf.lo.disable_ipv6 = 1

kernel.sysrq = 1

可以设置为下面这一组优化后的系统参数:

sysctl -w net.ipv4.tcp_tw_reuse=1

sysctl -w net.ipv4.tcp_tw_recycle=1

sysctl -w net.ipv4.tcp_fin_timeout=30

sysctl -w net.ipv4.tcp_keepalive_time=600

sysctl -w net.ipv4.tcp_max_syn_backlog=8192

sysctl -w net.ipv4.tcp_max_tw_buckets=5000

sysctl -w net.ipv4.ip_local_port_range='1024 65000'

sysctl -w net.ipv4.tcp_rmem='4096 436600 873200'

sysctl -w net.ipv6.conf.all.disable_ipv6=1

sysctl -w net.ipv6.conf.default.disable_ipv6=1

sysctl -w net.ipv4.tcp_synack_retries=2

sysctl -w net.ipv4.tcp_syn_retries=2

sysctl -w net.core.wmem_max=16777216

sysctl -w net.core.wmem_default=16777216

sysctl -w net.core.rmem_max=16777216

sysctl -w net.core.rmem_default=16777216

$ sysctl -p

网卡驱动一般情况下不允许设置,但可以查询设置情况和统计信息以定位问题。

如果可能,应该升级linux kernel和net driver(ko)以便获得更好的网络性能。

下面是一台典型centos7 VPS的网卡信息,驱动较为简单。

root@iZj6c591g5r6irirqvcj5gZ ~/$ ethtool -i eth0

driver: virtio_net

version: 1.0.0

firmware-version:

expansion-rom-version:

bus-info: 0000:00:03.0

supports-statistics: no

supports-test: no

supports-eeprom-access: no

supports-register-dump: no

supports-priv-flags: no

root@iZj6c591g5r6irirqvcj5gZ ~/$ ethtool -g eth0

Ring parameters for eth0:

Pre-set maximums:

RX: 4096

RX Mini: 0

RX Jumbo: 0

TX: 4096

Current hardware settings:

RX: 4096

RX Mini: 0

RX Jumbo: 0

TX: 4096

root@iZj6c591g5r6irirqvcj5gZ ~/$ ethtool -l eth0

Channel parameters for eth0:

Pre-set maximums:

RX: 0

TX: 0

Other: 0

Combined: 4

Current hardware settings:

RX: 0

TX: 0

Other: 0

Combined: 4

下面的设置全部失败。

root@iZj6c591g5r6irirqvcj5gZ ~/ $

$ ethtool -L eth0 tx 8 rx 8 other 8 combined 8

$ ethtool -G eth0 rx 8192 tx 8192

$ ethtool -C eth0 adaptive-tx off

相关推荐
_考不上研究生不改名1 小时前
【完美解决】VSCode连接HPC节点,已配置密钥却还是提示需要输入密码
linux·服务器·vscode·远程连接·hpc·超算集群
_长银1 小时前
Vim搜索和替换
linux·编辑器·vim
爱的叹息3 小时前
Spring Boot 自定义配置类(包含字符串、数字、布尔、小数、集合、映射、嵌套对象)实现步骤及示例
java·linux·spring boot
嵌入式-老费3 小时前
Linux上位机开发实践(一个硬件算法加速的示例)
linux·运维·服务器
前进的程序员3 小时前
Linux C 与 C 语言的区别及开发差异
linux·运维·c语言
CZIDC4 小时前
华为昇腾服务器上查看固件、驱动和CANN版本的常用方法
linux·运维·服务器
良许Linux5 小时前
C++在嵌入式中表现如何?
linux
林政硕(Cohen0415)5 小时前
Linux驱动开发进阶(七)- DRM驱动程序设计
linux·驱动开发·drm
良许Linux5 小时前
能详细地讲讲stm32该怎么学吗?
linux
菜鸟起航ing5 小时前
【Java面试系列】Spring Boot微服务架构下的分布式事务解决方案与性能优化详解 - 3-5年Java开发必备知识
java·spring boot·微服务·性能优化·分布式事务