3

I'm having some lags with my server running Ubuntu 10.04 on my UDP packets. What should I do to change the settings set for the UDP packets? I think the problem is there.

On my /proc/sys/net/ipv4/udp_mem I have 137088 182784 274176

udp_rmem_min: 4096
udp_wmem_min: 4096

/proc/sys/net/core/rmem_max  - 131071
/proc/sys/net/core/rmem_default  - 124928

/proc/sys/net/core/wmem_max  - 131071
/proc/sys/net/core/wmem_default  - 124928

I'm sending 30 packets every second from the client to the server and from the server to the client. They are all coming in a delay when there are a lot of users connected.

6
  • Can you be more precise about the problem? What are "some lags" exactly?
    – David Schwartz
    Sep 10, 2011 at 18:48
  • I'm sending 30 packets every second from the client to the server and from the server to the client. They are all coming in a delay when there are a lot of users connected.
    – Eli
    Sep 10, 2011 at 19:09
  • About how long is the delay? Are we talking microseconds or seconds? Is the CPU load high when you experience the delay or is it low? Sep 10, 2011 at 19:18
  • Hey I was unable to comment you so here is again the question: askubuntu.com/questions/60870/udp-tuning-ubuntu-how-to The delay is seconds. The CPU is using 150% I have 400%.
    – EiTkoCaT
    Sep 10, 2011 at 19:35
  • How many is "a lot" of users? And what kind of network connection do you have to them? How large are the packets? If the total throughput is starting to max out your bandwidth, that would certainly explain the long delays. 30 packets per second is an awful lot.
    – psusi
    Sep 10, 2011 at 21:42

1 Answer 1

1

Your problem is not related to UDP directly. The problem is that one of your cores is maxed and some application involved in your use of UDP cannot take advantage of more than one core. Your choices are to profile/optimize it to get it to do its job with the resources available or to redesign it to use multiple threads or multiple processes so that it can take advantage of the other cores.

Exactly how you do this depends on what's wrong with the code now. One possibility is if the code looks roughly like this:

while(1)
{
 do_udp_stuff(); // this is fairly simple
 do_other_stuff(); // this is complex
}

In this case, the solution is either to optimize the do_other_stuff or move it to a different thread.

Another possibility is if the code looks like this:

while(1)
{
 do_some_work_which_generates_a_UDP_Packet();
 send_udp_patch();
}
// or
while(1)
{
 receive_UDP_packet();
 process_UDP_packet();
}

In this case, the solution may be to have more than one thread doing the work that generates the UDP packet or processing the UDP packet.

Basically, you either have to reduce the amount of CPU you use per UDP packet or you need to increase your CPU utilization efficiency by distributing the work over the cores.

5
  • I'm using boost thread for each client I'm opening a thread which opens a TCP and UDP sockets. That's not good?
    – EiTkoCaT
    Sep 10, 2011 at 20:43
  • It depends on implementation details. For example, if you have a thread for each client, that means doing a little bit of work on each of 100 clients requires 100 context switches. But most likely your issue has to do with the processing you do in between calls to send/receive the UDP datagrams. Sep 10, 2011 at 23:22
  • So what would be the solution?
    – EiTkoCaT
    Sep 11, 2011 at 14:46
  • See the update to my answer. Basically, either make your code use less CPU or make it take advantage of the cores more effectively. Sep 12, 2011 at 0:53
  • Hey, Ok, I have done that. But still on the game server with people connected, I'm having the problem. Why? What should I do?
    – EiTkoCaT
    Sep 16, 2011 at 16:23

You must log in to answer this question.

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