Why is the total available memory displayed in the Service Registry dashboard not the same across all service instances?
search cancel

Why is the total available memory displayed in the Service Registry dashboard not the same across all service instances?

book

Article ID: 297203

calendar_today

Updated On:

Products

Support Only for Spring

Environment

Product Version: Other

Resolution

Checklist:
As shown in the images below, the total available memory for two service registry instances created using identical configuration are different. This is because the total available memory available to the container is dependent on the host environment. It is a run time value that cannot be configured through the tile or the cli.

Service Registry Dashboard of one instance -

Screen Shot 2021-08-13 at 4.08.19 PM.png

Service Registry Dashboard of another instance -
Screen Shot 2021-08-13 at 4.08.53 PM.png



Official documentation at this link https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#totalMemory(), describes this in detail, as shown below.
 
public long totalMemory()
Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.

Note that the amount of memory required to hold an object of any given type may be implementation-dependent.

Returns:
the total amount of memory currently available for current and future objects, measured in bytes.


 
 The total-avail- memory, num-of-cpus and current-memory-usage displayed on the dashboard are computed as follows.
int totalMem = (int) (runtime.totalMemory() / 1048576);

int freeMem = (int) (runtime.freeMemory() / 1048576);

int usedPercent = (int) (((float) totalMem - freeMem) / (totalMem) * 100.0);



result.generalStats.put("num-of-cpus",

String.valueOf(runtime.availableProcessors()));

result.generalStats.put("total-avail-memory",

String.valueOf(totalMem) + "mb");

result.generalStats.put("current-memory-usage",

String.valueOf(totalMem - freeMem) + "mb" + " ("

+ usedPercent + "%)");