开发者

Setting Java Heap Size under Apache Karaf

I apologize if this is a du开发者_开发百科plicate, but I can't seem to find this answered anywhere.

What is the best way to increase the maximum Java heap size when using Apache Karaf?

Currently, I modified the following line in the karaf.bat file:

set DEFAULT_JAVA_OPTS=-server -Xmx<NewMaxValue>M.

I feel like modifying the bat file is not the best solution. Additionally, none of the config files seem to have a place to put this.

Thanks


(At least) in karaf 2.2.10:

If running karaf through bin/start

As Ford Guo pointed out, memory values could be configured in the bin/setenv file:

export JAVA_MIN_MEM=256M # Minimum memory for the JVM
export JAVA_MAX_MEM=1024M # Maximum memory for the JVM
export JAVA_PERM_MEM=128M # Minimum perm memory for the JVM
export JAVA_MAX_PERM_MEM=256M # Maximum memory for the JVM

If running karaf as a service (karaf-service)

In this case any exported variable seems to be ignored.

The maximum java heap size could be defined in the etc/karaf-wrapper.conf:

# Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=1024


Updating to Karaf 2.2.3 reveals a new bat file.

if "%JAVA_MIN_MEM%" == "" (
    set JAVA_MIN_MEM=128M
)

if "%JAVA_MAX_MEM%" == "" (
    set JAVA_MAX_MEM=512M
)

if "%JAVA_PERM_MEM%" == "" (
    set JAVA_PERM_MEM=16M
)

if "%JAVA_MAX_PERM_MEM%" == "" (
    set JAVA_MAX_PERM_MEM=64M
)

This means one can just create a system variable instead of modifying the bat file.


That what I would do in your situation.

I have seen people suggest using a service start which allows you define the the command line arguments.

I liked using the webconsole so I changed it so it read a karaf.vmoptions file for the applications it starts. This requires patching the code, but it turned out to be very useful.


in the bin directory ,there is a setenv(.bat) file, you can set the max/min mem in there.


setenv wasnt loaded for me (using the karaf wrapper), so I put it into the wrapper config: (/opt/apache-servicemix-6.1.3/etc/karaf-wrapper.conf in my case)

# JVM Parameters            
# note that n is the parameter number starting from 1.
wrapper.java.additional.1=-Dkaraf.home=%KARAF_HOME%
wrapper.java.additional.2=-Dkaraf.base=%KARAF_BASE%
wrapper.java.additional.3=-Dkaraf.data=%KARAF_DATA%
wrapper.java.additional.4=-Dkaraf.etc=%KARAF_ETC%
wrapper.java.additional.5=-Dcom.sun.management.jmxremote
wrapper.java.additional.6=-Dkaraf.startLocalConsole=false
wrapper.java.additional.7=-Dkaraf.startRemoteShell=true
wrapper.java.additional.8=-Djava.endorsed.dirs=%JAVA_HOME%/jre/lib/endorsed:%JAVA_HOME%/lib/endorsed:%KARAF_HOME%/lib/endorsed
wrapper.java.additional.9=-Djava.ext.dirs=%JAVA_HOME%/jre/lib/ext:%JAVA_HOME%/lib/ext:%KARAF_HOME%/lib/ext

# added by me
wrapper.java.additional.10=-XX:PermSize=512m 
wrapper.java.additional.11=-XX:MaxPermSize=512m 

Check prior to the restart:

# get process id of you running instance
jps -lvm
# or
ps aux | grep java

# check memory before and after restarting the service to see wether it changed
jmap -heap $MY_PID 2>/dev/null | sed -ne '/Heap Configuration/,$p';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜