Here is how to add Swap or Virtual Memory on Rackspace Cloud Server Instance running Ubuntu 14.04 LTS. Swap can save instance from complete failure. However, on Rackspace Cloud, it is not recommended to use Swap or Virtual Memory to fight with RAM crisis. This guide to add Swap or Virtual Memory on Rackspace Cloud Server is for “increasing” RAM for temporary period – like that, while upgrading a system. Swapping is a terminology which is used for of Computer Hardware System Components, but here the phrase Swap refers to Virtual Memory. Official documentation about Swap can be found here :
Why We Do Not Suggest To Add Swap or Virtual Memory on Rackspace Cloud Server?
People can still create swap partitions within their VM, but basically for the sake of Multi-Tenancy, Swappiness of VM is kept to 0 (zero) :
To make the system more faster, smoothly running, we need to plan for any way of scaling. We can use OpenStack Heat templates ( read Rackspace Deployments ) to get a scalable infrastructure. Rackspace is never a budget saving option – it is for higher quality and higher redundancy. If we increase the RAM, our Networking, virtual cores also will get increased proportionately. A 2 GB server can perform better than an 1 GB server performance 1 flavor. Furthermore, Rackspace uses PVHM virtualization mode.
We can not give warranty whether Auto Scaling, Automated Image Building will work rightly on Rackspace after adding Swap or Virtual Memory.
Practically, this option is for web hosts like Digital Ocean where increasing RAM is kind of linear. There, if one uses a 1 GB server, adding 500 MB can do better as simply the cost will remain down and increasing to 2 GB will not provide any better virtual processor. Hostgator like web hosts with no own Data Center can use the infrastructure of Rackspace, possibly they do not use Swap.
One can monitor Swap memory on Cloud Intelligence Graph (beta at the time of publishing this guide). Cloud Intelligence Graph supports Swap’s tracing, but actually we need not use it. 1 GB server will outperform a 512 MB server on Rackspace. This is, in the same way true for Amazon, Azure, Fujitsu etc. leading A grade Cloud IaaS providers. Shared Hosting is also required – we do not need all our domains to have a bigger infrastructure. But basically adding Swap to a 512 MB Instance on Rackspace will not do any good – the cost of 1 GB is not huge, the cost of bandwidth is same for all. Where horizontal scaling with five 1 GB will perform better than one 4 GB server, we can not tell it – you need to talk with Rackspace. It depends on many parameters.
Also, increasing RAM might hide a defect – it is abnormal if a WordPress site demands a 32 GB server. The infrastructure is either not optimized or the Application Server’s instance has issues – like database might need a repair. For high load, we obviously server with cache. Caching at front end can bring disaster. That theory is for old servers, Bare Metal and Dedicated Server.
When we will need to detach the device ( like for going to rescue mode, adding more SSD storage device ), this Swap might create problem. So at least take a Server Image snapshot if you are going to do it for production server.
How To Add Swap or Virtual Memory on Rackspace Cloud Server
So the space on the hard drive will be used when RAM is no longer sufficient for running the instance. There are many ways to add Swap. You can read Rackspace’s guide ( read the comments too ) :
By default there is no Swap, so if we run :
sudo swapon -s
it will return a blank table :
Filename Type Size Used Priority
You will get response if you run :
fallocate -l 4G /swapfile
ls -lh /swapfile
chmod 600 /swapfile && ls -lh /swapfile
# run this command separately
sudo mkswap /swapfile
You will get return like “Setting up swapspace version 1, blah blah blah…”. Now you can enable and check :
sudo swapon /swapfile
You can check by running :
sudo swapon -s
This is temporary swap. It will go away on reboot. This is what actually need for emergency.
If you want to make this Swap permanent, you need to follow these steps :
sudo nano /etc/fstab
# add this, use tab key to separate properly
/swapfile none swap sw 0 0
# write out with ^ + O , Exit with ^ + X
# check swaminess
# it should return a value closer to 0
# this command can change the value
sudo sysctl vm.swappiness=10
# swappiness=10 is set in /etc/sysctl.conf file, we can manually open it
Another parameter is cache_pressure, in the same way :
# will return something
# changes the value
sudo sysctl vm.vfs_cache_pressure=50
# vfs_cache_pressure=50 is set in /etc/sysctl.conf file, we can manually open it
You should stop where we wrote “This is temporary swap” for production server. With wrong value or even if this Swap is eaten up and for some reason you need to go to rescue mode, you’ll probably forget your fathers’ name. Fix your RAM consumption. VMs are not for adding more virtual…
Follow the Author of this article :