How to detect the heap size from within a Scala program?

204 views Asked by At

I have a graph with about 6000 nodes (pedigree). The program should determine all ways between two given nodes (relationship). Depending on the position of the start and destination nodes, the number of paths to be searched can be very large. Now I want to monitor the free heap so that I can adjust the search strategy depending on the size still available. How can I determine the size of the free heap?

Translated with www.DeepL.com/Translator (free version)

1

There are 1 answers

1
Daniel Hinojosa On

Assuming since you included this post in the [scala] tag and you mentioned this is a Scala application, you are running in the JVM. If you just need simple monitoring, you would just need JVisualVM or the Visual Flight Recorder as you are running your JVM. I personally use JVisualVM. Works great. I believe the flight recorder will record it's heap use over time so you can do a review and maybe wire it up in a performance test.

Below is an image of the flight recorder.

Flight Recorder

Below is an image of JVisualVM.

JVisualVM