Tuesday, November 11, 2014

How to improve Drupal 7 Performance Using Content Delivery Network (CDN)

Drupal 7 allows developers to develop common functionality, layout and content in a much shorter timeline using off-the-shelf modules compared to developing such things from scratch. Also, due to a large online Drupal developer community, one can have ready access to latest modules, fixes and all manners of peer help, which makes it one of the most widely used Content Management Systems in use. 

However, the limitations of Drupal 7 become apparent as new contents, modules and themes are added since its performance is not optimized enough to handle module complexities. The most visible impact of the degradation in performance is an increase in the time taken for the website pages to get loaded. The de facto standard for page response times on most corporate websites is 5 seconds or less, failing which studies show that visitors are unlikely to return thus impacting the corporate’s image and business opportunities. This page lists some possible solutions for the performance issues in Drupal 7 so that the developers might benefit from the advantages provided by Drupal 7 without getting hampered by performance issues. 


Performance Improvement Recommendations for utilizing CDN Cache for Performance:


A content delivery network (CDN) is a collection of web servers distributed across multiple locations to deliver content more efficiently to users. The server selected for delivering content to a specific user is typically based on a measure of network proximity i.e. the server with the fewest network hops or the server with the quickest response time is chosen. It is observed that 80-90% of the end-user response time is spent downloading all the components in the page: images, style sheets, scripts, flash, etc. So it is always better to first disperse the static contents / asset files using CDN which can reduce the page response times significantly if is configured properly.

Benefits: For CDN implementation, a sub-domain is created and attached with a content delivery network service provider (Akamai, CloudFront etc) server to deliver the large assets like streaming media or downloadable files for the end users. In general, if the website URL is ‘www.example.com’ then ‘cdn.example.com’ is typically used for content delivery network implementation. The benefits are mentioned below -

1. Faster page response time
2. Cover maximum geographical barriers
3. Improved scalability
4. High availability based on the service provider SLA
5. CDN usage analytics / statics


Alternatives: For most of the content heavy sites Content Delivery Network is used to load different assets like documents, images etc. The CDN server (like Akamai) can cache full HTML pages for Anonymous users as well. This feature can boost performance for non-logged in users. By default Drupal7 provides form based login / logout feature using Druapl7 core user module which uses Drupal session based user permissions. To gain the benefit for authenticated user performance through CDN, the following approach can be considered -
1. A new socket based server is used to handle login / logout from external domain
2. Return the response with cookies in the browser to handle user permissions via AJAX i.e. no page reload
3. Only the dynamic part will be changed (new content will be fetched from the origin server)
4. In this way authenticated user will use the CDN cache for unchanged contents and the page load will be much faster.

Limitations: The below are the limitations of the above approach.
1. This is a costly solution as this needs both CDN and socket server to run the application.
2. Single point of failure if the socket server is down
3. Additional changes in the Drupal code will be required to run the application with this implementation.


Drupal have a nice module named CDN for integrating cdn with its static content (https://www.drupal.org/project/cdn). 

You have to download the CDN module for Drupal (version 2.5 or later). Install it like you install any other module for Drupal. After the module installation, go to admin/config/development/cdn (admin/settings/cdn on Drupal 6). There are three tabs:
      1. General
      2. Details
      3. Other
I’ll cover them one by one. Note that you can install the Advanced Help module to get more and better help.

First tab: “General”

There is only one important setting here: the status of the CDNmodule. You can either disable it, enable it, or put it in testing mode, which is somewhere in between. In testing mode, none of your visitors will get files from the CDN; only users with the access files on CDN when in testing mode permission will get to see it. This is perfect to test whether the CDN integration is actually working correctly. So, for now, let’s put it in testing mode.
The second (and last) setting on this tab is the Display statistics setting. Users with the access per-page statistics permission will get to see, well,per-page statistics at the bottom of each page: “what percentage of files is served from a CDN”, and so on. Enable this for now, so you get to see the results for each page on your site.



Second tab: “Details”

At the top of this tab, there’s a Mode setting, which allows you to choose between Origin Pull and File Conveyor. Choose Origin Pull (the default).
Next, there are mode-specific settings. The most important one is the “CDN mapping” setting. Here we define which files are mapped to whichCDN (in case you’re using multiple CDNs — or static file servers).
Go back to the CloudFront Management Console and copy the domain name of your CloudFront Distribution. In my case: d67something714.cloudfront.net. Now paste this into the “CDN mapping” setting, but prepend it with http://. So your CDN mapping is now set tohttp://d67something714.cloudfront.net. This will cause all files to be served from CloudFront.
Read the included Advanced Help documentation to see what else is possible (e.g. serve images from a different CDN or only serve CSS and JSfrom a CDN), but for us (and for http://wimleers.com), this CDN mapping will do.

Third tab: “Other”

We won’t go into the details of the various settings on this tab, but there’s only one we care about for the scope of this article: the CDNsupports HTTPS setting. If your site is using HTTPS and you configured your CloudFront distribution’s Protocol Policy to Match Viewer, then you can enable this setting as well. Whenever your site is accessed throughHTTPS, your files will still be served from the CDN, via HTTPS!
CDN configuration

You're done!
If you haven’t already, make sure you have enabled Drupal’s CSS aggregation, block caching and page caching. The CDN module automatically rewrites image URLs in blocks and nodes, but we don’t want that to happen on every page load if it’s not necessary — hence enable those caching layers. 





15 comments:

  1. A sales representative from Akamai was making a pitch to one of our IT directors about how their Content Delivery Network could improve our conversion 5-10% by speeding up the delivery of our content. To justify their costs, we'd like to devise a low-expense test. Does anyone have experience engaging in a test like this?

    Ideally, we would like to do an internal A/B Test, but this option seems complicated. We want to avoid: implementing it for a given time period and comparing it to the same date range last year, the week before/after, etc. (too many uncontrolled variables)

    Does anybody have any idea on setting up a tighter test? Or how to make the A/B Test? Akamai can apparently cache the “static” parts so I was trying to figure out a way to direct traffic through their server 50% of the time. Anyone have experience in conversion testing with the effects of using something like Akamai?

    Thanks so much,
    cdn online

    ReplyDelete
  2. I am really very agree with your qualities it is very helpful for look like home. Thanks so much for info and keep it up.
    linux commercial software

    ReplyDelete
  3. I really loved reading your thoughts, obviously you know what are you talking about! Your site is so easy to use too, I’ve bookmark it in my folder
    windows activation

    ReplyDelete
  4. Thanks for always being the source that explains things instead of just putting an unjustified answer out there. I loved this post.
    Coral Gables

    ReplyDelete
  5. This blog is so nice to me. I will keep on coming here again and again. Visit my link as well.. 到會服務

    ReplyDelete
  6. I love the way you write and share your niche! Very interesting and different! Keep it coming! Grocery Delivery

    ReplyDelete
  7. This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info: tracking china post

    ReplyDelete
  8. so happy to find good place to many here in the post, the writing is just great, thanks for the post. thekontent.de/

    ReplyDelete
  9. You re in point of fact a just right webmaster. The website loading speed is amazing. It kind of feels that you're doing any distinctive trick. Moreover, The contents are masterpiece. you have done a fantastic activity on this subject! thekontent

    ReplyDelete
  10. Well we really like to visit this site, many useful information we can get here. thekontent

    ReplyDelete
  11. I have a mission that I’m just now working on, and I have been at the look out for such information thekontent

    ReplyDelete
  12. Welcome to the party of my life here you will learn everything about me. thekontent

    ReplyDelete
  13. Amazing knowledge and I like to share this kind of information with my friends and hope they like it they why I do thekontent

    ReplyDelete
  14. Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging, thekontent

    ReplyDelete
  15. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. Difference Between Health and Wellness

    ReplyDelete