Site is slow after a while – Adding a swap file

Continuing from the previous post about migrating this site to an Azure VM… I noticed the the site’s performance was horrendous on the free B1s VM size 1CPU 1GB.

I increased the VM size to B1MS 1CPU 2GB which takes me out of the free tier but so far it seems to work. But in the interest of going back to free tier, I’m going to want to go back to the 1GB VM size. I’ll need to look into this some more.

So it turns out the Azure Ubuntu VM by default doesn’t have a swap file. This appears to be the reason why the VM bogs down and runs out of memory. I checked the site this morning and it wasn’t responsive at all. Azure portal showed it had 35Mb of RAM free.

So I just created a swap file and rebooted. Let’s see if this works. So far so good.

Create 2GB file in root directory called swapfile:
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress

Give only system permission:
sudo chmod 600 /swapfile

Make it a swap file:
sudo mkswap /swapfile

Turn on swap file:
sudo swapon /swapfile

Make persistent by editing /etc/fstab and adding swapfile entry:
sudo nano /etc/fstab
“/swapfile none swap 0 0”

Reboot:
sudo reboot

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.