Before we go into the details of techniques and tips to speed up drupal 7, lets understand what slows down drupal.
- Database queries
- Loading CSS and Javascript
- Images which are loaded on your page
- Loading unwanted modules
Now lets see what are some of the quick things you can do to speed up and optimize.
Configuration changes
- For an initial, quick performance tuning, see on your site: Administer > Site configuration > Performance
Here you can read the options for page cache, CSS optimization, JavaScript optimization. That standard optimization and database caching can be enough for many sites.
Check the boxes next to "Cache pages for anonymous users," "Cache blocks," "Compress cached pages," "Aggregate and compress CSS files," and "Aggregate JavaScript files."
Turning off modules
- Turn off update manager module
- Turn off any devel modules if you have installed.
- Turn off overlay module
- Turn off toolbar module, download and install administration menu module instead.
Likewise you should turn off and remove any modules you are not using, since fast loading site is much more important than adding more functionality which is slow.
Boost Module
- Enable Boost module. For anonymous users Boost caches your pages HTML files, so your webserver can serve them much more quickly as there will be no database reads. So if majority of traffic is from anonymous users, then Boost is a great module for you. Boost can help you realize a significant performance increase for personal blogs, small business, corporate sites, portals and directories that receive mostly anonymous traffic. For shared hosting this is your best option in terms of improving performance and enhancing your website visitor's experience.
For statistics you can always use google analytics module.
Advanced Performance Tuning
- Adding Rule to .htaccess file
If you use the mod_deflate rule, you don't necessarily need to check the "Compress cached pages" checkbox on the Performance settings page.
Rules to be added to the .htaccess file (I add this little block of code to the top of the file, just under the "Apache/PHP/Drupal settings:" comments):
##### Midwestern Mac-recommended additions #####
# Use mod_deflate to gzip components
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css application/x-javascript application/javascript text/plain text/html text/xml application/xml
</IfModule>
# Disable ETags (can help if you're using multiple servers, or use cloud hosting)
# see: http_://www.askapache.com/htaccess/apache-speed-etags.html for more info
FileETag None
################################################
- Innodb Tuning
Now that Drupal 7 (D7) joins mediawiki and gallery2 in using the Innodb database engine if you use any of these you must consider tuning it too and not just myISAM, or these products will run slower than they should.
Edit /etc/my.cnf and for a small D7 site start by adding the following lines under the [mysqld] section.
# innodb specific
# innodb_buffer_pool_size 50% of memory on 5GB+ server. Set it to be larger than your data size or 500M on 4G box.
innodb_buffer_pool_size=20M
# innodb_log_file_size This depends on your recovery speed needs but 256M seems to be good performance
# innodb_log_buffer_size=4M 4M is good for most large servers
innodb_log_buffer_size = 2M
# innodb_flush_log_at_trx_commit=2 (1=flush log to disk every transaction, 2=flush to OS Cache, 0=don't flush)
innodb_flush_log_at_trx_commit = 2