1. Modify the buffer size of a single socket: Use setsockopt to use so_rcvbuf to set the receiving buffer. This parameter will not be compared and verified with rmem_max when set, but if the set size exceeds rmem_max, the part exceeding rmem_max does not take effect;
2. Modify the UDP buffer size in Linux: Use rmem_max to set the upper limit of UDP cache in the system. The value can be viewed as follows:
[Email protected]:/mnt/HGFS/Vm-shared/socket # Cat/proc/sys/NET/CORE/rmem_max
131071
The modification is made as follows:
[Email protected]:/mnt/HGFS/Vm-shared/socket # vi/etc/sysctl. conf
Add the following information to the/etc/sysctl. conf file:
Rmem_max = max
Note that the rmem_max parameter set here is the size of the entire system, not the size of a single socket.
You can run the following command to view the modified size:
[Email protected]:/mnt/HGFS/Vm-shared/socket # sysctl-A | grep rmem_max
Net. Core. rmem_max = 131071
Summary
To modify the buffer size of Linux UDP packets, You need to modify both of the preceding two places at the same time.
The buffer size is limited by rmem_max.
Only change to 2nd points. A socket reserves only 63 message receiving buffers.
The sending buffer is the same as the receiving buffer, but the parameter names are different: so_sndbuf and wmem_max.
Run the following command to view the number of existing packets in the corresponding buffer zone:
[Email protected]:/mnt/HGFS/Vm-shared/socket # netstat-Na | more
Active Internet connections (servers and established)
PROTO Recv-Q send-Q local address foreign address State
TCP 0 0 0.0.0.0: 111 0.0.0.0: * listen
TCP 0 0 0.0.0.0: 22 0.0.0.0: * listen
TCP 0 0 0.0.0.0: 23 0.0.0.0: * listen
TCP 0 0 127.0.0.1: 631 0.0.0.0: * listen
TCP 0 0 0.0.0.0: 53113 0.0.0.0: * listen
TCP 0 0 0.0.0.0: 35551 0.0.0.0: * listen
TCP 0 0 0.0.0.0: 2049 0.0.0.0: * listen
TCP 0 0 0.0.0.0: 42697 0.0.0.0: * listen
TCP 0 52 192.168.16.55: 22 192.168.16.48: 57258 established
Tcp6 0 0: 22: * listen
Tcp6 0 0: 1: 631: * listen
Tcp6 0 0: 445: * listen
Tcp6 0 0: 139: * listen
UDP 0 0 0.0.0.0: 58548 0.0.0.0 :*
UDP 0 0 0.0.0.0: 68 0.0.0.0 :*
UDP 0 0 0.0.0.0: 52684 0.0.0.0 :*
UDP 0 0 0.0.0.0: 57298 0.0.0.0 :*
UDP 0 0 0.0.0.0: 5353 0.0.0.0 :*
UDP 0 0 0.0.0.0: 54889 0.0.0.0 :*
UDP 0 0 0.0.0.0: 111 0.0.0.0 :*
UDP 0 0 0.0.0.0: 2049 0.0.0.0 :*
UDP 260464 0 0.0.0.0: 2435 0.0.0.0 :*
In this example, 2435 = 260464/1784 packets are cached in the socket with the port number 146.
TCP/UDP Cache