M BUZZ CRAZE NEWS
// general

How do I increase the UDP receive buffer size?

By Sarah Rodriguez

I have a computer that communicates with a camera via UDP connected with a physical cable (no router or switch). The camera acts as the UDP server with the computer as client. Once in a while my Java APP hangs while an image is being transferred, line by line. My Java software waits for a line of the image that is never received and I believe this could be caused by receive buffer overflow.

I've tried to increase the receive buffer maximum size in /etc/sysctl.conf:

sysctl -w net.core.rmem_max 1000000

My program requests 7000000 bytes but at runtime reports that it received only 212992 bytes.

When I try to ask the OS the min, default, and maximum size:

$ sysctl -a | grep usb
net.ipv4.udp mem 185535 247780 371670

How do I get a larger buffer? Is sysctl even being read?

2

2 Answers

Type:

sysctl -w net.core.rmem_max=8388608

This sets the max OS receive buffer size for all types of connections.

from Linux Networking Documentation

Resolving Slow UDP Traffic

If your server does not seem to be able to receive UDP traffic as fast as it can receive TCP traffic, it could be because Linux, by default, does not set the network stack buffers as large as they need to be to support high UDP transfer rates. One way to alleviate this problem is to allow more memory to be used by the IP stack to store incoming data. For instance, use the commands:

sysctl -w net.core.rmem_max=262143

and:

sysctl -w net.core.rmem_default=262143

to increase the read buffer memory max and default to 262143 (256k - 1) from defaults of max=131071 (128k - 1) and default=65535 (64k - 1). These variables will increase the amount of memory used by the network stack for receives, and can be increased significantly more if necessary for your application.

1

The edit to /etc/sysctl.conf was in error, it should have read as below and I should have increased the default value as well:

net.core.rmem_max=1000000
net.core.rmem_default=1000000

I don't know why the below wouldn't work when I entered it by hand but I wanted the values to be set at boot anyway.

sysctl -w net.core.rmem 1000000
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy