Search code examples
comet

Does long polling really work better than periodic ajax poll?


The overhead for long polling is http connection establishment, also on server side the Java EE server has to hold a lot of suspended requests.

For periodic polls with 10/20 seconds interval, it will work worse than long polling?


Solution

  • It depends on various things:

    • How expensive is it on your client, server and network to make a new request? In some cases, the server may be able to handle "here's a new result - push it to anyone who cares" (from the backend) more easily than "have there been any results in the last 20 seconds" (from the client). Likewise new connections over a 3G network may be more expensive than keeping an existing one going.
    • How important is it to get immediate results? (Think about a chat application, for example.)

    (And no doubt there are others...)