AWS EC2 Micro servers and performance

Recently I’ve been having a problem where this blog would go down because WordPress could no longer connect to the database. The EC2 instance I’m using is the smallest configuration they have, the Micro server, running on AMI Linux (it uses yum so I guess it’s Redhat-based). In the past I’ve ran this blog on servers that had even smaller configurations, some as VPS and other times shared hosting. At no time before have I experienced a problem like the one I was having. I isolated it to the Google indexing servers hammering the server. Although I wouldn’t really call it hammering as anyone opening more than 3-4 concurrent connections basically brought the server to its knees.

The solution was to add a swap file. Normally, the EC2 micro server instance doesn’t have one configured by default so I’ve written a little tutorial to get you started.

First SSH into your EC2 instance and then switch to root:
user:$ ssh -i ec2-server-keyring.pem [email protected]
$ sudo -s

Now create a swapfile (I created a 1gigabyte swapfile):
# dd if=/dev/zero of=/swapfile  bs=1m count=1024

Format the swapfile and set the kernel to use it:
# mkswap /swapfile
# swapon /swapfile

Now, if you want the swapfile to always be enabled at boot add it to the fstab:
# nano /etc/fstab

/swapfile      swap      swap      defaults      0      0