What has probably happened is that you have developed your drupal (or any other PHP+MySQL) site, tested the functionality, everything was working fine and after that you decided to go live, but suddenly you found out that the site in its current state does not cope with the loads. Or, probably, you just run some load testing and found out the same thing – number of users visiting your site is too high for the current configuration. The website performance is too bad, the site is too slow, or even worse, you are experiencing time out errors or something similar.
So, the question is, what can be done? See these 6 tips below!
1. Check if your web site is utilizing client-side caching possibilities at its best. There are a few tools on the market that allow you to do the testing for free. I’m using a couple of them:
– http://www.webpagetest.org/ . To use webpagetest, you do not need to install anything on your computer, just follow the link and enter the URL of your web site. The good thing is that you do not need to install anything on your PC, but it requires your web site to be published and available on the web – in other words you won’t be able to test a site which is only available on your localhost.
– https://addons.mozilla.org/en-US/firefox/addon/yslow/ . This is a firefox browser plugin, to use it you’ll need to have the FireFox browser. Even if it requires installation, you can test caching (eTags and some other!) settings of the site which is even hosted on your machine only.
These tools also provide you with some advice on how to improve your site speed, such as:
– utilizing browser caching – that will allow returning users to save time on downloading content that was already downloaded before.
– compressing components (css, js, html) with gzip – gzipping will make download time shorter since content size becomes smaller.
– configuring eTags (Entity tags are a mechanism web servers and the browser use to determine whether a component in the browser’s cache matches one on the origin server).
– checking errors in your html and making recommendations on how to improve (duplicated links to resources, 404 errors, images scaling, heavy cookies, etc)
2. If most of your site users are actually readers and not content publishers, it can be helpful to use some sort of server-side caching mechanism. If you are using Drupal, I would recommend to check out the Boost module. It is possible to configure this module to create a static HTML snapshot of dynamic PHP pages and store them on the disk. Non-authorized users then will see cached version of the pages (i.e. you can set to refresh them every 3 hours), only logged in users will continue to see the most recent content. It’ll allow you to offload your CPU and MySQL. If you are using nginx as a proxy to serve static content (see below), it’ll allow you to offload Apache as well form serving these static pages. The scheme below (taken from the module site) shows how Boost will change the work flow of serving content to your users:
Using Boost can have some side effects though:
– Since non-authorized users are served with cached version of pages, they don’t see the most recent changes. However, this is not needed for all pages, and you may exclude some of the pages from being cached in the module settings.
– You may have problems with Drupal native way of tracking visitors (populating of node_counter table), some tweaking could be required.
3. Try to improve your MySQL performance. Please see this post for detailed instructions: http://cloudinservice.com/speed-up-mysql-for-your-website/
4. Configure Apache MPM Prefork module for better performance: http://cloudinservice.com/tune-apache-performance-using-mpm-prefork-module/
5. Configure proxy server to offload apache from routine tasks: http://cloudinservice.com/configure-nginx-proxy-for-drupal-site/
6. The problem, of course, can be in the code itself. Probably the code is not optimal, uses too many database calls or leads to memory leaks. In case your web site is built by a group of developers, it is highly recommended to establish a code review procedure when code written by the team is analyzed and reviewed by experienced senior developer. If your web site is built on Drupal, you can use the devel module to check what is going on behind the scenes. It’ll let you know which DB queries (and how long do they take to execute) are run when particular web page of the site is opened.