开发者

How to use MemoryPoolMXBean

开发者 https://www.devze.com 2023-01-10 18:09 出处:网络
We develop a server and we want to program congestion control into it. What we want to do is detect when free heap is below a certain threshold开发者_如何学编程 and stop accepting new data until free

We develop a server and we want to program congestion control into it. What we want to do is detect when free heap is below a certain threshold开发者_如何学编程 and stop accepting new data until free memory goes up again. Our first approach used runtime.freeMemory. This caused false positives as free heap went below the threshold before GC kicked in. I found a similar question on this site and the answer was to use MemoryPoolMXBean. This looks like the right way since we can get a notification when free memory AFTER GC is below a thershold. But... what pool to monitor? I don't want my implementation to be dependent on the type of GC the JVM decided to use. One option would be to sum the usage of all heap memory pools and use that as a metric. Is this a good solution?

Thanks, Doron


We tried the approach I described in my question: we are monitoring all the heap type memory pools, summing up their free space. Once the total free space goes below the threshold we go into congestion mode. We did extensive testing and it works great. So I guess I can mark this as answered.

0

精彩评论

暂无评论...
验证码 换一张
取 消