The Long-Polling Technique
by Dylan SchiemannNovember 15th, 2007The long-polling Comet technique is a technique that optimizes traditional polling to reduce latency.
Traditional polling sends an XMLHttpRequest to the server in fixed intervals. For example, open a new XMLHttpRequest every 15 seconds, receive an immediate response, and close the connection.
Long-polling sends a request to the server, but a response is not returned to the client until one is available. As soon as the connection is closed, either due to a response being received by the client or if a request times out, a new connection is initiated. The result is a significant reduction in latency because the server usually has a connection established when it is ready to return information to return to the client.
Greg Wilkins recently compared long-polling to traditional polling in the article Comet is Always Better Than Polling.











November 16th, 2007 at 1:50 am
It strikes me that long polling might not be appropriate for situations where you are broadcasting the same event to very large numbers of clients, because it will cause all of those clients to attempt to start a new HTTP request simultaneously - or are the various high performance cometd servers designed to be able to cope with thi?
November 16th, 2007 at 9:17 pm
[...] Dylan talked about the long-polling technique. This method has become fairly well-disseminated, but there are some misconceptions as to the [...]
December 13th, 2007 at 12:34 pm
[...] Long-polling works differently than streaming. Instead of stringing together every event in a single indefinitely long server response, our server keeps each connection open until it has an event, but then closes it after sending a response. Then the browser immediately opens another connection, ensuring that the server can pass it events in real time. This is less effective than streaming transports with respect to bandwidth overhead and throughput; it works, however, in all recent browsers—without the ugly side effects of iframe streaming. [...]
December 18th, 2007 at 10:14 am
[...] of the oft-cited advantages of forever frame over long polling is that it does not suffer from the 3x max latency issue. This is when an event occurs the instant [...]
July 2nd, 2009 at 1:14 pm
[...] development pattern is called Comet , and typically uses the long-polling technique. Holding connections open is better than polling – the latency is lower, and total [...]
October 22nd, 2009 at 1:42 pm
[...] development pattern is called Comet , and typically uses the long-polling technique. Holding connections open is better than polling – the latency is lower, and total [...]