Kamal rajput
Kamal rajput

Reputation: 11

Predicting memory consumption of java components

I am currently working on an event driven System with multiple components running. Recently , I have received an urgent requirement to identify the memory consumption of java components running , so that we can give a brief idea of memory requirements before it is getting deployed on UAT/customer production environments.

Do we have any API using which Deep retained size can be calculated or a formula can be provided using which memory requirements can be computed.

Any ideas on this will surely help.

I have seen some API's ( java instrumentation Api) using which Shallow size can be calculated , but this will not suffice my need. I also found java Assist using which java byte code can be modified at runtime.

Upvotes: 0

Views: 80

Answers (2)

Erik
Erik

Reputation: 2051

Enable garbage collection logging and analyze the log. As a bonus you will also be able to identify (and fix) aberrant behaviour.

To turn on gc logging, use the following flags:

-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCCause -Xloggc:/gc-%t.log

This log file can then be handled in a number of tools like Censum from JClarity or uploaded to https://gceasy.io/ for easy analysis. Note that you will see the memory consumption as a whole for the app, not a breakdown. For that you will have to use something like VisualVM mentioned above.

Upvotes: 0

e.g78
e.g78

Reputation: 697

To identify the memory consumption of a java aplication, you can use a profiler. In jdk 6 or greater you can find jvisualvm (https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jvisualvm.html).

With jvisualvm, you can attach to a java process and, in sampler tab, you can see the memory consumed grouped by class type. There are even other powerful profilers (JProfiler is one of them)

Upvotes: 1

Related Questions