Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Web Development

The AJAX Application Delivery Challenge


AJAX and Application Performance

The network guys have a secret they don't want you to know: The computational cost of TCP session setup and teardown is high, second only to application processing time in terms of its effect on the overall response time of your application. Every connection made by a web browser to the server requires an underlying TCP session, and it is time consuming to both client and server.

HTTP 1.1 dealt with this issue by introducing pipelining of HTTP requests over an existing TCP connection, ostensibly reducing the number of connections necessary to load a web page. In a sort of Moore's Law like phenomenon, as performance improved pages again grew even fatter, requiring even more requests and more bandwidth.

But HTTP 1.1 says that clients should not open more than two connections to a server, and by default Internet Explorer adheres to the specification. While pipelining of HTTP requests is advantageous in terms of minimizing the impact of connections on the server, it isn't so great for the end-user and the "slow" rendering of large pages within Microsoft's browser is primarily due to the limitation on connections and not any specific deficiency with the underlying code. The specification was written with the performance of servers, not clients, in mind.

AJAX is exciting because it provides the means by which developers can limit the initial amount of data transferred to the client, pre-fetch data and images to enable a more responsive experience, and silently load data during the session that is unique to the user's interaction. AJAX-based applications are not page-centric, they are component centric. This allows browser-based clients to act more like their fat-client counterparts, offering an interactive experience that doesn't require a constant refresh.

This does result in fewer total page refreshes, but requires a great deal more application logic on the client to manage additional connections to the server and exchange data at the appropriate times, such as when the value in a list box changes or a new tab is selected.

The problem with this model begins to manifest itself in the communication channel underlying AJAX requests. Developers taking advantage of libraries like Dojo or Zimbra rely upon these toolkits for the basic format of data being exchanged - and rarely have control over that format. The toolkits are great for enhancing developer productivity but poor at enabling developers to understand and control the exchange of data. The data is usually exchanged using XML, with no defined schemas against which messages can be validated, leaving applications vulnerable to a set of XML-borne web attacks that are easily prevented simply by tightening and enforcing a well-defined schema.

Also problematic is the refresh rate of AJAX-based components. AJAX makes it a simple task to not only build interactive interfaces, but to provide a near real-time experience for the user. AJAX doesn't solve the inability of the server to push data to the client, therefore applications remain reliant on polling to update data.

The refresh rate can impede performance in multiple ways. First, it maintains an intermittent flow of data between the client and server. Depending on the refresh rate this can cause any number of performance problems. If it's too high and exceeds the browser's default idle time out value (1 minute for Internet Explorer), then the additional performance penalty incurred by establishing a new TCP session with every request drives up response time. This is also true of normal requests made via JavaScript -- if the user is idle too long, a new connection will need to be established. If it's too low and the user is on a WAN or slow link, the requests can begin to overlap and the client will be constantly sending and receiving requests at ridiculous rate.

In addition to the performance implications on the client, the server also has to maintain more connections for longer periods of time and it may not be optimally tuned to handle the additional burden. Web servers were meant to serve content in a request-reply paradigm. Although AJAX complies with the paradigm, it does so in ways that were not anticipated by those who penned the HTTP specification by reusing the connection over long periods of time.

To address the potential performance pitfalls you'll need to tune your web server accordingly. There are a limited number of parameters you can tune to assist in improving performance of AJAX-based applications and they are tactical, stop-gap solutions rather than strategic, but they might tide you over while you search for long-term solutions.

  • Increase the TCP time out to a value in-line with the rate of requests in your client. If you anticipate a request every 3-4 minutes, you may want to raise the TCP timeout to 5 minutes to eliminate the overhead of initiating a new connection. (Connection Timeout for IIS, KeepAliveTimeout for Apache)
  • Validate that the maximum number of requests per connection is high enough to support your application. Consider the number of requests in a typical user session and set this value high. (MaxKeepAliveRequests in Apache, no equivalent in IIS)

Even after tuning your web server you may find that your users experience inconsistent performance and your web server may be experiencing undesirably high CPU utilization rates. You may run into an artificial simultaneous connection limitation set by the web server or you might know that additional AJAX-based applications are coming and you need a more robust and widely applicable solution. If that's the case, you'll need to turn to an external solution such as application delivery controller.

An application delivery controller addresses these performance issues by providing optimized TCP and HTTP stacks capable of handling the higher request rate in a more efficient manner. Such devices provide a more consistent user experience because they are capable of optimizing communication between the client and server as well as providing better management of the resources available on the server by being aware of the state of the server and managing requests and responses appropriately. One such feature provided by these devices is request throttling, which limits the number of times per session, per user, or per second that a request can be made.

Application delivery controllers that act as a full proxy are also capable of servicing more clients while maintaining a lower number of connections to back-end servers, essentially cutting the number of connections to servers in half. This feature lets you provide consistent application performance to more clients without deploying additional servers.

These devices are also aware of the bandwidth available to the client and can adjust the rate of delivery accordingly while allowing the server to deliver content at the highest rate possible. This means the server can deliver content as fast as possible and does not need to tie up a connection while it waits for a client on a slow link or device (WAN, dial-up, mobile devices) to receive the data. This can also eliminate the possibility of needing a second, third, or even fourth web server to handle the increase in requests created by AJAX and Web 2.0 applications.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.