quick-perf / quickperf

QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties
https://github.com/quick-perf/doc/wiki/QuickPerf
Apache License 2.0
488 stars 65 forks source link

Add @ExpectNoInflaterMemoryLeak #98

Open jeanbisutti opened 4 years ago

jeanbisutti commented 4 years ago

java.util.zip.Inflater can cause non-heap memory leaks, as explained in this presentation. They can be detected during the application execution thanks to the Leakchecker project. This issue aims to provide an @ExpectNoInflaterMemoryLeak annotation in QuickPerf to detect this memory leak as soon as possible. The @ExpectNoInflaterMemoryLeak will be based on the Leakchecker project. This project has an Apache 2.0 license so that it is ok to detect inflater memory leak in the same way in QuickPerf project. Both in QuickPerf source code and QuickPerf documentation, we will take care of mentioning the Leakchecker project.

This issue is focussed on memory leaks that could come from Inflater. Later, we could detect other kinds of potential memory leaks, such as those that could be raised from ObjectInputStream.

loicmathieu commented 4 years ago

Tomcat has a lot of memory leak protections since version 7: https://cwiki.apache.org/confluence/display/TOMCAT/MemoryLeakProtection

Maybe we can create multiple memory leak detection based on those examples. This could be a very cool addition to what quickperf already does!

lhotari commented 3 years ago

Btw. There is also Leak Canary from Square for detecting memory leaks. It's originally developed for Android apps, but there is some support for applying it for JVM apps: https://square.github.io/leakcanary/recipes/#detecting-leaks-in-jvm-applications . Perhaps some parts could be reused in QuickPerf?

jeanbisutti commented 3 years ago

I ignored that Leak Canary could work with a JVM app. It would be interesting to reuse the Leak Canary HeapAnalyzer in QuickPerf.

jeanbisutti commented 3 years ago

Information coming from interesting Twitter conversations about Leak Canary:

jeanbisutti commented 3 years ago

JFR may reveal some heap memory leaks with the help of the Old Object Sample event: http://hirt.se/blog/?p=1055

QuickPerf can trigger JFR profiling and retrieve JFR events.

However, the Old Object Sample event was introduced in JDK 10. So, the heap leak detection would only work from this JDK version.