Re: Unicast UDP Server



On Sat, 29 Mar 2008 15:18:19 -0700, O.B. <funkjunk@xxxxxxxxxxxxx> wrote:

Wow, this is great. All this time I have been confusing bind and connect. Thank you for the detailed explanation.

You're welcome.

For the record, I still have to bind to a _local_ IP address for UDP sockets in order for the receive data callback to be invoked. From what I gathered from your post, invoking "connect" with a remote address in a UDP socket will ensure that the receive callback is only invoked with data received from the specified remote address, correct?

It should, yes.

[...]
The code has been rewritten using unmanaged code to get a significant speed up over the original C++ implementation. Without the 75 MB receive buffer, we _occasionally_ find the buffer overfilling.

I don't understand the above comment. If you're using unmanaged code, why are you posting in the C# newsgroup? C# is dependent on the .NET runtime, and so is inherently tied to managed code. If the original implementation was C++, is the above statement meant to imply that you were using managed C++?

In running a profiler, it appears the code is processing the data as fast as the OS is invoking the asynchronous callback. As a test, I wrote a receive callback that only sucked data off the socket and put it into an internal buffer for processing. We were still encountering an overflow ... very odd.

How do you know you are encountering an overflow? Are you sure that you aren't losing datagrams due to some other reason?

Maybe it is the actual NIC we're using? Or is it a limitation of Windows XP and Windows 2003 Server? This is a tough one to figure out.

The "U" in "UDP" might as well stand for "unreliable". UDP is inherently unreliable, and you _will_ lose datagrams eventually, no matter what you do.

On a LAN, you can avoid many of the problems that exist going over the Internet, but your code still must always be able to deal with lost datagrams. Data loss will be reduced significantly on a LAN as compared to the Internet, but it will never go away completely.

You haven't made any mention as to what your actual network speed and load is, but I'll reiterate my previous statement: only on the fastest networks, under the highest loads, should a buffer of 75MB be useful. Even at that size, that's on the order of 500 ms worth of constant data throughput on a 1 gigabit network. Or put another way, if a 75MB buffer is needed, that means that the layer of network transport that's supposed to be reading from that buffer is at times being delayed by longer than 500 ms.

On a modern computer, that's practically forever. In my opinion, you should never be seeing delays that long. If you are seeing delays that long, there's probably a better way to deal with them. Such as, preventing the delays rather than allowing them to happen and just letting the data pile up in a larger buffer.

As an example of that 500 ms really means: you'd have to be running roughly ten fully CPU-bound threads on a single-core/CPU computer in order for some other thread's execution to be delayed by that much time. And of course, running ten fully CPU-bound threads on a single-core computer is definitely not a good idea (heck, running just two fully CPU-bound threads on a single-core computer isn't a good idea).

If you're running on a more conventional network (e.g. 100 Mb/s...though I admit, 1 Gb/s is getting more and more common, I think 100 Mb/s is still more typical), and/or your data transmission rate does not saturate the network, then a 75MB buffer implies an even larger delay (for a 100 Mb/s, it's more like 5 seconds than 500 ms). And if a half-second delay is a sign of something wrong, you can imagine that an even larger delay means. :)

Pete
.



Relevant Pages

  • Re: Xbox Extender giving network congestion errors
    ... Given the behavioral change you saw with changing your network setup, ... Regarding slow mo playback - next time you see video enter this mode, ... this doesn't sound like buffer depletion; what I would expect you to ... It corrects itself in a really ...
    (microsoft.public.windows.mediacenter)
  • Re: server scenario - variables in the right spot?
    ... If I'm correct in what I think you mean by 'data structures' then I also ... steps, the command has, and a way to mark which steps are done or not done, ... Assuming you are using the same receive callback for each BeginReceive, ... that processes the data for the first buffer. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TCPBEUI misbehaving
    ... >> I try to analyse problems on my network. ... The wrkheuristics parameter sets a variety of requester fine-tuning ... 9 buffer small read and write requests until the buffer is full ... 27 force correct open mode when creating files on a core server (reserved ...
    (comp.os.os2.setup.misc)
  • Re: WMS source changing issue
    ... we use 5 second buffer in WMP. ... The question is - why the server is stopping broadcasting for a while (it ... clearly seen in network statistic in Task Manager) when switching to file ... We're streaming one 5Mbps live stream and one 5Mbps CBR file periodically so ...
    (microsoft.public.windowsmedia.server)
  • Re: 8Signs PC Firewall Problem
    ... > First a little understanding of my network setup... ... > If I turn 8 Signs PC Firewall Off, ... > the packets in realtime. ... > I was wondering if it's buffer problem, as in the buffer on the lan ...
    (comp.security.firewalls)