Locating online OOM (out of memory)

There is an exception of OutOfMemoryException, what may be the reason? How to quickly locate?

cause of OOM

1. Too many applications at one time

 Change the number of application objects

For example, when querying the data list, it is possible to take out all the data in the database at one time. If the amount of data reaches tens of millions, all the data is put into the List, which may cause memory overflow.

2. Memory resources are exhausted and not released

Find the unreleased object and release it

For example, using threads or database queries, in the case of high concurrency, continuously creating threads and jdbc Connections, but not releasing them, will cause memory overflow over time.

You can use the idea of ​​pooling. At most, you only apply for fixed resources, and when you use them, you block them and don't apply again.

3. Insufficient resources

jmap -heap View heap information

How to locate by dump

1. The system has OOM hanged

During OOM, a heap dump file will be exported to the specified file path. (It will record all the object information in the running of the program, which takes up a lot of disk space)

set in advance

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=路径

 2. There is no OOM during system operation 

Export dump file: (can be debugged through the Arthas tool)

jmap -dump:format=b,file=xxx.hprof 进程id

Can cause GC STW

The running program will export the dump file without uploading it. Only when it receives frequent fullgc or high CPU Load alarms will it export the dump file to the server

3. The dump file is combined with jvisualvm to count

View the most business-related objects --> find GCRoot --> view thread stack

 

Guess you like

Origin blog.csdn.net/xzxailh/article/details/128995447