How to use MemoryPoolMXBean

We are developing a server, and we want to program congestion control. We want to determine when the free heap is below a certain threshold, and stop accepting new data until the free memory returns again. Our first approach used runtime.freeMemory. This caused false positives, as the free heap fell below the threshold before the HA exploded. I found a similar question on this site, and the answer was to use MemoryPoolMXBean. This seems like the right way, as we can be notified when the free memory AFTER the GC is below the mark. But ... what is the monitoring pool? I do not want my implementation to depend on the type of GC that the JVM decided to use. One option is to summarize the use of all heap memory pools and use this as an indicator. This is a good decision?

Thanks Doron

+4
source share
1 answer

We tried the approach that I described in my question: we control all heap-type memory pools by summing their free space. As soon as the total free space falls below the threshold, we will switch to overload mode. We have done extensive testing and it works great. Therefore, I think I can mark this as an answer.

0
source

All Articles