Tricking out MySQL & Apache Micro EC2 performance

Recently, I moved this blog from one micro EC2 instance to another. In the process, I switched from Nginx to Apache. I quickly realized that my instance was running out of memory (RAM) which was causing all of my Apache-hosted applications to fail. Therefore, I made a few tweaks to increase my micro EC2 performance. I want to share them in the hope they are useful to others.

MySQL tuning

To reduce the memory footprint of MySQL, I decided to reduce the Innodb memory pool size. This will impact MySQL performance; I am only using MySQL for this simple WordPress blog.

First, I opened my MySQL configuration file:

sudo vim /etc/my.cnf

Second, I added this to the end of the file:


Third, I restarted MySQL:

sudo /etc/init.d/mysqld restart

Apache tuning

Apache was consuming most of my micro instance’s memory. This was slowly causing my instance to fail over time. To adress this, I decided to adjust the server process (prefork.c) pool/settings.

First, I opened the Apache config file:

sudo vim /etc/httpd/conf/httpd.conf

Second, I found the prefork.c section in the file (about line 104) and changed the section to match the following settings:

StartServers 1 MinSpareServers 1 MaxSpareServers 5 ServerLimit 50 MaxClients 50 MaxRequestsPerChild 5000

Third, I restarted Apache:

sudo /etc/init.d/httpd restart

Linux swap space

Finally, I added some swap space to my EC2 instance based on some other suggestions. If/when my instance is low on memory in the future (or runs out) the swap should hopefully help keep the system online.

As a note, this will likely lead to a higher cost per month since you’ll be charged more for EBS IOPS.

To add the swap space, I ran these three commands in sequence.

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 sudo /sbin/mkswap /var/swap.1 sudo /sbin/swapon /var/swap.1

Disagree, have a question?

If you see something weird or have questions, leave a comment!