I was asked to put together some information for a presentation entitled ‘HTTP Acceleration and Caching’ covering some basic background and certain techniques and technologies that can be employed to speed up a website/web application. This is by no means a technical specification or a definitive list of tools / techniques but I thought it was worth sharing for those requiring an introduction and then basic guidance on the subject so I hope it will help some people along the way.
- Lower hosting costs even after getting it cheap from places like AKEA Web Solutions LLC & better green credentials – A complete approach to caching will reduce the server time and bandwith used per request. Ensuring only essential levels of resources are consumed.
- Improved user experience – faster page loads, increased responsiveness of UI
- Search engine optimisation – Google now include page load speed as a metric for ranking web sites
- Scalability – Caching can help to reduce server load, which allows provision of more requests per second
Web Application Caching
There are time and bandwidth implications associated with invoking each of these layers and many of these requests and responses may be similar. Therefore it is possible to save the result output by these layers in order to bypass them and reduce their use of server time and resources.
Implementing caching mechanisms at various points in the application lifecycle conveys multiple benefits:
Application Layer (PHP)
Acceleration: PHP is a dynamic language and is compiled on the fly, caching the result of this compilation step greatly improves the performance of the application. We currently use APC (Alternative PHP Cache) to achieve this.
Business Logic: Parts of the business logic of the application may involve complex computational functionality, the result of these functions can be cached with APC in order to minimise their impact on the performance of the applicationDatabase Layer (MySQL)
Retrieving data from the database can potentially be an expensive operation. For example a business report may pull in large quantities of data from multiple sources in order to compile and compute statistics. This is an intensive operation for both the database and the application layers; however it is possible to use transient caching to bypass the need for repeated generation of a report past initial generation. We currently use APC to achieve this.
Full Page (HTTP) and Asset Caching
Full Page Caching:There is a caching model built into the HTTP specification. Each time a user requests a web page, the browser caches the response. For an application following the HTTP caching specification, subsequent requests will only make a check to see if the content is changed – essentially bypassing all but the server layer (as such minimising the bandwidth and server time per request).
HTTP Acceleration: We are currently using Varnish which sits in front of the Server Layer and utilises the specifications outlined in full page caching above. As it bypasses all the aforementioned layers, the increases in application performance and efficiency is dramatic.
Cloudflare carries additional benefits to its CDN properties by providing an additional security layer by preventing access to services from know exploiters and spammers, and a host of other services including analytics.