I am trying to set the JVM of the server I am working on, so it dumps a heap to file when an OOME occurs.
I know I have to add this option -XX:-HeapDumpOnOutOfMemoryError to the JVM arguments somewhere, but I can't figure how to do this.
FYI, I can access the server through PuTTY, so I am looking for a command line way of doing this.
The JVM I am using is OpenJDK64-Bit Server VM.
I don't know if that's relevant, but the application is a war file.
PS : ps -ef|grep java
tomcat 23837 1 0 Mar25 ? 00:03:46 /usr/lib/jvm/jre/bin/java -classpath :/usr/share/tomcat6/bin/bootstrap.jar:/usr/share/tomcat6/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat6/temp -Djava.util.logging.config.file=/usr/share/tomcat6/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start
EDIT :
I found something, correct me if I'm wrong : since I am using Tomcat, I decided to add these lines in the tomcat.conf file:
JAVA_OPTS=-XX:-HeapDumpOnOutOfMemoryError
JAVA_OPTS=-XX:HeapDumpPath=/root/dump
JAVA_OPTS=-Xmx20m
What do you think ?
This option from the HotSpot VM options. I would think it'd be the same in the OpenJDK VM but let me know if it's not.
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path to dump file>
You can also manually generate a memory map using jmap if you know the process id:
jmap -J-d64 -dump:format=b,file=<path to dump file> <jvm pid>
You can use JHat to analyze the dump.
jhat <path to dump file>
As mentioned by #CoolBeans, the JVM options to use are:
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path to dump file>
For setting this in tomcat, create a file named setenv.sh (setenv.bat for windows) under TOMCAT_HOME/bin directory & add the following line
export CATALINA_OPTS="$CATALINA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<path to dump file>"
CATALINA_OPTS is preferred for these kind of options as they need not be applied to the shutdown process.
Related
I have this VM with tomcat, java, and grails in it. I've been getting permgen errors so I looked around and found the solution:
set JAVA_OPTS="-Xms256m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m"
I use SSH to access the vm and type the arguments above. I suppose that would fix the problem. Thing is, I wanted to make sure that I did it correctly. So I searched again on how I could check the current permSize and this is the solution I got:
jinfo -flag MaxPermSize 6444
6444 is the pid, and as a response, I got this.
-XX:MaxPermSize=85983232
Question: Is the value of the maxPermSize in bytes? because, if it is, then that would mean that the java_opts command didn't work. I am expecting to get 512m but 85983232 bytes = 82 mb.. Or am I seeing it wrong..? Can anybody enlighten me on this? D:
You have to change the values in the CATALINA_OPTS option defined in the Tomcat Catalina start file. To increase the PermGen memory change the value of the MaxPermSize variable, otherwise change the value of the Xmx variable.
Linux & Mac OS: Open or create setenv.sh file placed in the "bin" directory. You have to apply the changes to this line:
export CATALINA_OPTS="$CATALINA_OPTS -server -Xms256m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m"
Windows:
Open or create the setenv.bat file placed in the "bin" directory:
set CATALINA_OPTS=-server -Xms256m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m
Don't put the environment configuration in catalina.bat/catalina.sh. Instead you should create a new file in CATALINA_BASE\bin\setenv.bat to keep your customizations separate of tomcat installation.
So you are doing the right thing concerning "-XX:MaxPermSize=512m": it is indeed the correct syntax. You could try to set these options directly to the Catalyna server files so they are used on server start.
Maybe this post will help you!
How to make sure that Tomcat6 reads CATALINA_OPTS on Windows?
Completely removed from java 8 +
Partially removed from java 7 (interned Strings for example)
source
When running JMeter, java server has the -Xmx value of only 512 MB. I tried to change it via following code in the jmeter.bat.sh file.
set HEAP=-server -Xms512m -Xmx6144m
set NEW=-XX:NewSize=512m -XX:MaxNewSize=6144m
also tried this:
set HEAP= -Xms512m -Xmx6144m
set NEW=-XX:NewSize=512m -XX:MaxNewSize=6144m
By checking the process after while JMeter is running I can see that java -sever doesn't recognize this setting.
If you are running jmeter startup script on Linux the syntax will be different, i.e:
HEAP="-Xms512m -Xmx6G"
as SET command is something Windows-specific
Alternatively you can define JVM_ARGS environment variable value like:
JVM_ARGS="-server -Xms512m -Xmx6G" && export JVM_ARGS
this way you won't need to edit files and/or restart JMeter.
Finally, you can launch JMeter jar directly like:
java -server -Xms512m -Xmx6G -jar ApacheJMeter.jar
See the following reference material:
Tuning Java Virtual Machines (JVMs)
JMeter Best Practices
9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure
Getting this kind of error on linux server in my project when i run my spring-hibernate project
i read the
Increase permgen space
someone replied to execute
-XX:MaxPermSize=128m
to increase of MaxPermSize but when i execute this command in in my
project under directory of classes i got an error
[root#server classes]# -XX:MaxPermSize=128m
-bash: -XX:MaxPermSize=128m: command not found
Initial SessionFactory creation failed.java.lang.OutOfMemoryError: PermGen space
How can I set MaxPermSize only for one particular project as I am working on live server some projects are live on that server so please suggest me right solution so that I can set MaxPermSize on live server
You misunderstood the answer on the original question.
When you run a Java program, you use a command like:
java [JVM arguments] ClassName [program arguments]
The --XX:MaxPermSize=128m part goes in the "JVM arguments" part - it is a directive to the JVM to allocate 128m of memory to the PermGen.
So you are supposed to edit the java command in your script and not put that argument on a separate line.
You should also consider upgrading to Java 8, in which Permgen no longer exists.
-XX:MaxPermSize=128m is a JVM argument, not a bash command.
On Linux when using -XX+HeapDumpOnOutOfMemoryError the hprof file produced is owned by the user under which the java process is running and has permissions of 600.
I understand that these permissions are best security wise but is it possible to override them?
You can start the JVM with
java -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError="chmod g+r java_pid*.hprof" {mainclass} {args}
The command runs after the heap dump is created. This will allow group read access to all heap dump files in the current directory for example.
The -XX:OnOutOfMemoryError parameter doesn't work for me with spaces in the command on JRE 7(1.7.0_72). But pointing to a shell script (without spaces) does. Example:
-XX:OnOutOfMemoryError="/path/to/shell/script.sh"
I was trying to adjust initial heap size of a tomcat 7 (CentOS, java -version: 1.6.0_25-b06) instance by adding the following line to catalina.sh:
export CATALINA_OPTS="-Xms=512M -Xmx=1024M"
Starting up tomcat fails and logs the following message to catalina.out:
Invalid initial heap size: -Xms=512m
Could not create the Java virtual machine.
What is wrong with these options?
You must not use =. Simply use this:
export CATALINA_OPTS="-Xms512M -Xmx1024M"
Use following command to increase java heap size for tomcat7 (linux distributions) correctly:
echo 'export CATALINA_OPTS="-Xms512M -Xmx1024M"' > /usr/share/tomcat7/bin/setenv.sh
You might no need to having export, just add this line in catalina.sh :
CATALINA_OPTS="-Xms512M -Xmx1024M"
setenv.sh is better, because you can easily port such configuration from one machine to another, or from one Tomcat version to another. catalina.sh changes from one version of Tomcat to another. But you can keep your setenv.sh unchanged with any version of Tomcat.
Another advantage is, that it is easier to track the history of your changes if you add it to your backup or versioning system. If you look how you setenv.sh changes along the history, you will see only your own changes. Whereas if you use catalina.sh, you will always see not only your changes, but also changes that came with each newer version of the Tomcat.
Go to "Tomcat Directory"/bin directory
if Linux then create setenv.sh else if Windows then create setenv.bat
content of setenv.* file :
export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx8192m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"
after this restart tomcat with new params.
explanation and full information is here
http://crunchify.com/how-to-change-jvm-heap-setting-xms-xmx-of-tomcat/
After spending good time time on this . I found this is the what the setenv.bat must look like . No " characters are accepted in batch file.
set CATALINA_OPTS=-Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=768m
echo hello "%CATALINA_OPTS%"
Take care with change in Debian distributions! I tried to change CATALINA_OPTS in my Debian 7 and the results where that tomcat didn't start anymore. Thus I solved this issue by changing the property JAVA_OPTS in place of CATALINA_OPTS, like this
export JAVA_OPTS="-Xms512M -Xmx1024M"
Just came across this and I've implemented Nathan's solution:
add the line (changing the values as required):
export JAVA_OPTS="-Xms512M -Xmx1024M"
to /usr/share/tomcat7/bin/setenv.sh
If that file doesn't exists then create it and
chown root:root it
chmod 755 it
And then restart tomcat and
check it with
ps aux | grep logging
Which should just pick up the instance and show the java parms
It works even without using 'export' keyword. This is what i have in my setenv.sh (/usr/share/tomcat7/bin/setenv.sh) and it works.
OS : 14.04.1-Ubuntu
Server version: Apache Tomcat/7.0.52 (Ubuntu)
Server built: Jun 30 2016 01:59:37
Server number: 7.0.52.0
JAVA_OPTS="-Dorg.apache.catalina.security.SecurityListener.UMASK=`umask` -server -Xms6G -Xmx6G -Xmn1400m -XX:HeapDumpPath=/Some/logs/ -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:SurvivorRatio=8 -XX:+UseCompressedOops -Dcom.sun.management.jmxremote.port=8181 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTS="$JAVA_OPTS -Dserver.name=$HOSTNAME"
If it's not work in your centos 7 machine "export CATALINA_OPTS="-Xms512M -Xmx1024M"" then you can change heap memory from vi /etc/systemd/system/tomcat.service file then this value shown in your tomcat by help of ps -ef|grep tomcat.