How do I increase the UDP receive buffer size?

20,567

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.

Share:
20,567

Related videos on Youtube

Nate Lockwood
Author by

Nate Lockwood

I work at a US federal laboratory and participate in research using an aircraft with several imaging radiometers (research grade cameras with band pass filters and other modifications) so that we can acquire synchronized images - mostly infrared. Our main research thrust is studying wildfires. I'm in a project to upgrade our equipment, computer, and system. Since our contract engineer doesn't know C/C++ I've been teaching myself Java, HTML5, CSS3, and Dart attempting write software to provide a operator's GUI which controls the other computers and cameras on the aircraft LAN. I'm now concentrating on R to, agglomerate data and provide statistic analysis and plots of our data. My title is Ecologist.

Updated on September 18, 2022

Comments

  • Nate Lockwood
    Nate Lockwood almost 2 years

    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?

    • MrSnowMan
      MrSnowMan over 5 years
      Please eddit with UDP errors output from <code>netstat -su</code> this will show us how many UDP datagrams lost due to buffer overflow.
    • Nate Lockwood
      Nate Lockwood over 5 years
      I'll try netstat -su the next time it fails, thanks.
  • Nate Lockwood
    Nate Lockwood over 5 years
    Thanks, k500, i entered command in terminal - no change. Edited sysctl.conf, rebooted (JIC), rmem_max was not changed.
  • VoteCoffee
    VoteCoffee almost 4 years
    You need to do sudo with sysctrl
  • Nate Lockwood
    Nate Lockwood almost 4 years
    Thanks, VoteCoffee, If I ever get back to the office and that computer I'll give it a try!