Slow socket performance
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Slow socket performance

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    3

    Angry Slow socket performance

    Hi,

    This is a pretty long and sordid tale...

    I am frustrated. Immensely so. I'm in the process of creating a small, multi-player MUD-like game. I have done so before without much trouble. This game is being designed with a Flex-based, web-accessible client application which then makes a TCP socket connection to a server currently running on my PC. The client app runs wonderfully. The server is where I'm running into problems...

    If I test everything locally, it runs swiftly and responsively. Once I connect to it from somewhere outside my LAN, things go downhill. Data sent to the server from the client is received server-side immediately. Anything sent from the server to the client takes an absolutely unacceptable period of time. Sometimes 5-60 seconds for a single packet, sometimes it never gets there at all. This problem is also (mostly) language-independent. The vexing thing is that the send() call returns non-error values, indicating X number of bytes were sent, but the client still never gets the info. It's almost as though it's hanging out in the socket's send buffer and never actually getting sent out, despite what the send() function is saying. I understand that sometimes things can hang out in this buffered state for awhile before being sent off, but this is completely unrealistic and unacceptable performance.

    To simplify the troubleshooting, I built a simple echo server that immediately echoes the client's input back to them in C++ and in Python with the same problem. In both languages I've used the select() function to allow for asynchronous input handling.

    I've also created a simple threaded server that uses a block socket to listen for connections, and spawns a new thread for each connection, each thread using a blocking socket to constantly poll for input and echo it back right away, no use of the select() function. Same problem.

    So, I tried a pre-written C# socket server that simple echoes input back. It works perfectly.. data is sent out and received by the client immediately after the call is made to send it.

    Bypassed the router, disabled the firewall, made sure all my drivers were up to date, etc., same issue.

    If I compile and run the C++ server code on a friend's computer (we're both using Visual Studio 2008), it works perfectly.

    Also, setting or clearing the TCP_NODELAY option to disable/enable Nagle's algorithm has no effect.

    So, this problem is local to my PC, and I'm at a complete loss as to what could cause it. I'm wondering if anyone here has any suggestions as to where to go next before I pull all my hair out. I can't see it being a hardware issue, as any other network applications I have installed send and receive data without a problem.

    Any suggestions? Anyone else had the same or similar problems? Help!

    Thanks...

  2. #2
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Slow socket performance

    Quote Originally Posted by Pharis View Post
    If I compile and run the C++ server code on a friend's computer (we're both using Visual Studio 2008), it works perfectly.
    Are you running a debug version or a release, optimized version of the program? It must be a release version for any further analysis of any slowdown -- in other words, the program must be able to be run a machine that does not have Visual Studio installed.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jan 2009
    Posts
    3

    Re: Slow socket performance

    Hi Paul,

    Thanks for the reply! I have also tried compiling a release version with full optimization and running it on a different machine, and it works fine there. Running a release build on my workstation results in the same poor performance.

    Thanks,
    -Pharis

  4. #4
    Join Date
    Jan 2009
    Posts
    8

    Re: Slow socket performance

    Might be related to gracefull closure of the sockets and TCP states (TIME_WAIT etc)
    Use the netstat command to check for this.
    Compare the netstat results with the C# server.
    Perhaps on your devpc, "incomplete" socket shutdowns accumulate.

    Hope this helps.

  5. #5
    Join Date
    Jan 2009
    Posts
    3

    Re: Slow socket performance

    Hi,

    That what I thought at first, too.. so I rebooted the machine and started the server up fresh. The problem still occurs on the very first connection.

    Thanks!
    -Pharis

  6. #6
    Join Date
    Aug 2007
    Location
    Birmingham, UK
    Posts
    360

    Re: Slow socket performance

    I'd first check with a packet sniffer that the data actually leaves the server properly, then I'd concentrate on the receive part of the client. Since the system works fine locally but not over the Internet it may have something to do with the server packet being split up into multiple packets by the time it reaches the client. In that case it takes multiple calls to recv() to be fully received. Check that your client can can cope with this.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center