Friday, September 23, 2011

Speed up web server with RAM caching


When I deploy a large web server I need to guarantee that HTTP requests are serviced with a minimum response time and many companies impose a Service Level Agreement (SLA) requiring that 90% of web page requests be served up with sub-second response time.
It’s considered rude to make your customers wait, especially on the web.  This article on web page caching notes hat a RAM cache can make a huge impact on overall response time:
    “Formulating a caching policy for a web site – determining which resources should not get cached, which resources should, and for how long – is a vital step in improving site performance.”

Consider HTML Compression

Servicing an HTTP request does not involve high CPU consumption.  However, you can utilize idle CPU resources by installing HTTP compression to improve webserver HTML delivery speed, trading off unused CPU cycles for faster web response time.  The two most popular compression tools are:
mod_gzip – Available on Apache, mod gzip compresses all outgoing HTML and the browser uncompresses the HTML at rendering time.
mod_deflate – A newer tool, mod_deflate is available on Apache 2.0 and one vendor has mod_deflate for Apache 1.3.
I’m told that this tool will allow mod_deflate in a shared server environment using Apache 1.3, and it looks interesting because it does both RAM caching and HTML compression.

The best RAM caching for web servers

When a web server without a web cache is experiencing stress, the cause is most likely disk enqueue requests.  The average disk latency is 15-20 milliseconds and it does not take much traffic to cause disk enqueues.
Most webservers have some pages that are far more popular than others, and caching the most popular images will dramatically improve total response time.
Disk speed is measured in milliseconds (thousandths of a second) and RAM is measured in nanoseconds (billionths of a second).  In theory, RAM should be 10,000 times faster than disk, but even with RAM management latency overhead, caching frequently-used components can results in a 500x improvement in webserver response time.
Almost all web site have an 80-20 rule where 80% of the traffic is for the 20% of the most popular web pages.  You can examine your referrer statistics to see the top 20% most popular pages and cache them in RAM.  Once sized and configured, your web cache should keep your most frequently requested images and HTML cached for outbound traffic.
You can have a front-end cached reverse proxy server to serve-up requests without forcing your server to go to disk.  Open source products such as Squid do a great job, but your web server must have dedicated RAM resources.

Choosing your web server RAM caching

Most companies choose Intel-based web server hardware on a server with expandable RAM to cache the most frequently requested pages and images.
Make sure that you choose a server that has expandable RAM capacity, at least 2 gig with expansion to 16 gig, depending on the size of your working set of frequently-referenced pages and images.
If you have less than a million page views a month, you can buy powerful 64-bit PC’s for webserver hardware, install Red Hat Linux advanced server with Squid and have a 1.5 gig web cache for super-fast web page delivery.

No comments:

Post a Comment