Use performance testing to troubleshoot high memory usage on service online

Problem: The server memory usage remains high.
Clue: ImportCheckFailedEntity has a high number of surviving instances (used in import files), and TreeMap and ReentrantLock have a high number of surviving instances (used in excel import components).
Reasons:
1. ThreadLocal stored in thread pool threads Data memory leaks. Because the life of threads in the thread pool is very long, using ThreadLocal in the threads of the thread pool must call its clear method to clear the data in the TreadLocal to release the memory;
2. When the OPCPackage in the Excel import component is used up, call the close method to release the read-write lock Locked data
Scope:
1. The function of importing excel files using poi (including real-time or asynchronous)
2. The function of importing files using TreadLocal (batch processing asynchronous import is used)
. Pressure test effect after repair: Yes 10 minutes after importing the interface pressure test, grab the heap memory information and analyze, there is no excel data object information. During the stress test, the memory increase was extremely small, and the increase trend was smooth and slow (indicating that it can be recovered by ygc)
I chose an import function for testing, and the optimization methods for other import functions are the same.

jstate -gcutil pid 1000 100 #jstat抓取gc信息,每隔1秒打印一次,打印100次
jstack pid jstack #抓取进程线程信息
jmap -heap pid #查看堆内存分配信息

Guess you like

Origin blog.csdn.net/feifeixiongxiong/article/details/110123321