First, use the jdk built-in tool jmap dumping (dump) java memory heap data to local files. The jmap dump command format is as follows:
Jmap-dump: <dump-options> <pid>
<Dump-options> indicates the dump option, and <pid> indicates the process ID of the java application that requires dump.
Dump-options can have the following three parameters, separated by commas:
Live: only dump active objects. If not specified, dump all objects
Format = B, byte stream format
File = <file>, <file> is the storage path of the dump file.
The following is an example of the dump command:
Jmap-dump: format = B, file = heap. bin 8023
After dump is complete, use the Eclips tutorial e Memory Analyzer to open the dump file for analysis. Eclipse Memory Analyzer is a java Memory heap dump file analysis tool that can generate Memory analysis reports (including Memory leakage Leak Suspects ). The following figure shows the Top Consumers chart after the analysis is complete:
When you see these two charts, the problem becomes clearer. The data node com. sleepycat. je. tree. BIN in berkeley db occupies a large amount of memory, leading to memory overflow. To improve access efficiency, berkeley db caches a large number of nodes. The cache size limit can be set in EnvironmentConfig. The default value is 60% of the jvm memory size limit. In this application, five EnvironmentImpl are used, and the cache size is not set separately, the total cache limit is 300% of the jvm memory limit (the BIN node in the chart occupies 94.55% of the memory), far exceeding the java memory limit. As the service runs, more and more cached data leads to memory overflow errors. Therefore, you can set an appropriate cache size limit for each EnvironmentImpl to avoid memory overflow again.