One of the crucial things when running your Solr instances in production is performance. What you want is to give your clients relevant results in the blink of an eye. If your clients have to wait for their results for too long, some of them might choose other vendors or sites that provide similar services. One of the things when running Java application such as Apache Solr is to ensure that the operating system won't write the heap to disk, to ensure that the part of the memory used by Solr won't be swapped at all. This recipe will show you how to achieve this on a Linux operating system.
Note that the following recipe is only valid when you are running Apache Solr on a Linux operating system. In addition to this, be advised that turning off swapping should only be done when you have enough memory to handle all the necessary applications in your system and you want to be sure that there won't be any swapping.
sudo sysctl -w vm.swappiness=0 sudo /sbin/swapoff -a
free -m
The response was as follows:
total used free shared buffers cached Mem: 3001 2326 675 0 3 97 -/+ buffers/cache: 2226 775 Swap: 0 0 0 0 0 0
And again, we can see that there is no swap usage. Now let's see how that works.
In the first provided screenshot, you can see that there is a bit more than 183 MB of swap memory being used. This is not good—in a production environment, you want to avoid swapping, of course, if you have the needed amount of memory. Swapping will write the contents of the memory onto the hard disk drive and thus make your operating system and applications execution slower. This can also affect Solr.
So, in order to turn off swapping in a Linux operating system, we will run two commands. The first one sets the vm.swappiness
operating system property to 0
, which means that we want to avoid swapping. We need to use sudo
, because in order to set this property with the use of the sysctl
command, we need administration privileges. The second command (the /sbin/swapoff -a
one) disables swapping on all known devices.
As you can see in the second screenshot, the Solr administration panel didn't even include the swapping information, so we can suspect that it was turned off. However, in order to be sure, we used another Linux command, the free
command with the -m
switch in order to see the memory usage on our system. As you can see, the Swap
section shows 0
, so we can now be sure that swapping was turned off.
13.58.123.165