Socket buffer 调优相关

http://www.man7.org/linux/man-pages/man7/tcp.7.html

 The maximum sizes for socket buffers declared via the SO_SNDBUF and
       SO_RCVBUF mechanisms are limited by the values in the
       /proc/sys/net/core/rmem_max and /proc/sys/net/core/wmem_max files
       tcp_rmem (since Linux 2.4)
              This is a vector of 3 integers: [min, default, max].  These
              parameters are used by TCP to regulate receive buffer sizes.
              TCP dynamically adjusts the size of the receive buffer from
              the defaults listed below, in the range of these values,
              depending on memory available in the system.
       tcp_wmem (since Linux 2.4)
              This is a vector of 3 integers: [min, default, max].  These
              parameters are used by TCP to regulate send buffer sizes.  TCP
              dynamically adjusts the size of the send buffer from the
              default values listed below, in the range of these values,
              depending on memory available.
简书 https://www.jianshu.com/p/755da54807cd
 
可靠性好不意味着不出错,可靠性好意味着容错能力强。
容错能力强就要求有 备份,也就是说要有缓存,这样的话才能支持重传等功能。
每个Socket都有自己的Send Buffer和Receive Buffer。
当进行send和recv操作时,立即返回,其实是将数据并没有发送出去,而是存放在对应的Send Buffer和Receive Buffer马上返回成功。
 
接收缓冲区:
接收缓冲区把数据存入内核,应用进程一直没有调用read进行读取的话,此数据会一直缓存在相应socket的接收缓冲区内。
read做的工作就是把内核缓冲区的数据拷贝到应用层用户的Buffer里面
接收缓冲区被tcp和udp用来缓存网络上来的数据,一直保存到应用进程读走为止
TCP: 如果应用一直没有读取,buffer满了之后,通知对端tcp协议中的窗口关闭(滑动窗口的实现)。保证tcp套接口接收缓冲区不会溢出(保证了TCP的可靠传输),因为对方不允许发出超过所通告窗口大小的数据(流量控制),如果对方无视窗口大小而发出了超过窗口大小的数据,则接收方tcp将丢弃。
UDP:当套接口接收缓冲区满时,新来的数据报无法进入接收缓冲区,此数据包被丢弃。udp没有流量控制,快的发送者可以很容易淹没慢的接受者,导致接收方的udp丢弃数据报。
 
发送缓冲区:
进程调用send发送数据的时候,将数据拷贝进入socket的内核发送缓冲区之中,然后send返回,返回之时数据不一定会发送到对端去,send仅仅是把应用层Buffer的数据拷贝进socket的内核发送Buffer中。每个upd都有一个接收缓冲区,没有发送缓冲区,只要有数据就发,不管对方是否可以正确接收,所以不缓冲,不需要发送缓冲区
 
 
原文地址:https://www.cnblogs.com/it-worker365/p/9389359.html