Essential steps to speed up a Drupal web site

Technologies: Drupal 5+, PHP (optional), MySQL (optional), Apache (optional)

An initial installation of the Drupal content management system can be slow. You can speed up your web site substantially by making a few essential adjustments to your site's web server, database, PHP, and Drupal configurations. This article introduces a series of articles on the steps to take and why.

Configure the web server

Drupal is a popular content management system written using PHP and typically installed using a MySQL database and an Apache web server. If you have administrator authority over the computer running Apache, PHP, and MySQL, making a few adjustments can halve page load times and substantially speed up your web site. If the computer serves multiple web sites, all of them will benefit.

The default configurations for Apache, PHP, and MySQL have important performance features turned off. The following articles in this series provide step-by-step instructions and explanations to turn these features on:

Configure Drupal

Drupal has several built-in performance features that can further reduce page load times and speed up your site. The default configuration for Drupal has these features turned off. The following series articles show how to turn them on:

Configure your theme and page layout

Drupal makes it easy to enable lots of features and decorate your site with all sorts of blocks listing recent content, current users, the latest weather report, and lots more. Drupal's theming system lets you download and install hundreds of different themes, or author your own to create a very fancy look and feel. But beware. The more you add to your site, the slower it goes.

The following articles in this series include step-by-step instructions, explanations, and benchmarks showing the costs for blocks and theming choices and what you can do about them:

However, it's easy to get carried away fiddling with everything to extract the maximum performance from a site. Sometimes, the effort is just not worth the savings:

This is fantastic stuff, man!

Especially the bit about optimizing the theme, aggregating the CSS and the other Drupal config stuff. Great for multi-module sites.

One question -- what is a good webhost that will let you configure the webserver and database server as you reccommend?

And speaking of which, doesn't a lot of the speed question just get down to what webhost you use?

Thanks a ton.

Web hosts, configurations, etc.

Thanks for your comments.

There are roughly four main things that affect the perceived performance of a web site:

  • Database query time
  • PHP page assembly time
  • Page download time
  • Page request time

Every time a user asks for a Drupal web page, Drupal issues database queries. Sometimes quite a lot of queries. Most of the time spent by MySQL to answer a query is spent reading data from database tables on disk. Using a faster computer won't help much. A faster disk and more memory for a disk cache will help. But the best way to improve performance is always to avoid doing slow things in the first place. So enable MySQL's query cache to save previous query results. This will skip doing most slow disk I/O and return query results faster without having to buy or lease faster hardware.

Drupal has to spend time executing PHP code to assemble a page for a user. Since PHP is an interpreted language, the PHP engine has to compile Drupal's PHP scripts into an executable program every time a script is run. Installing a PHP script cache saves a lot of this time. Using a faster computer would speed up PHP compiles, but a script cache is always a win regardless of the computer's speed. Once a script is compiled, a faster computer would execute that script faster. But a better approach is to cache previously-generated Drupal pages. Then there is less PHP code to execute and the computer's speed doesn't matter as much. Caching is always better than depending upon fast hardware.

Once a page is assembled, it has to be downloaded to the user. The higher the network bandwidth, the more you can send them within a few seconds. But the bandwidth bottleneck is usually at the user's side. So adding more network bandwidth on the web server side won't help the user any. Instead, compress text content before you send it, carefully compress your images, and use a simpler theme so that there is less to send in the first place. A faster web host can compress text faster, or cache the compressed files, but since the bottleneck is almost always the network I/O, a faster computer won't help that much.

Every web page uses multiple files: the HTML, the CSS, images, JavaScript, Flash, etc. To get a file, a user's browser issues a request to the server and waits for the file to be returned. Network latency describes the round-trip time for the request to travel across the Internet and the server to answer. This is largely a function of the speed of light and the distance between the user's computer and the web server. Since the speed of light can't be increased, and the user's location isn't under your control, network latency is largely unavoidable. To reduce its impact, though, reduce the number of files you have to send to the user. CSS aggregation does this. Using a simpler theme with fewer images, JavaScript files, and Flash also makes a big difference. If there are fewer files to send, the user's browser spends less time waiting for them.

So, for a small web site the speed of a web hosting company's computers and network connection doesn't matter much once you enable caching and do good web site theme design. From a hosting company's perspective, enabling caching everywhere reduces the server load and enables them to host more sites on the same server. That means more income without spending more money on hardware. So, any competent hosting company should be pleased to enable Apache compression, MySQL query caching, and PHP script caching. If they aren't, perhaps they aren't that competent and you'd be better served by going someplace else. Or host the site yourself. It isn't that hard and for a small site it can be done with any old PC or Mac you have laying about.

Dave_Nadeau You are mostly correct but...

HTTP request round-trip time and browser rendering time make up the most of the time it takes to load a page.

see Yahoo's Exceptional Performance Team

Re: Dave_Nadeau You are mostly correct but...

Each of the factors I listed above strongly affect the page load time. If you install Drupal and do not enable a PHP accelerator, MySQL query cacheing, and Drupal page cacheing, your site will be slower than it should be... regardless of the page request time (the HTTP round-trip time) or the browser rendering time. It is only after you have sped up the server side that the rest of the load time factors become relevant.

Yahoo's excellent articles, which you reference, study the page load time issues after a site has had its servers made reasonably quick. They do not advocate ignoring server side performance problems entirely. Common sense tells you that if you serve your web site on, say, an ancient 286 PC, it's going to be slow. What the articles point out is that after doing reasonable server-side optimization, the problem shifts to a network and browser problem and further server-side effort has diminishing returns. To gain further performance improvements you have to shift your focus to network and browser issues.

Browser rendering time is a factor in the page load time, but usually a very small factor. The rendering time on most reasonable computers is well under a second for even large web pages. By far most of the page load time comes from sending page requests (via HTTP) and waiting for the responses. And the time waiting for those responses is mostly due to network latency... if the web server has been properly configured first.

this is exactly what I was looking for

I'm testing Drupal 4.x for our intranet. I had everything configured, but it was just too slow. Now it looks like I can go live. Thanks.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Nadeau software consulting
Nadeau software consulting