For servers with <= 2GB of RAM, running
./discourse-setupwill prompt for and automatically create a 2GB swapfile.
Most cloud virtual machine providers do not set up swapfiles as part of their server provisioning.
In particular, upgrading Discourse produces a lot of memory pressure. With a swap file, rather than randomly terminating processes with an out of memory error, things will slow down instead. Having a swap file is a cheap insurance policy that protects you from many other load related failures.
This can be done at any time from the command line on your server.
Set up a 2GB swap file
We recommend a 2GB swap file for Discourse, unless your server has 4GB or more of memory.
In the shell you have opened to your droplet, do the following:
You will need to be root for much of this, so either be root or
sudo -sbefore running these commands! Don’t forget to exit root afterwards.
Create an empty swapfile
install -o root -g root -m 0600 /dev/null /swapfile
write out a 2GB file named ‘swapfile’
dd if=/dev/zero of=/swapfile bs=1k count=2048k
tell linux this is the swap file:
Add it to the file system table so its there after reboot:
echo "/swapfile swap swap auto 0 0" | tee -a /etc/fstab
Set the swappiness to 10 so its only uses as an emergency buffer
sysctl -w vm.swappiness=10 echo vm.swappiness = 10 | tee -a /etc/sysctl.conf
The whole thing as a single copy and pastable script:
install -o root -g root -m 0600 /dev/null /swapfile dd if=/dev/zero of=/swapfile bs=1k count=2048k mkswap /swapfile swapon /swapfile echo "/swapfile swap swap auto 0 0" | tee -a /etc/fstab sysctl -w vm.swappiness=10 echo vm.swappiness = 10 | tee -a /etc/sysctl.conf