Advanced Web Performance Optimization | WebReference

Advanced Web Performance Optimization


[next]

Andrew B. King

Now that you've learned how to crunch your content, let's look at some more advanced server- and client-side techniques for increasing web performance.

On the server side, this chapter explores methods that you can use to boost performance by:

  • Optimizing parallel downloads
  • Caching frequently used objects
  • Using HTTP compression
  • Deploying delta encoding
  • Rewriting URIs with mod_rewrite

On the client side, we'll investigate procedures that you can use to improve the speed of content delivery. Although these techniques take some additional effort, they boost both perceived and actual web page speed.

Server-Side Optimization Techniques

This section explores some server-side techniques that you can use to boost your site's performance. Note that some of these techniques are hybrids, combining server-side settings with concomitant client-side modifications. For more on server-side performance optimization, you can also check out Web Performance Tuning: Speeding Up the Web, by Patrick Killelea (O'Reilly).

Optimizing Parallel Downloads

The HTTP 1.1 specification recommends that browsers limit downloads to two objects per hostname. This recommendation was created in 1999, in the days of dial-up and less robust proxy servers. Most browsers default to this limit. Although users can change these defaults, most don't bother to do so. For sites hosted on one domain, the result is slower load times with objects loaded two at a time.

Now that bandwidth and proxy servers have improved, you can improve parallelism by using multiple domains (or subdomains) to deliver objects. Yahoo! found that increasing the number of hostnames to two was optimal (see Figure 9.1: Loading an empty HTML document with 20 images using different numbers of aliases).

Increasing to four or more hostnames actually degraded performance for larger images, because of the overhead of off-site requests and "CPU thrashing."

Ryan Breen of Gomez reported similar improvements after increasing the number of subdomains to serve objects. He used Domain Name System (DNS) canonical name records (CNAMEs) to create subdomains such as images1.example.com, images2.example.com, and images3.example.com, all pointing back to the main server, www.example.com. Then he used code to assign subdomains to images, even though they all point back to the same server.

Warning: You may decrease the potential search rankings of content that is hosted on subdomains, but for external objects such as images and videos this technique can improve performance.

DNS Domain Aliasing Using CNAMEs

CNAMEs make one hostname an alias of another, and take the following form:

For example:

where IN indicates Internet, and CNAME indicates CNAME record.

The preceding records indicate that images1.example.com and images2.example.com are aliased to www.example.com. Note that you must also have an A record that points www.example.com to an IP address.

For example:

These records are stored in a "zone" file on your DNS server. In addition, the web server needs to be configured to respond to your new CNAME address. The VirtualHost and ServerAlias configuration directives are often stored in the httpd.conf file.

For example:

Moving from two to six simultaneous connections improved the load time of a sample page by more than 40% (see Figure 9.2, "Response time improvement from two to six simultaneous connections").

When evaluating the maximum number of simultaneous downloads per server, browsers look at hostnames, not at IP addresses. This technique fools browsers into thinking that these objects are served from different domains, allowing more simultaneous downloads. Another way to increase parallelism is to downgrade your object server to HTTP 1.0, which allows up to four simultaneous downloads. See https://www.die.net/musings/page_load_time/ for some simulations of the effect of multiple hostnames, object size, and pipelining on page load time.

Reduce DNS lookups

The Domain Name System (DNS) maps domain names to IP addresses. DNS gives portability to domain names by allowing sites to move to new servers with different IP addresses without changing their domain name. DNS typically takes 20–120 milliseconds to look up the IP address for each hostname. The browser must wait for DNS to resolve before continuing to download the page components. Therefore, minimizing the number of hostnames per page will minimize the overhead due to DNS lookups.

Minimizing the number of hostnames per page also limits the number of parallel downloads, however. For the average web page with more than 50 objects, the best compromise is to split your objects among two to four hostnames to balance the speedup of parallel downloads with the overhead of DNS lookups, opening TCP connections, and the use of client-side resources. The CNAME trick we discussed before can help to simplify object management.


[next]