zoukankan      html  css  js  c++  java
  • the socket buffer size of linux


    # Most versions of UNIX have a very low default buffer limit, which should be increased to at least 2MB. Also, note that UDP recommendations are only applicable for configurations which explicitly configure UDP in favor of TCP as TCP is the default for performance sensitive tasks.

    # for read
    cat /proc/sys/net/ipv4/tcp_rmem
    # for write
    cat /proc/sys/net/ipv4/tcp_wmem

    sysctl net.ipv4.tcp_rmem
    sysctl net.ipv4.tcp_wmem

    sysctl -w net.core.rmem_max=2097152
    sysctl -w net.core.wmem_max=2097152


    # However, the default socket buffers are just set when the sock is initialised but the kernel then dynamically sizes them (unless set using setsockopt() with SO_SNDBUF). The actual size of the buffers for currently open sockets may be inspected using the ss command (part of the iproute package), which can also provide a bunch more info on sockets like congestion control parameter etc. E.g. To list the currently open TCP (t option) sockets and associated memory (m) information:

    ss -m --info
    ss -tm

    State       Recv-Q Send-Q        Local Address:Port        Peer Address:Port
    ESTAB       0      0             192.168.56.102:ssh        192.168.56.1:56328
    skmem:(r0,rb369280,t0,tb87040,f0,w0,o0,bl0,d0)

    # Here's a brief explanation of skmem (socket memory) - for more info you'll need to look at the kernel sources (e.g. sock.h):
    r:sk_rmem_alloc
    rb:sk_rcvbuf          # current receive buffer size
    t:sk_wmem_alloc
    tb:sk_sndbuf          # current transmit buffer size
    f:sk_forward_alloc
    w:sk_wmem_queued      # persistent transmit queue size
    o:sk_omem_alloc
    bl:sk_backlog
    d:sk_drops

    # There is also /proc/sys/net/core/rmem_default for recv and /proc/sys/net/core/wmem_default for send
    cat /proc/sys/net/core/rmem_default
    cat /proc/sys/net/core/wmem_default

    #!/bin/bash
    #
    # aggregate size limitations for all connections, measured in pages; these values
    # are for 4KB pages (getconf PAGESIZE)
    
    /sbin/sysctl -w net.ipv4.tcp_mem='   65536   131072   262144'
    
    # limit on receive space bytes per-connection; overridable by SO_RCVBUF; still
    # goverened by core.rmem_max
    
    /sbin/sysctl -w net.ipv4.tcp_rmem=' 262144  4194304  8388608'
    
    # limit on send space bytes per-connection; overridable by SO_SNDBUF; still
    # goverered by core.wmem_max
    
    /sbin/sysctl -w net.ipv4.tcp_wmem='  65536  1048576  2097152'
    
    # absolute limit on socket receive space bytes per-connection; cannot be
    # overriden programatically
    
    /sbin/sysctl -w net.core.rmem_max=16777216
    
    # absolute limit on socket send space bytes per-connection; cannot be overriden;
    # cannot be overriden programatically
    
    /sbin/sysctl -w net.core.wmem_max=16777216
    
  • 相关阅读:
    第6章 LVM详解
    第5章 Linux上管理文件系统
    第4章 ext文件系统机制原理剖析
    第3章 Linux上文件的权限管理
    第2章 系统用户/组管理(2) su和sudo
    第2章 细说Linux系统用户/组管理(1)
    cpio用法详细说明
    Linux find运行机制详解
    第1章 Linux文件类基础命令
    PXE+kickstart无人值守安装CentOS 6
  • 原文地址:https://www.cnblogs.com/ztguang/p/14479342.html
Copyright © 2011-2022 走看看