How Do I Adjust the Socket Buffer Size of the Linux OS
Question
Applications invoke the socket system to communicate with remote servers. Each socket has a read/write buffer. The read buffer saves data sent from remote servers. If the buffer is full, data will be discarded. The write buffer saves the data to be sent to remote servers. If the write buffer is full, system applications cannot write data to the buffer. For a large-scale Linux, you must adjust the buffer size. Otherwise, the overall performance during application operation will be affected. How do I adjust the size?
Answer
- Log in to the Linux OS as the root user.
- Modify the configuration file to modify the kernel parameters of Linux.
- Switch to the /etc directory.
# cd /etc
/ is the root directory of Linux.
- You are advised to back up the configuration file sysctl.conf before modifying it. If the backup file name is sysctl.conf_bak, run the following command to back up the file:
# cp sysctl.conf sysctl.conf_bak
- Open the sysctl.conf file in text mode.
# vi sysctl.conf
- Modify or add (if it does not exist) the content as follows in the sysctl.conf file:
net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.wmem_max = 20971520 net.core.rmem_max = 8388608 net.ipv4.tcp_mem = 1162629 1550174 2325258 net.ipv4.tcp_wmem = 4096 16384 4194304 net.ipv4.tcp_rmem = 4096 87380 6291456
- Run the following command for the parameters to take effect:
# /sbin/sysctl -p
- Switch to the /etc directory.