Boosted LAMP for Drupal devs

In one on my previous posts I wrote how to configure Drupal development environment in Ubuntu, in this post I am going to talk about performance on your localhost (PAE, APC and MySQL tuning). There is also another blog post about Tuning Drupal Performance for production which is a bit different thing.

My old laptop was broken last days so I quickly found a cheap replacement, which had a bit different insides: two AMD cores VS four Intell i3 cores and 4GB vs 3GB. I decided to try Linux Mint, which is said is better then Ubuntu. IMO for LAMP stack the name of the Linux distribution is not so important, because they are all working good now :) But you should decide which version of one to chose: 32 bit or 64 bit. In this post I found out that 64 bit Linux is better for development, but it could be not good enough for some applications, which could fail running on 64 bit Linux.

Memory utilization for 32 bit Linux

I decided to chose 32 bit version of Mint. But the first thing I noticed was 2.6GB of RAM was only available. That looked very weird and that was one of disadvantage of 32 bit system. When I was running full LAMP stack + IDE + Skype I saw almost almost all memory was used and some disk space were taken for swap. Fortunately good people wrote Physical Address Extension (PAE) which could be installed with the following command:

$ sudo apt-get install linux-generic-pae linux-headers-generic-pae

That worked good and then System Monitor showed 3.5 GB of RAM. Still not 4, but it could be a unit conversion issue. I am glad that swap is not being used and system is working faster now.

Configuring Alternative PHP Cache

A bit later I cloned a big project and I saw how hardly my machine was trying to handle requests, which used to slow down the system. So the way out was to install APC. Alternative PHP Cache is a free, open source framework that optimizes PHP intermediate code and caches data and compiled code from the PHP bytecode compiler in shared memory. In Mint or Ubuntu it could be installed with following command:

$ sudo apt-get install php-apc

Then I made sure that /etc/php5/conf.d/apc.ini file is in place and overrode default settings:

extension=apc.so
apc.shm_size=128M
apc.max_file_size=10M

Then I installed APC module for Drupal that allows to store Drupal cache in memory instead of database. That should give me huge performance increase. I made sure that the size of project cache tables was less then shm_size in config file, enabled APC module and added following lines into settings.php file:

$conf['cache_backends'] = array('sites/all/modules/apc/drupal_apc_cache.inc');
$conf['cache_default_class'] = 'DrupalAPCCache';
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;

See module's readme to check for more options.

MySQL tuning

Despite APC cache was enabled, it was not affecting on the database performance, so I needed to change settings of MySQL to make it work faster. Below are values which I overrode in MySQL configuration files.

/etc/mysql/mysql.cnf:

[mysqld]
key_buffer              = 128M
max_allowed_packet      = 128M
max_connections        = 300
table_cache             =  256
query_cache_limit       = 16M
query_cache_size        = 128M

/etc/mysql/conf.d/innodb.cnf:

[mysqld]
innodb_buffer_pool_size = 1024M
innodb_additional_mem_pool_size = 32M
#innodb_log_file_size = 16M
innodb_log_buffer_size = 4M
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency = 4
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1

Check out what do those settings mean.

Conclusion

Finally I had up to 100% increase in performance. I have not tried to change my HD to SSD yet, but I am sure, it will gain even more performance. BTW, here is an interesting manual, they use it to perform automated tests. It does even allow to run MySQL in memory instead of disk. Enjoy!

If you are interested in performance increase for your production website you can check out my other post Tuning Drupal Performance.