Pages

Saturday 9 November 2013

Socket Buffer Size

In network programming, we usually set the a buffer size to the sockets using the SO_RCVBUF and SO_SNDBUF socket options. In the code, we use the setsockopt function as follows:

int sockfd;                                     /* Socket descriptor */
int SockInBuffSize = 1024 * 512;  /* Size of the input socket buffer here 262144 bytes*/

setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &SockInBuffSize, sizeof(SockInBuffSize));

For the above code to work, we need to make sure that the OS will allow us to set larger socket buffer sizes. We can achieve this using sysctl command as follows:

#sysctl -w net.core.rmem_max=524288 
#sysctl -w net.core.wmem_max=524288 
#sysctl -w net.core.wmem_default=524288 
#sysctl -w net.core.rmem_default=524288

Where rmem is the receive buffer and wmem the send buffer.

Failing to do the above, results in the socket buffer sizes that cannot be greater than the max values defined in /proc/net/core/

To view the current values of socket buffer sizes use the following command:

#sysctl -a | grep net.core


References

Working with NIC Ring Buffers
This post explains how to modify the NIC ring buffers which are important in fine tuning your network performance.
Source: www.scottalanmiller.com

Resolving Common Queuing/Frame Loss Issues
This chapter of Linux RedHat document explains how to use ethtool to fine tune your NIC for better network performance.
Source: redhat.com

No comments:

Post a Comment