fromSeptember 2014
Column:

Caffeinated Drupal

The Pursuit of Perfection
0

Once upon a time, I drank coffee purely to wake myself up in the morning or to stay awake during a late night coding marathon. Eventually, I gained an appreciation for the different flavors, smells, and textures to be found in different coffees and brewing methods. That appreciation has grown into a pursuit of the perfect cup of coffee which, while it may never be achieved, provides me with a fun hobby as well as an endless supply of amazing coffee.

 Coffee

Performance tuning a website is another of those endless pursuits wherein you may never actually reach a happy ending.

Is there such a thing as a perfectly performing website? The answer to that question is much like the perfect cup of coffee: perfection lies in the eye of the beholder. While we may not ever be able to achieve a perfectly performing website, we can certainly define goals for what would be considered a well performing site. And by precisely measuring aspects of the site’s performance, we can know if our adjustments are moving us in the right direction or not.

Of course, when defining performance goals, like any project, it’s best to begin at the beginning. In this case there’s no better place to start than a nice cup of Kenya Peaberry, brewed in a manual pour-over to bring out the amazing citrus fruitiness (with a touch of spice). Mmmm, if that’s not nirvana, it sure is close! Now we can jump right in.

Defining Performance Goals

As I mentioned, we need to define goals in order to know where we’re going with the performance tuning, otherwise we’re likely to get people working on random performance improvements that may or may not meet our business requirements. The more specific the goals, the better. Here are a few ideas to get us going:

  • The front page must load in under X seconds.
  • The site must support at least Y concurrent users.
  • Popular entry points to the site must load in under Z seconds.

The important point here is to create an authoritative list which will get everyone on the same page and understand exactly what they’re working towards. Even if you are a team of one person, this is still a great way to define an endpoint for your (current) performance work.

Measuring Performance

We should be able to measure performance of the site objectively, and to clearly see the various elements that contribute to overall performance. There are many things that we’ll likely want to measure and monitor, including:

  • Page load time and time-to-first-byte for various page types on our site, especially the pages with the most traffic. For this we could use an assortment of load testing software or services.
  • PHP execution time and detailed function calls. Tools like Xhprof are great for providing this information.
  • Server load. There are many UNIX tools for tracking load or monitoring it over time.
  • MySQL slow queries.

Whatever you choose to measure, be sure that it’s repeatable, so that you can observe and record changes in performance that result from your efforts.

Working Towards Your Goals

Much like pursuing that perfect cup of coffee, there are many different aspects of a site that contribute to its overall performance.

In some cases, you may find your site can’t perform well because your server is simply underpowered. Perhaps you need to look at upgrading your server or adding additional servers. You certainly can’t get great coffee out of a $5 coffee pot; sometimes you just need a new machine.

Other times, you may have plenty of server power, but things aren’t tuned quite right to take advantage of those resources. For example, you may be able to allocate more memory to your database to speed things up significantly. Similarly, coffee flavors change greatly based on water temperature and immersion time when brewing. Even great coffee can turn out poorly if you don’t “configure” your brewing correctly.

And of course, there’s always the code. If you have custom code, perhaps it wasn’t written with performance in mind. A poorly written query or a missed opportunity to cache a returned value could make all the difference. After all is said and done, a cup of coffee is only as good as the bean it came from.

Image: "Various Coffees" by premshree is licensed under CC BY-NC-SA 2.0