Email iconarrow-down-circleGroup 8Path 3arrow-rightGroup 4Combined Shapearrow-rightGroup 4Combined ShapeUntitled 2Untitled 2Path 3ozFill 166crosscupcake-icondribbble iconGroupPage 1GitHamburgerPage 1Page 1LinkedInOval 1Page 1Email iconphone iconPodcast ctaPodcast ctaPodcastpushpinblog icon copy 2 + Bitmap Copy 2Fill 1medal copy 3Group 7twitter icontwitter iconPage 1
    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.

    Web Application Caching

    A typical web page request involves a browser making a request to the server layer (Apache) which then passes information about the request to an application layer (PHP – handles business logic) or returns files associated with the presentation layer. The application layer then serves information contained within a database layer (MySQL) and returns a response which is made up of the presentation layer (HTML, JavaScript and CSS stylesheets) which is downloaded by the browser.

    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:

    1. 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.
    2. Improved user experience – faster page loads, increased responsiveness of UI
    3. Search engine optimisation – Google now include page load speed as a metric for ranking web sites
    4. Scalability – Caching can help to reduce server load, which allows provision of more requests per second

    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.

    Content Delivery Networks: Services such as Cloudflare and Amazon Cloudfront function in a similar method to varnish. They can sit in front of any request made to your website can serve static asset files (Javascript and Stylesheets) without the need for them to be downloaded from your server. It addition to reducing the bandwidth used by the application on its server, these services are distributed worldwide and as such improve page load times globally.

    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.

Share: