The easiest things make the biggest difference in Drupal site performance

2246952356 dc25aeabf0

The easiest things make the biggest difference in Drupal site performance

Web site performance is an expansive topic. Like just about any aspect of Web development, a career can be made out of becoming knowledgeable on performance. A career can even be made out of becoming a Drupal performance expert (David Strauss is doing just that). I find for single-server sites there are 4 must-dos for performance. These are the biggest bang-for-the-buck performance improving techniques. For a top-100 site like Facebook or Amazon, performance optimization can yield savings measured in millions of dollars per year. For smaller sites, there is a tipping point where it makes sense to hire a knowledgeable professional in performance. For many projects, however, the costs of high level performance optimization cannot justified. Fortunately, for most sites that run on a single Web server the things that can have the biggest effect on performance are often the easiest to implement.

Opcode Caching

Use an opcode caching system like APC or eAccelerator. PHP is an interpreted language as opposed to a compiled language. This means that code written in PHP must be translated from PHP to bytecode that a microprocessor can understand each and every time a PHP script runs. A page served from a typical Drupal site will not only require interpreting PHP from Drupal core but also interpreting code from many contributed module There are costs and benefits to interpreted languages. One significant cost is in performance. An opcode caching system like APC stores compiled bytecode in memory which eliminates the overhead compilation. Opcode caching will noticeably speed up performance on even extremely low trafficked sites. I have found that in practice this reduces time to first byte by about 0.5 seconds to a full second.

Enable and configure mod_deflate

mod_deflate is an Apache module that enables the Web server to gzip compress files before serving them to the Web client. Javascript and CSS files linked within the element in an HTML document must be served before the browser starts rendering the page. Unlike an image within an HTML page, your browser will not begin to draw anything to the screen until all elements in the document head are served. Reduction in filesize of head elements will result in a noticeable performance increase. The bad news is that Drupal is head-heavy. Drupal includes the entire jQuery framework in each page. In addition, contributed modules include their own CSS and Javascript. In a typical Drupal site you will see at least 100K of Javascript and 50K of CSS. For some sites, that number can nearly double. The good news is that the heavy elements in head are all text files. Text files compress exceptionally well. If you configure mod_deflate to compress all Javascript and CSS files you'll see a reduction in file size of an average of around 70%. A site with 150-300K of files in head should reduce to 45-90K which is a 105-210K reduction in the amount of data that the web server needs to submit before the browser can start rendering the page. For most internet connections, this is a very noticeable difference!

Use Drupal performance settings for production sites

In admin/settings/performance you have several performance related settings.

Enable caching

You can have Drupal cache pages and blocks. This can result in a significant reduction in database reads. Drupal stores this cache in cache tables in the Drupal database. The upside to this is that no extra server software or configuration is needed for this performance boost. Any Drupal site can use it regardless of hosting.

Enable aggregation

Drupal has settings to aggregate Javascript and CSS files. A Drupal page view have a dozen or more links to Javascript and CSS files. Each link is a new HTTP request and HTTP requests come with overhead. Drupal can concatenate all CSS and Javascript files into one, reducing a dozen or more HTTP requests to just two - one for CSS and one for Javascript. This is different from compression. Compression reduces file size. Aggregation does not. It combines many files into one.

Educate sitebuilders, themers and content creators on performance issues

Site builders, themers and content creators need to be aware that files they create and upload will affect performance. Drupal has an imageapi that can use GD or ImageMagick to automatically reduce image file sizes uploaded by content creators. Photoshop and GIMP have excellent tools optimize images for Web use, allowing creators to use a slider to visually gauge the trade-off between image quality and file size. Bloggers like to include images in teasers because they know that it has a subtle but positive affect on readership. Knowing that each teaser may have one or more images, sitebuilders need to consider how many posts should display on one page. The more posts, the heavier the page, the lower the performance. All people involved with creating a Web site, not just developers, need to have a certain awareness of how their work can negatively impact the performance of the site.

...and more

There are plenty of other techniques that can be done for single server sites. These include database optimization, resource reduction, use of CSS sprites, use of content delivery networks, code optimization, reverse proxy caching, using a performance-tuned distribution like PressFlow and Web server turning. These techniques aren't as easy to implement and don't have as great of an impact as the techniques discussed above. Several of these options are worth looking into for higher traffick sites.

Related Posts

Websites That Enable You to Make a Difference

Sumeeta Kumar
Read more

The Six Biggest Mistakes You Can Make Running A Business

John DeRudder
Read more

ShowSlow: Monitor Your Site's Performance For Free

Randall Knutson
Read more

Some Things I Want In An E-Commerce Site

Julie Miller
Read more

Improve Drupal Website Performance on Shared Hosting

Read more

Tuning Drupal Performance on DigitalOcean

Kyle Taylor
Read more