Avoiding swapping

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.

Getting ready

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.

How to do it...

  1. Before turning off swapping, let's take a look at the amount of swap memory used by our operating system. In order to do this, let's take a look at the main page of the Solr administration panel:
    How to do it...
  2. As you can see, some swap memory is being used. In order to demonstrate how to turn off swap usage, I freed some memory on the virtual machine that I was using for tests and after that I ran the following commands:
    sudo sysctl -w vm.swappiness=0
    sudo /sbin/swapoff -a
    
  3. After the second command is done running, I refreshed the main page of our Solr admin instance and this is what it showed:
    How to do it...
  4. It seems that it is working, but in order to be sure, I will run the following command:
    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.

How it 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.123.165