3

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
  • Please eddit with UDP errors output from <code>netstat -su</code> this will show us how many UDP datagrams lost due to buffer overflow.
    – MrSnowMan
    Feb 4, 2019 at 20:36
  • I'll try netstat -su the next time it fails, thanks. Feb 5, 2019 at 17:09

2 Answers 2

3

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
  • Thanks, k500, i entered command in terminal - no change. Edited sysctl.conf, rebooted (JIC), rmem_max was not changed. Feb 5, 2019 at 17:44
0

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
  • You need to do sudo with sysctrl
    – VoteCoffee
    Sep 24, 2020 at 17:43
  • Thanks, VoteCoffee, If I ever get back to the office and that computer I'll give it a try! Sep 25, 2020 at 18:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .