Long Polling and HTTP Streaming

PureLoad Logo
PureTest 5.2
January 2015
http://www.pureload.com
support@pureload.com

Documentation Index -- Task Reference

Background

There is currently several techniques available to create highly responsive, event driven AJAX based applications in a browser. The main goal of such applications is to keep clients up-to-date with data arriving or changing on the server side.

The most popular technique used with AJAX currently is called polling. With polling, an AJAX application will poll the server for data every time the content of the page require an update. As an example, a chat based application will poll the server every 10 seconds to see if new chat messages are available. Technically, it means the browser will open a connection to the server every time data are required:

polling

There is several problems with this approach. The first one is scalability. The number of requests made to the server can be extremely high if the frequency of polling is set to a small value. As an example, if you expect your AJAX applications to be deployed on a small server but still support 10 000 simultaneous users, the performance of your application might be extremely bad. Not only the server but also the network can become saturated with all those requests. The second problem is well illustrated with the above picture. Sometimes if there is no data on the server, the response will not contains any data. Doing such "void" request might overload the server for nothing.

Long Polling

Fortunately there is better technique which is called long polling that helps solving this problem. With long polling, you open a persistent connection and wait for the server to push data when available:

long polling

This technique may solve the scalability problems associated with the polling technique, depending on the server you are using. If your server support asynchronous request processing, then long polling is a good solution. Servers like Jetty, GlassFish and Tomcat all use a technique called asynchronous request/response processing which allow them to not block on a thread, but instead park the request object.

HTTP streaming

Another technique is called HTTP streaming. HTTP streaming is similar to the long polling technique except the connection is never closed, even after the server push data:

streaming

Here the AJAX application will only send a single request and receive chunked (partial) responses as they come, re-using the same connection forever. This technique significantly reduce the network latency as the browsers and server don?t need to open/close the connection. As an example, gmail is using that technique to update the mail interface in a real time fashion.

Simulation using the Asynchronous HTTP Tasks

Both long polling and HTTP streaming is supported by using the Asynchronous HTTP Tasks. See the Task Reference document for details.


Copyright © 2015 PureLoad Software Group AB. All rights reserved.