none
Socket.SendAsync() painfully slow on when called frequently RRS feed

  • Question

  • I am having a serious issue with Socket.SendAsync() method. I built a server on top of Sample Code from MSDN Documentation for SocketAsyncEventArgs. I changed it from Echo server to a server that broadcasts messages to all connected clients.

    The messages are coming sizes as big as 1500 bytes and about 100 messages per second.

    First I tried calling SendAsync() on every client with no synchronized wait and I ended up having thousands of calls that are waiting to be "Completed" per client.

    Then I limited 1 call per connection and not call another SendAsync() until Completed event is raised for the pending call. This way, I ended up with severe starvation of connected clients.

    Then I tried limiting "uncomplete" SendAsync() calls per socket to a certain number, I have tried max 50 waiting, and I still have starvation. In fact with this approach, I also discovered that there comes a time when all 50 waiting never get "Completed" event raised ever.

    I searched internet for this issue, a few guys have posted a question on StackOverflow but never got answered.

    Can somebody please point me into the right direction ?

    Thanks


    Fahad

    Monday, April 29, 2013 5:36 PM

Answers

  • first, don't assume posted sample code actually works.  The sample code was meant to demonstate the syntax of the methods.  The webpage page you reference is for TCP.  TCP you can only have one client and one server for each connection.  If you broadcast, you are probably sending the same message on each one of the esablished connections and not trying to to more than one computer on the same connection.

    I would first use the command "netstat -a" from a cmd.exe windows to check the status of all the connection to see if any actually completed.  Also using a sniffer like wirshark can get additioanl information to debug the problem.  You also may find some usualful error message in the Event Viewer (in control panel - adminstrator tools) that may help sove the problem.


    jdweng

    Monday, April 29, 2013 9:56 PM