Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Huge UDP delay/lag with Android

I'm working on an Android application which sends/receives a high volume of UDP traffic to a Windows endpoint over a WLAN (and no, I can't use TCP).

The problem is that when I ramp up the traffic, I begin to see HUGE delays between when I call sendto (the app is written with the NDK) and when I see the packet arrive at the Windows endpoint. In the neighborhood of 10 seconds! The same thing happens in reverse too: I see huge delays between the packet being sent by the Windows endpoint and being picked up by recvfrom().

  • Changing SO_SNDBUF has no effect, so I don't think it's an issue with the application-level buffering control.
  • I've verified that the problem exists on a variety of Android devices, so I don't think it's an issue with the hardware/wireless drivers
  • Using a sniffer and correlating the timestamps, I confirmed that the delay is occurring between calling sendto() and the packet being sent from the Android device, so the buffering isn't happening in the AP or Windows endpoint

So at this point I'm all but out of ideas. The facts would lead me to believe that the buffering is happening on the Android OS layer, but 10 seconds of 10Mbps traffic? That seems too high to be feasible for an OS where memory footprint is such a huge concern.

Also, if the issue is that I'm sending data too fast and overwhelming the OS, then I would expect sendto() to return ENOMEM or ENOBUFS... But there are no indications that anything is wrong on the Android application level.

So my question is: what's causing this delay? And is there a way to mitigate it, or do I need to alter my application to have longer timeouts or some way of detecting this condition before it gets bad?

like image 590
Taylor Brandstetter Avatar asked Oct 28 '13 22:10

Taylor Brandstetter


1 Answers

You are sending too much.. how much are you sending? 10Mbps is definitely way too high. Bear in mind:

  1. Every UDP datagram you send has an additional 28 byte header (UDP + IP over IPv4)
  2. Connection link speeds are theoretical maximum limits that you will never be able to achieve
  3. The Phone OS could be limiting you, Phone OS's need to conserve battery and try to minimise socket comms to do so.

OR

You say your CPU is at 20%, how many cores do you have - you could be maxing out the core that is doing the sending, i.e. processing speed is the bottleneck.

like image 69
markmnl Avatar answered Sep 28 '22 13:09

markmnl