Search code examples
actionscript-3apache-flexhttpservice

AS3 HttpService is slow, seeing 1-5 seconds response time


Using Flex Builder 4.5 with rails running on localhost on a brand new MacBook Air. Using curl, the response time of the server of a read is around 200-300ms. When I use HTTPService, from send() to result received is between 1-5 seconds for less than ten lines of XML received from the server. If I use the browser to render the URL, it matches curl, ie it is instantaneous, I'm not waiting for the XML to render.

The number is the same for debug/non-debug mode. The HTTPService is called after creation complete, so the GUI is done. After data is received, the rest of my algorithms are completing under 20ms in the application.

Is this time expected, or am I doing something wrong, or have something configured incorrectly?


Solution

  • What you've described sounds like HTTPService isn't setting the TCP_NODELAY socket option (setsockopt(3)) on its sockets before sending a request. From my Linux tcp(7):

      TCP_NODELAY
              If set, disable the Nagle algorithm.  This means that
              segments are always sent as soon as possible, even if
              there is only a small amount of data.  When not set,
              data is buffered until there is a sufficient amount to
              send out, thereby avoiding the frequent sending of
              small packets, which results in poor utilization of
              the network.  This option is overridden by TCP_CORK;
              however, setting this option forces an explicit flush
              of pending output, even if TCP_CORK is currently set.
    

    Perhaps your platform has another way you can ask to disable Nagle's algorithm for a specific connection.