tags:

views:

501

answers:

2

I have a simple C# application that uses UDP multicast in a single-receiver, single-sender scenario. The goal is to get message delivery as fast as possible in a local network environment.

I have used SocketAsyncEventArgs/SendAsync/ReceiveAsync, BeginSend/BeginReceive, Threads/Send/Receive, and have tried both PGM and UDP multicast.

Each implementation attempt works OK for repeated message delivery up to around 1000 messages with local send, local receive. After that, the performance starts to drop exponentially. Where 1000 messages take a few hundredths of a second, 10,000 messages might take anywhere from 2-10 seconds.

Does anyone have experience in high-performance UDP/PGM multicasting? What is the best design to get maximum throughput?

Update

Right now, it's just a single program running locally - 1 application with 1 sender and 1 receiver. The test messages are 4 bytes.

A: 

I'm no expert on this, but it sounds like your bumping up against the capacity of your network. You may need to upgrade your hardware to get better throughput. But without knowing the size of the packets, the network bandwidth, or how many machines are trying to communicate, etc., that's just a guess.

Jeffrey L Whitledge
+5  A: 

Try making your socket's send or receive buffer (server or client) large enough to accommodate the amount of traffic you expect to deal with. Here is some sample C# code from my own UDP multicast server/client on the server side where dataSock is my Socket bound to the UDP multicast group:

dataSock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, (NumberOfPackets * PacketSize) + SmallEpsilonForExtraHeadroom);

Also be sure and set SocketOptionName.SendBuffer on your client side to match the buffer size your server is producing.

I would also recommend, if you were not already aware, to make your packet sizes less than the MTU. By default, MTUs are set to 1500 bytes. (MTU is maximum transmission unit size)

You may still get dropped packets unless you also throttle your send rate, to make sure your clients can keep up. Your network hardware is most likely not the bottleneck here. See my question http://stackoverflow.com/questions/1631501/need-microsecond-delay-in-net-app-for-throttling-udp-multicast-transmission-rate for an answer to that problem (using Stopwatch in a while-loop for delays on the order of microseconds).

James Dunne
Thanks for the well-thought-out information.
Anton
No problem at all. I'm in the trenches with this stuff at the moment too. :)
James Dunne