Continuing to work on how I performance tune web servers. One thing I found is that under a heavy load of 50 or more simultaneos requests, an ubuntu process called OOM-Killer would kill some of my processes. Not that big of a deal right?…ubuntu just trying to keep my system up and running? Wrong…It was killing mysqld. This being a web server, thats not an ideal situation to have.
I learned that by default on aws ec2, there is no swap file included on t1.micro instances. A swap file is essentially Virtual Memory. When the server runs out of real memory, it can write to swap and use this as well. This was what I needed. To create a swap file if not exists, simply do the following:
**Note: replace 1024 with the size of swap file you want. Typically, about twice your allocated real memory. The first line may take a while since it actually writes an empty 2gb data file to /var/swapfile. Please also note that ideally, a separate disk or partition would be used for swap, and not just a file on your root, but this works in a pinch.
sudo dd if=/dev/zero of=/var/swapfile bs=1M count=1024 sudo chmod 600 /var/swapfile sudo mkswap /var/swapfile echo /var/swapfile none swap defaults 0 0 | sudo tee -a /etc/fstab sudo swapon -a