简体   繁体   中英

Which java garbage collector we should use for spring boot with java 11 and Ubuntu 18

We have 10 spring boot applications which are running on ubuntu18 with 8GB RAM and Java 11.

We are running the apps using java garbage collector -XX:+UseSerialGC without restricting the heap space.

But after few days server memory fully consumed and server got hanged.

Do we need to restrict the heap memory if we are using garbage collector?

I have tried with other garbage collectors also but nothing working except +UseSerialGC.

The UseSerialGC is "ok-ish" (not good.) but will be blocking. Use the parallel one at least. Check https://www.baeldung.com/jvm-garbage-collectors for the differences.

That said,a different garbage collector isn't going to help you much if you have a genuine memory leak. You should probably profile your applications to see which instances of objects are not being recycled by the GC.

Check this article for Spring Boot: https://medium.com/illegalarguments/how-to-find-memory-leaks-in-spring-boot-592faf11d571

If you are exhausting the heap, you are exhausting the heap. Your choice of garbage collector will not help you.

Any garbage collector* will attempt clear up as much as possible when you've exhausted your heap, so if SerialGC couldn't make some space then none of the other collectors will be able to either.

You presumably have a memory leak. Take a heap dump and see what is consuming the most space. Start with the low hanging fruit - those which consume the most space. Maybe you have collections which you add to and never remove from. (for my projects, Map is usually the most common culprit).

Consider restarting your server periodically if possible to fully clear everything down.


*well, not quite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM