Improving Drupal Page Speed with a CDN

 

In March of 2012, one of our major goals for EmpowHER.com was to increase page load times. One of the easiest ways to accomplish that is to limit the number of HTTP requests your web server needs to fill per page request. On a CMS driven site like Drupal, the total number of requests a single page requires can easily get into the hundreds.

How much will it cost?

The first thing I can warn you about from experience is that the top-tier CDNs are going to want you to commit to a yearly contract and a minimum monthly bandwidth spend - usually somewhere around 4 TB. If you need that kind of traffic, then start calling around and asking for quotes. Expect to spend somewhere in the neighborhood of $1-2k / month.

If you're looking for a smaller amount of bandwidth with no contract, here's a few approaches:

  • Ask your hosting provider if they resell CDN bandwidth. Firehost is our host for EmpowHER.com, and they offer CDN service (through EdgeCast) at $.50 / GB. This is really pricey, but it is an option with no monthly commitment. 
  • Amazon CloudFront is one of the cheapest CDN providers out there at $0.12 / GB as of this writing. The downside is they offer no admin interface to speak of. The only way to purge individual assets is via an API, and you get no usage statistics.
  • Use a dedicated reseller, such as GoGrid, SpeedyRails, or TurboBytes.

What features will I need?

Most CDNs divide their caches up into large and small objects. This effectively means images, JavaScript, and CSS files in the small cache, and video and rich multimedia content in the large cache. Large object caching comes at a slightly higher premium. Not all CDNs treat both caches the same, so that's where I started. We only needed a small object cache.

Another requirement was that we have a control panel that allows us to monitor bandwidth usage, and purge individual items from the cache. From time to time individual objects in the cache will grow stale and need to be manually refreshed. Some providers make this easier than others so be aware of this when evaluating their offerings. 

Here's a couple of links that I used while researching CDN providers:

  • Cdnplanet.com, a great site for side by side comparison shopping
  • Cedexis.com, scroll about half way down the page for CDN response time comparisons. Note that a shorter response time is better.

So how does this all work?

There's two major methods of integrating with any CDN: Origin Pull or Push. Origin pull means you will point all requests for objects you want cached in the cloud to your CDN provider. They will check their servers to see if that object is present. If not, they will pull it from your website (also called the origin server) and then copy that to their servers which are distributed globally (also referred to as 'edge servers').

Push integration simply means that instead of waiting to pull cacheable objects from your servers, you plan to preemptively upload the files in a batch to your CDN provider. This is most commonly used with large object caching, as you don't want your CDN waiting for an upload to complete on a large file (say, a video) before serving it to your users.

How do I integrate my Drupal site with a CDN?

First, you're most likely going to want to create a subdomain for your CDN. We created a simple subdomain off of EmpowHER.com (cdn.empowher.com) and pointed it at EdgeCast's CDN server. Your CDN provider will have instructions on how to set this up.

In Drupal, there's a community module to make all of this really simple: CDN. Just install the module as usual and go to '/admin/settings/cdn'. Then simply tell the CDN module what domain it's supposed to pull from and what files you want to serve via CDN. For example:

  • On the 'General' tab, simply set the Status to 'Testing' to start.
  • On the 'Details' tab, leave the mode set to 'Origin Pull'. in the CDN mapping text area field, enter:

    http://cdn.yourdomain.com| .css .js .ico .jpg .png .ong .svg .otf .ttf .swf

This will enable CDN integration for Administrator level users only. Be sure to clear your cache in the usual way before testing. Once you've verified everything looks good, switch CDN from 'Testing' to 'Enabled'.

How do I monitor my CDN usage?

If your CDN provider offers a control panel, then they should have reporting built in. I recommend keeping a close eye on your bandwidth usage for at least the first couple of months, as any overages from your monthly spend (if you have a set agreement) are typically billed at a higher rate, so it pays to be aware!

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
glqxz9283 sfy39587stf02 mnesdcuix8
sfy39587stf03
sfy39587stf04