I've deployed an application in tomcat 7.0.55 for testing.I want to capture whether "HeapDumpOnOutOfMemoryError" is occurring or not . Following are my JVM parameters.
JAVA_OPTS="-server -Xms512M -Xmx2048M -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ThreadStackSize=512 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/apps/dumps/"
I don't see any file under the directory. Does it create a file under the directory or i've to manually create a file to append ?
You can use it as below :
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=
You can also manually generate a memory map using jmap if you know the process id:
jmap -J-d64 -dump:format=b,file=
You can use JHat to analyze the dump.
jhat "path to dump file".
By default the heap dump is created in a file called java_pid.hprof in the working directory of the VM, as in the example above. You can specify an alternative file name or directory with the -XX:HeapDumpPath= option. For example -XX:HeapDumpPath=/disk2/dumps will cause the heap dump to be generated in the /disk2/dumps directory.
Check if it is a permissions issue to write to the configured folder /apps/dumps/.
For reference -
https://blog.gceasy.io/2015/08/14/how-to-capture-heap-dump-jmap/
https://blogs.oracle.com/LuzMestre/entry/how_to_collect_a_heap
Related
I am facing a issue in which my heapdump is more than 2gb or maybe even 3gb is some cases , Now the problem is the heap dump gets created in a location (/home) which is of around 1gb only so after 1gb of heapdump the server gets deadlock(No other process can run)
I just want to change the location of the Heapdump.
I am running my code on unix server , and increasing the size of /home dir is not an option.
I have tried using -XX:HeapDumpPath but it is not working.
Please help me out here.
You should use -XX:HeapDumpPath='your location' according to http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html#DebuggingOptions
JAVA_OPTS="$JAVA_OPTS -Xdump:heap:label=/dumps/heapdump.%Y%m%d.%H%M%S.%pid.%seq.phd"
JAVA_OPTS="$JAVA_OPTS -Xdump:java:label=/dumps/javacore.%Y%m%d.%H%M%S.%pid.%seq.txt"
JAVA_OPTS="$JAVA_OPTS -Xdump:system:label=/dumps/core.%Y%m%d.%H%M%S.%pid.%seq.dmp"
JAVA_OPTS="$JAVA_OPTS -Xdump:snap:label=/dumps/Snap.%Y%m%d.%H%M%S.%pid.%seq.trc"
(Optional) JAVA_OPTS="$JAVA_OPTS -Xdump:what"
You can change the JAVA_OPTS env variable or simple add individual -Xdump cmds from where you are running the code.
like
java -d64 -Xdump:heap:label=/${INFA_ROOT}/temp/heapdump.%Y%m%d.%H%M%S.%pid.%seq.phd -Xmx4g ...rest of the arrgs.
I am getting this error in tomcat server.
Exception in thread "http-bio-8080-exec-17"
Exception in thread "http-bio-8080-exec-2"
Exception in thread "http-bio-8080-exec-15"
Exception in thread "http-bio-8080-exec-20"
Exception in thread "http-bio-8080-exec-18"
java.lang.OutOfMemoryError: Java heap space.
I have seen MAT but how do I generate the .hprof file in my Tomcat server.
Thank you.
to remove the error edit the file
/etc/default/tomcat7
replace with:
JAVA_OPTS="-Djava.awt.headless=true -Xmx1280m -XX:+UseConcMarkSweepGC"
Then restart the web server.
Xmx is the new maximum size of memory and it should be affordable by your machine.
add this line to /path/to/tomcat/bin/setenv.sh (if doesn't exist create it) :
CATALINA_OPTS="$CATALINA_OPTS -server -Xms256m -Xmx1024m"
this increases tomcat's heap size to 1024MB.
Solution as per your OS:
if Ubuntu:
open .bashrc file available in user home folder (it is hidden) and Add or Edit one line among last 2-3 lines:
export CATALINA_OPTS="-Xms512m -Xmx1024m"
else Windows:
In your environment variables add/edit
CATALINA_OPTS = "-Xms512m -Xmx1024m"
Go to /bin and create a file named setenv.sh for Linux systems or setenv.bat for Windows.
Inside the setenv file, use the following format to set the heap size using the following parameters:
-Linux:
export CATALINA_OPTS="-Xms4096M -Xmx4096M"
-Windows:
set CATALINA_OPTS=-Xms4096M -Xmx4096M
Make sure both the values match for minimum and maximum.
Save the file and restart Tomcat.
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
BACKGROUND: I have a web Project which uses JSP. The IDE is Eclipse.
The configuration of tomcat is: Automatically publish when resources change and publishing interval is "1 second".
A property file in the classes folder which used to save some settings.It also can be dynamically modified by the servlet. The modify operation is trigerred by the save button in the JSP.
PROBLEM: After several save operation, Tomcat come with java.lang.OutOfMemoryError: PermGen space.
LOG MESSAGE
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1815)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:108)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:58)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1064)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4238)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3083)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:404)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1279)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1580)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1580)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1560)
at java.lang.Thread.run(Thread.java:662)
Tomcat does need a lot of permgen. 512m is not an unreasonable max. However it only delays the hot-deploy leak. Permgen will grow ~25mb per hotdeploy, which, in Eclipse, might be every time you save a Java file. 512m disappears fast if you have a Ctrl+S twitch like me.
The solution: allow Java to kick class definitions out of memory, i.e., garbage collect byte code. Add these along with your boosted permgen size:
-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC
You may set environment variable named : "JAVA_OPTS" and set value of it as follows -Xms256m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m
FOR ECLIPSE
Go to server properties
Go to platform
Now in VM argument write this
-Xms256m -Xmx256m -XX:PermSize=256m -XX:MaxPermSize=512m
FOR NETBEANS
Go to Netbeans folder/etc/
open netbeans.config in any editor
edit this line as
netbeans_default_options="-J-client -J-Xss256m -J-Xms256m -J-XX:PermSize=256m -XX:MaxPermSize=512m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true"
Thats all
setting like this:
-Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m
Just configure it from the apache tomcat interface:
start C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\Tomcat8w.exe (or you may just search in windows start for "Configure Tomcat");
Go to Java tab;
Set the required space in the input fields:
Just to add for Windows, if someone is still stuck:--
Open catalina.bat file (located at Apache tomcat installation folder/bin)
Set JAVA_OPTS as follows in the very start(before actually its first use anywhere in the file):--
set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m
Restart Tomcat and its done.
You can find nice explanation here
Tomcat server runs different JAVA and the eclipse runs in different JAVA.
So adding -XX:MaxPermSize=512m to eclipse.ini will help resolving this issue. Follow the below steps to add this to tomcat server:
Double click server in eclipse
open launch configuration
add "-XX:MaxPermSize=512m" to VM arguments in the Arguments tab.
I have an upload files scenario in my project. When I'm trying to upload the large files it's giving me an OutOfMemory error. That error is related to Java heap size.
How can you increase the heap size in Java and which file do I need to alter for this? I'm using jboss 5.1 server for running my application.
You can set it as JVM arguments the usual way, e.g. -Xms1024m -Xmx2048m for a minimum heap of 1GB and maximum heap of 2GB. JBoss will use the JAVA_OPTS environment variable to include additional JVM arguments, you could specify it in the /bin/run.conf.bat file:
set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m"
However, this is more a workaround than a real solution. If multiple users concurrently uploads big files, you'll hit the same problem sooner or later. You would need to keep increasing memory for nothing. You should rather configure your file upload parser to store the uploaded file on temp disk instead of entirely in memory. As long as it's unclear which parser you're using, no suitable answer can be given. However, more than often Apache Commons FileUpload is used under the covers, you should then read the documentation with "threshold size" as keyword to configure the memory limit for uploaded files. When the file size is beyond the threshold, it would then be written to disk.
On wildfly 8 and later, go to /bin/standalone.conf and put your JAVA_OPTS there, with all you need.
Edit the following entry in the run.conf file. But if you have multiple JVMs running on the same JBoss, you might want to run it via command line argument of -Xms2g -Xmx4g (or whatever your preferred start/max memory settings are.
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms2g -Xmx4g -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true
Use -Xms and -Xmx command line options when runing java:
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
For more help type java -X in command line.
I have mentioned the configuration changes needed for the increase of heap size in Windows or Linux environments.
Linux:
bin/standalone.conf
Check for the following line,
JAVA_OPTS
and change it accordingly to suit your heap size needs
-Xms1303m: initial heap size in megabytes
-Xmx1303m: maximum heap size in megabytes
JAVA_OPTS="-Xms1024M -Xmx2048M -XX:MaxPermSize=2048M -XX:MaxHeapSize=2048M"
Windows:
bin/standalone.conf.bat
JAVA_OPTS="-Xms1024M -Xmx2048M -XX:MaxPermSize=2048M -XX:MaxHeapSize=2048M"
Now restart the server and it will work without prompting any heap size errors.
For more information you can refer this link below.
https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/5/html/getting_started_guide/adjust_memory_settings
Look in your JBoss bin folder for the file run.bat (run.sh on Unix)
look for the line
set JAVA_OPTS, (or just JAVA_OPTS on Unix) at the end of that line add -Xmx512m. Change the number to the amount of memory you want to allocate to JBoss.
If you are using a custom script to start your jboss instance, you can add the set JAVA_OPTS option there as well.
In my case, for jboss 6.3 I had to change JAVA_OPTS in file jboss-eap-6.3\bin\standalone.conf.bat and set following values -Xmx8g -Xms8g -Xmn3080m for jvm to take 8gb space.
Add following option in jboss in bin/standalone.conf.bat
set "JAVA_OPTS=-Xms1G -Xmx1G -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=1024m"
What to change?
set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m"
Where to change? (Normally)
bin/standalone.conf(Linux) standalone.conf.bat(Windows)
What if you are using custom script which overrides the existing settings? then?
setAppServerEnvironment.cmd/.sh (kind of file name will be there)
More information are already provided by one of our committee members!
BalusC.
You can increase or set the heap size configuration i.e. -Xms/Xmx or any other JVM options in the JBoss application server in JAVA_OPTS JVM options in standalone.conf(Linux) & standalone.conf.bat file in Windows.
JAVA_OPTS="-Xms2048M -Xmx2048M"