Solr Core Configuration Considerations

Image

In this blog post I want to share few solr configuration changes that might be considered for optimizing the performance of SOLR server used in a scaled Sitecore environment. It is a learning that is an outcome of SOLR DOWN DOMINO EFFECT ON SITECORE CD AND CM. Trying to find out why did our SOLR server went down, the starting point was of course to investigate log files from the SOLR server and the logs were piled up with lot of below java errors.[code language="c-sharp"]“ ERROR (qtp1450821318-8602) [ x:sitecore_analytics_index] o.a.s.c.SolrCore org.apache.solr.common.SolrException: Exception writing document id visit|ed96eac7-071b-460c-a696-c1bda7ba57a8 to the index; possible analysis error. at org.apache.solr.update.DirectUpdateHandler2.addDoc(DirectUpdateHandler2.java:167) at org.apache.solr.update.processor.RunUpdateProcessor.processAdd(RunUpdateProcessorFactory.java:69) Caused by: org.apache.lucene.store.AlreadyClosedException: this IndexWriter is closed at org.apache.lucene.index.IndexWriter.ensureOpen(IndexWriter.java:719) at org.apache.lucene.index.IndexWriter.ensureOpen(IndexWriter.java:733) at org.apache.lucene.index.IndexWriter.updateDocument(IndexWriter.java:1471) at org.apache.solr.update.DirectUpdateHandler2.addDoc0(DirectUpdateHandler2.java:239) at org.apache.solr.update.DirectUpdateHandler2.addDoc(DirectUpdateHandler2.java:163) ... 36 moreCaused by: java.lang.OutOfMemoryError: Java heap space”[/code]Why is the java heap running out of space? Can I increase it? Are you having the same questions that struck me? Keep reading…Looking at the SOLR dashboard and some google results I figured out the place where the heap size can be seen, it’s right there, available on the SOLR dashboard. Below image shows the default heap size and it is 512MB[caption id="attachment_2726" align="alignnone" width="780"]

SOLR Heap Size

SOLR Heap Size[/caption]Consulting with Sheetal Jain his suggestion was it should be configurable from a config file. So a search & investigation was started to find out the config file or a place where the heap size can be changed. The result was it can be changed at any one place out of the below two

  1. In file solr-5.4.0/bin/solr.in.cmd file

         Search for SOLR_JAVA_MEM and change the value from 512 to a desired value, do take into account the physical memory of the machine on which SOLR is running.For e.g. ChangeFrom                set SOLR_JAVA_MEM=-Xms512m -Xmx512mTo                set SOLR_JAVA_MEM=-Xms1024m –Xmx1024mRestart SOLR service if you have configured it as windows service and you will see the change on the SOLR Admin Dashboard

  1. In file solr-5.4.0/bin/solr.cmd file

         If the above change do not work open solr.cmd search for below line, comment this line by starting  the line with “REM” and set SOLR_JAVA_MEM.For e.g. ChangeFrom                IF "%SOLR_JAVA_MEM%"=="" set SOLR_JAVA_MEM=-Xms512m -Xmx512mTo                IF "%SOLR_JAVA_MEM%"=="" set SOLR_JAVA_MEM=-Xms512m -Xmx512m                set SOLR_JAVA_MEM=-Xms1024m -Xmx1024m.The other learning was why does the heap size goes out of memory read “Documents are always added to the most recently opened segment. When a segment fills up, a new segment is created and subsequent updates are placed there. If creating a new segment would cause the number of lowest-level segments to exceed the mergeFactor value, then all those segments are merged together to form a single large segment. Thus, if the merge factor is 10, each merge results in the creation of a single segment that is roughly ten times larger than each of its ten constituents. When there are 10 of these larger segments, then they in turn are merged into an even larger single segment. This process can continue indefinitely.” for more details and how can that be avoided so a fix is to decrease mergeFactor from a default value of 10 to 5. In order to change the mergeFactor open solrconfig.xml and look out for <mergeFactor>10</mergeFactor>. This setting needs to be changed in all the solrconfig.xml file for the sitecore cores in SOLR if you have same solrconfig.xml then copy past is the best option.Click here to download the solrconfig.xml, the section that has been added is,[code language="xml"]<indexConfig></pre><mergePolicyFactory class="org.apache.solr.index.TieredMergePolicyFactory"><int name="maxMergeAtOnce">5</int><int name="segmentsPerTier">5</int></mergePolicyFactory></indexConfig>[/code]