How do I increase the UDP receive buffer size?
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 1000000My 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 371670How do I get a larger buffer?
Is sysctl even being read?
2 Answers
Type:
sysctl -w net.core.rmem_max=8388608This sets the max OS receive buffer size for all types of connections.
from Linux Networking Documentation
1Resolving 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=262143and:
sysctl -w net.core.rmem_default=262143to 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.
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=1000000I 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 More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"