「Linux问题」配置network stack( buffer size)

  1. 我的服务器默认网络堆栈配置如下:

    # default maximum Linux TCP buffer sizes is calculated automatically based on system memory
    $ cat /proc/sys/net/ipv4/tcp_mem
    22755	30340	45510
    
    $ sysctl net.ipv4.tcp_rmem
    net.ipv4.tcp_rmem = 4096	87380	6291456
    
    $ sysctl net.ipv4.tcp_wmem
    net.ipv4.tcp_wmem = 4096	16384	4194304
    
    # The default and maximum amount for the receive socket memory
    $ cat /proc/sys/net/core/rmem_default
    212992
    $ cat /proc/sys/net/core/rmem_max
    212992
    
    # The default and maximum amount for the send socket memory
    $ cat /proc/sys/net/core/wmem_default
    212992
    $ cat /proc/sys/net/core/wmem_max
    212992
    
    # The maximum amount of option memory buffers
    $ cat /proc/sys/net/core/optmem_max
    20480
    
    # there is a feature for auto tuning, which dynamically adjusts the TCP buffer size till the maximum value is attained. This feature is turned on by default and I recommend that it be left turned on. 
    $ cat /proc/sys/net/ipv4/tcp_moderate_rcvbuf
    1
    
    # Before processing the data by the TCP/UDP layer, your system puts the data in the kernel queue. The net.core.netdev_max_backlog value specifies the maximum number of packets to put in the queue before delivery to the upper layer. 
    $ sysctl net.core.netdev_max_backlog
    net.core.netdev_max_backlog = 1000
    
    # MTU size
    $ ip addr
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
    
  2. 提高网卡MTU大小

    ifconfig eth0 mtu 9000
    
  3. 增大kernel socket buffer大小:

    # 暂时
    sysctl  -w net.core.wmem_default=262144
    sysctl -w net.core.wmem_max=4194304
    sysctl -w net.core.rmem_default=262144
    sysctl -w net.core.rmem_max=4194304
    # 永久
    echo 'net.core.wmem_default=262144' >> /etc/sysctl.conf
    echo 'net.core.wmem_max=4194304' >> /etc/sysctl.conf
    echo 'net.core.rmem_default=262144' >> /etc/sysctl.conf
    echo 'net.core.rmem_max=4194304' >> /etc/sysctl.conf
    sysctl -p
    
  4. TCP/UDP处理

    # 暂时
    sysctl -w net.ipv4.tcp_rmem=" 4096	87380	12582912"
    sysctl -w net.ipv4.tcp_wmem=" 4096	16384	6291456"
    # 永久:
    echo 'net.ipv4.tcp_rmem=4096	87380	12582912' >> /etc/sysctl.conf
    echo 'net.ipv4.tcp_wmem=4096	16384	6291456' >> /etc/sysctl.conf
    sysctl -p
    

Reference

  1. Network Performance Monitoring And Tuning In Linux
  2. Linux Tune Network Stack (Buffers Size) To Increase Networking Performance
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值