4

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
daramasala
  • 3,040
  • 2
  • 26
  • 33
  • Your solution should be already good enough, I don't think there is a better one. – Heri Sep 10 '10 at 23:00
  • Yes, it appears that summing the free memory in all heap memory pools works. It is not 100% accurate but it testing proved it enough for our congestion control. – daramasala Oct 21 '10 at 13:17

1 Answers1

0

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.

daramasala
  • 3,040
  • 2
  • 26
  • 33