Good day.
I have a JAVA application that writes a heapdump when an OutOfMemoryError ocurrs, the location of the heapdump is inconvenient and I'm trying to figure out if there's a way I can configure the automatic heapdump to place the dump file in a remote location other than the original server.
I know that for jmap there is an option that looks like this:
jmap [ option ] [server-id#]remote-hostname-or-IP
(see https://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.html)
But what I'm trying to do is directly on the VM options:
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=server-ip/server-directory
Related
I have an taken a core dump file from a machine, with file size 2GB. I can open this file with gdb and see the processes that were running when I took the core file. I want though to convert this file into a heap dump in order to see more useful information. I tried running the below commands without any success. Does anyone have an idea why the file is not converted into heap dump? How can I perform this action?
I tried the bellow commands but I get errors and the file never is being created.
jmap -heap:format=b file=jvmcore.hprof /usr/lib/jvm/jdk1.5.0_22/ jvm.core Usage: jmap \[option\] \<pid\> (to connect to a live java process) or jmap \[option\] \<executable\> \<core\> (to connect to a core file) or jmap \[option\] \[server_id#\]\<remote server IP or hostname\> (to connect to a remote debug server) where option must be one of: \<no option\> to print same info as Solaris pmap \-heap to print java heap summary \-heap:format=b to dump java heap in hprof binary format \-histo to print histogram of java object heap \-permstat to print permanent generation statistics \-h | -help to print this help message
Same result as above i got with the following command:
jmap -heap:format=b file=jvmcore.hprof /usr/lib/jvm/jdk1.5.0_11/ jvm.core
And trying this command gets an error:
jmap -heap:format=b file=jvmcore.hprof jvm.core Attaching to core jvm.core from executable file=jvmcore.hprof, please wait... Error attaching to core file: Can't attach to the core file
I am running jMeter from the command line on a Mac. Today it threw an Out of memory, heap space error....
newbie$ sh jmeter.sh
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
at java.awt.image.Raster.createPackedRaster(Raster.java:455)
I know I need to increase the memory allocated to it, but not sure how. I looked at this post Unable to increase heap size for JMeter on Mac OSX and found that jMeter script file in the bin folder it mentions and made the below updates..
HEAP="-Xms1024m -Xmx2048m"
NEW="-XX:NewSize=512m -XX:MaxNewSize=1024m"
But I am still getting the out of memory error. Do I just need to give it more or am I changing in the wrong place? Could it be I need to restart my whole machine?
As far as I understand:
You made changes to jmeter script
You're launching jmeter.sh script
You want to know why the changes are not applied?
If you changed jmeter script why don't you just launch it as ./jmeter ?
If you need to start JMeter via jmeter.sh for any reason, run it as follows:
JVM_ARGS="-Xms1024m -Xmx2048m -XX:NewSize=512m -XX:MaxNewSize=1024m" && export JVM_ARGS && ./jmeter.sh
See Running JMeter User Manual chapter in particular and The Ultimate JMeter Resource List in general for the relevant documentation.
If you have trouble finding it in the logs, then
You can use
ps -ef | grep jmeter
this may give you the details( Not a mac user, but I thing ps -ef would work)
The other option is to use jvisualvm, it ships already with jdk, so no extra tool is required.Run the visualvm and the jmeter, you can guess the name of the application ( entry of jemter ) on the left pane of visualvm , click on it, and all the jvm details will be available.
After this you can confirm whether jmeter is availed with 2GB max Ram. And increase if needed.
There could be different possible reasons for OutOfMemory Error. If you have successfully changed the allocated memory/heap size and still getting the issue then you can look into following factors:
Listeners: Do not use 'TreeView' and 'TableView' Listeners in actual load test as they consume lot of memory. Best practice is to save results in .JTL file, which can be later used for getting different reports.
Non-GUI Mode: Do not use GUI mode while performing actual load test. Run test from command line.
For more, visit the following blog as it has some really nice tips to solve OutOfMemory issues in JMeter.
http://www.testingdiaries.com/jmeter-out-of-memory-error/
I am creating heap dump using below command:
jmap -dump:file=DumpFile.txt <process-id>
I have opened the generated file - DumpFile.txt but it is not in readable format.
So please let me know how to analyze the data in the generated file.
You should use jmap -heap:format=b <process-id> without any paths. So it creates a *.bin file which you can open with jvisualvm.exe (same path as jmap). It's a great tool to open such dump files.
You can use jhat (Java Heap Analysis Tool) to read the generated file:
jhat [ options ] <heap-dump-file>
The jhat command parses a java heap dump file and launches a webserver. jhat enables you to browse heap dumps using your favorite webbrowser.
Note that you should have a hprof binary format output to be able to parse it with jhat. You can use format=b option to generate the dump in this format.
-dump:format=b,file=<filename>
Very late to answer this, but worth to take a quick look at. Just 2 minutes needed to understand in detail.
First create this java program
import java.util.ArrayList;
import java.util.List;
public class GarbageCollectionAnalysisExample{
public static void main(String[] args) {
List<String> l = new ArrayList<String>();
for (int i = 0; i < 100000000; i++) {
l = new ArrayList<String>(); //Memory leak
System.out.println(l);
}
System.out.println("Done");
}
}
Use jps to find the vmid (virtual machine id i.e. JVM id)
Go to CMD and type below commands >
C:\>jps
18588 Jps
17252 GarbageCollectionAnalysisExample
16048
2084 Main
17252 is the vmid which we need.
Now we will learn how to use jmap and jhat
Use jmap - to generate heap dump
From java docs about jmap
“jmap prints shared object memory maps or heap memory details of a given process or core file or a remote debug server”
Use following command to generate heap dump >
C:\>jmap -dump:file=E:\heapDump.jmap 17252
Dumping heap to E:\heapDump.jmap ...
Heap dump file created
Where 17252 is the vmid (picked from above).
Heap dump will be generated in E:\heapDump.jmap
Now use Jhat
Jhat is used for analyzing the garbage collection dump in java -
C:\>jhat E:\heapDump.jmap
Reading from E:\heapDump.jmap...
Dump file created Mon Nov 07 23:59:19 IST 2016
Snapshot read, resolving...
Resolving 241865 objects...
Chasing references, expect 48 dots................................................
Eliminating duplicate references................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
By default, it will start http server on port 7000.
Then we will go to http://localhost:7000/
Courtesy : JMAP, How to monitor and analyze the garbage collection in 10 ways
If you use Eclipse as your IDE I would recommend the excellent eclipse plugin memory analyzer
Another option is to use JVisualVM, it can read (and create) heap dumps as well, and is shipped with every JDK. You can find it in the bin directory of your JDK.
VisualVm does not come with Apple JDK. You can use VisualVM Mac Application bundle(dmg) as a separate application, to compensate for that.
MAT, jprofiler,jhat are possible options. since jhat comes with jdk, you can easily launch it to do some basic analysis. check this out
If you just run jmap -histo:live or jmap -histo, it outputs the contents on the console!
I am using Tomcat server and I want to get a heap dump on Out of Memory error.
How can I do this by specifying parameters in the Catalina.bat file?
Also is there a way to specify the path where the dump file is stored?
According to this http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
you can use option -XX:HeapDumpPath=./java_pid<pid>.hprof.
You do not have to modify calatalina.bat or other scripts to add options to Tomcat. Just set system variable CATALINA_OPTS before running Tomcat.
I was told I can add the -XX:+HeapDumpOnOutOfMemoryError parameter to my JVM start up options to my JBoss start up script to get a heap dump when we get an out of memory error in our application. I was wondering where this data gets dumped? Is it just to the console, or to some log file? If it's just to the console, what if I'm not logged into the Unix server through the console?
Here's what Oracle's documentation has to say:
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.
You can view this dump from the UNIX console.
The path for the heap dump will be provided as a variable right after where you have placed the mentioned variable.
E.g.:
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${DOMAIN_HOME}/logs/mps"
You can view the dump from the console on the mentioned path.
I found it hard to decipher what is meant by "working directory of the VM". In my example, I was using the Java Service Wrapper program to execute a jar - the dump files were created in the directory where I had placed the wrapper program, e.g. c:\myapp\bin. The reason I discovered this is because the files can be quite large and they filled up the hard drive before I discovered their location.
If you are not using "-XX:HeapDumpPath" option then in case of JBoss EAP/As by default the heap dump file will be generated in "JBOSS_HOME/bin" directory.
If you only configure -XX:+HeapDumpOnOutOfMemoryError parameter then heapdump will be generated in JBOSS_HOME/bin directory for OpenJDK/Oracle JDK. If you are using IBM JDK then heapdump will be created under /tmp directory as phd file. -XX:HeapDumpPath option gives us more feasibility for configuring our custom headpump path location (-XX:HeapDumpPath=/my-custom-jboss-server-path/). It's recommended to have this parameters configured in your environment as it will collect heapdump on OutOfMemory error for analyzing the issue with memory leak of the application or checking any large object retention in the application.