1

TL;DR

I have Apache Solr installed on Windows Server R2 64-bit machine with 8 GB of RAM. By default, JVM seems to be using ~256 MB of memory. Since I have some pretty big files for indexing with it, sometimes I get Java heap space OutOfMemoryError.

How should I increase the memory size available to Solr?

More details

Most of the documentation / posts I found over the web are pointing to something like java -Xms1024m -Xmx2048m -jar start.jar, but I'm not running the Solr through the command line. It's run as a Windows service. I guess there's a config option to set this somewhere in Solr installation folder, but I'm not able to find it (and besides, not very familiar with Java stack, since I'm a .NET developer).

Few things I tried:

  • setting environment variable in /Bitnami/solr-4.5.0-0/scripts/setenv.bat: set JAVA_OPTS="%JAVA_OPTS% -XX:MaxPermSize=1024m -Xms1024 -Xmx1024m"
  • modifying /Bitnami/solr-4.5.0-0/scripts/serviceinstall.bat and trying to add JvmOptions arguments to a command line for installing Jetty service (again, not familiar with syntax here). There's a similar answer for Ubuntu based installation, but script files are different.
  • running /Bitnami/solr-4.5.0-0/serviceinstall.bat REMOVE and serviceinstall.bat INSTALL after the changes above

Below is Solr's Dashboard screenshot.

Solr dashboard screenshot

Any idea?

Update 1

There's a serviceinstall.bat file in /Bitnami/solr-4.5.0-0/apache-solr/scripts/ which contains Jvm options which I tried modifying but failed to get the expected result. Here's that line from the file (added line breaks for better display):

"D:\BitNami\solr-4.5.0-0/apache-solr\scripts\prunsrv.exe" //IS//solrJetty 
--DisplayName="solrJetty" 
--Install="D:\BitNami\solr-4.5.0-0/apache-solr\scripts\prunsrv.exe" 
--LogPath="D:\BitNami\solr-4.5.0-0/apache-solr\logs" 
--LogLevel=Debug 
--StdOutput=auto 
--StdError=auto 
--StartMode=Java 
--StopMode=Java 
--Jvm=auto 
++JvmOptions=-DSTOP.PORT=8079 
++JvmOptions=-DSTOP.KEY=s3crEt 
++JvmOptions=-Djetty.home="D:\BitNami\solr-4.5.0-0/apache-solr" 
++JvmOptions=-Dsolr.solr.home="D:\BitNami\solr-4.5.0-0/apache-solr/solr" 
--Jvm=auto 
++JvmOptions=-Djetty.logs="D:\BitNami\solr-4.5.0-0/apache-solr\logs" 
--JavaHome="D:\BitNami\solr-4.5.0-0\java" 
++JvmOptions=-XX:MaxPermSize=128M 
--Classpath="D:\BitNami\solr-4.5.0-0/apache-solr\lib\*";"D:\BitNami\solr-4.5.0-0/apache-solr\start.jar" 
--StartClass=org.eclipse.jetty.start.Main 
++StartParams="D:\BitNami\solr-4.5.0-0/apache-solr\etc\jetty.xml" 
--StopClass=org.eclipse.jetty.start.Main 
++StopParams=--stop 
++StopParams=-DSTOP.PORT=8079 
++StopParams=-DSTOP.KEY=s3crEt

Does anyone know where to put additional JvmOptions (Xmx, Xms...) and what the syntax should be?

Community
  • 1
  • 1
Miroslav Popovic
  • 12,100
  • 2
  • 35
  • 47
  • I would make sure you have using the 64-bit version where the default should be 1/4 of main memory or 2 GB. For the 32-bit client JVM the default is 128 MB of heap and the rest could be shared libraries and thread stacks. – Peter Lawrey Oct 19 '13 at 23:38
  • @PeterLawrey As I can see from the provided [installer](http://bitnami.com/stack/solr/installer) link, there's only x86 support for windows. – rchukh Oct 20 '13 at 09:51
  • 1
    According to [this thread](http://community.bitnami.com/t/bitnami-apache-solr-ec2-ami-startup-script/20736/8) there should be something like `D:\BitNami\solr-4.5.0-0/apache-solr/scripts/ctl.bat` in solr installation directory where JVM settings can be specified – rchukh Oct 20 '13 at 09:56
  • @rchukh That is pretty sad. What happens when you use a 64-bit JVM on windows instead. – Peter Lawrey Oct 20 '13 at 11:59
  • @PeterLawrey Yes, it seems only 32-bit installer is available. – Miroslav Popovic Oct 20 '13 at 21:10
  • @rchukh The file looks different on Windows version... it doesn't start .jar file directly, but uses Jetty. Not sure what should be the right syntax. I have added the line from serviceinstall.bat to my question as an update. Thanks. – Miroslav Popovic Oct 20 '13 at 21:28
  • 2
    Well... as I see - there is a `++JvmOptions=-XX:MaxPermSize=128M `, so probably you can change the size if you want and add two additional lines - `++JvmOptions=-Xms1024M` and `++JvmOptions=-Xmx1024M` - right after that. – rchukh Oct 21 '13 at 08:56
  • @rchukh I tried that before, but didn't reinstall the service correctly - running the wrong script. Now I run that script directly, and it succeeded. Added an answer in case anyone else have the same problem. Thank you. – Miroslav Popovic Oct 21 '13 at 14:31

2 Answers2

7

After some more research, I've managed to increase the heap size, by modifying /Bitnami/solr-4.5.0-0/apache-solr/scripts/serviceinstall.bat script according to @rchukh's comment.

I've tried modifying that file before, but the Solr service needs to be reinstalled after any change there. The problem was that I tried to reinstall it using the /Bitnami/solr-4.5.0-0/serviceinstall.bat. That batch script should be running all other serviceinstall.bat scripts in all subfolders, however it doesn't run the one that I needed.

So, here's how my /Bitnami/solr-4.5.0-0/apache-solr/scripts/serviceinstall.bat script looks now (longer lines broken for readability):

@echo off
rem -- Check if argument is INSTALL or REMOVE

if not ""%1"" == ""INSTALL"" goto remove

"D:\BitNami\solr-4.5.0-0/apache-solr\scripts\prunsrv.exe" //IS//solrJetty 
--DisplayName="solrJetty" 
--Install="D:\BitNami\solr-4.5.0-0/apache-solr\scripts\prunsrv.exe" 
--LogPath="D:\BitNami\solr-4.5.0-0/apache-solr\logs" 
--LogLevel=Debug 
--StdOutput=auto 
--StdError=auto 
--StartMode=Java 
--StopMode=Java 
--Jvm=auto 
++JvmOptions=-DSTOP.PORT=8079 
++JvmOptions=-DSTOP.KEY=s3crEt 
++JvmOptions=-Djetty.home="D:\BitNami\solr-4.5.0-0/apache-solr" 
++JvmOptions=-Dsolr.solr.home="D:\BitNami\solr-4.5.0-0/apache-solr/solr" 
--Jvm=auto 
++JvmOptions=-Djetty.logs="D:\BitNami\solr-4.5.0-0/apache-solr\logs" 
--JavaHome="D:\BitNami\solr-4.5.0-0\java" 
++JvmOptions=-XX:MaxPermSize=256M 
++JvmOptions=-Xms1024M 
++JvmOptions=-Xmx1024M 
--Classpath="D:\BitNami\solr-4.5.0-0/apache-solr\lib\*";
            "D:\BitNami\solr-4.5.0-0/apache-solr\start.jar" 
--StartClass=org.eclipse.jetty.start.Main 
++StartParams="D:\BitNami\solr-4.5.0-0/apache-solr\etc\jetty.xml" 
--StopClass=org.eclipse.jetty.start.Main 
++StopParams=--stop 
++StopParams=-DSTOP.PORT=8079 
++StopParams=-DSTOP.KEY=s3crEt

net start solrJetty >NUL
goto end

:remove
rem -- STOP SERVICE BEFORE REMOVING

net stop solrJetty >NUL
sc delete solrJetty

:end
exit

After that script is modified, you need to reinstall the service by running it twice (to remove and install):

D:/Bitnami/solr-4.5.0-0/apache-solr/scripts/serviceinstall.bat REMOVE
D:/Bitnami/solr-4.5.0-0/apache-solr/scripts/serviceinstall.bat INSTALL
Miroslav Popovic
  • 12,100
  • 2
  • 35
  • 47
1

You can change Bitnami\solr-5.2.1-1\apache-solr\bin\solr.in.cmd . There is a line that says :

set SOLR_JAVA_MEM=-Xms512m -Xmx512m

Change that to

set SOLR_JAVA_MEM=-Xms2g -Xmx2g

Then you need to restart the service :

net stop solrJetty 
net start solrJetty 

go to : http://localhost:8983/solr/#/ You will see new values in effect.

Veysel Ozdemir
  • 675
  • 7
  • 12