0

I am running one of my Spring boot application (CRUD operations) in prod and it's taking around 400M memory. I haven't defined any Xmx and Xms values.

How can I figure out if this memory consumption is Normal or high. Is it recommended to use Xmx and Xms values? If yes, How to calculate those values?

James Z
  • 12,209
  • 10
  • 24
  • 44
Manish
  • 1,274
  • 3
  • 22
  • 59

2 Answers2

1

How can I figure out if this memory consumption is Normal or High.

It is not possible to "figure it out". Memory consumption depends on what your application is, what it does, and the strategies it uses.

For example, an application may use a lot of the memory:

  • because it employs algorithms that require a large in-memory data structures, or
  • because it gets a significant performance benefit by caching things in memory, or
  • because it is poorly designed / implemented; e.g. it has memory leaks, uses too many threads, unnecessarily creates large in-memory data structure, and so on.

So Normal vs High is highly context dependent. And a matter of opinion.

Is it recommended to use Xmx and Xms values?

It depends on the application. For example, if you don't specify the Xmx value, a platform-specific formula is used to calculate a default value; see How is the default max Java heap size determined?. That default can be appropriate.

If yes, how to calculate those values?

Empirically. You try different values and observe what happens.

It is worth noting that the JVM needs a proportion of "extra" space so that the GC can work efficiently1. So even if it was possible to calculate the aggregate of the sizes of all of the application's objects, the JVM needs substantially more memory than that for efficiency.


1 - Garbage collectors work by "marking" the heap to determine what is reachable, and then reclaiming the objects that are not reachable. The work of marking is proportional to the number of reachable objects and references. When the heap is close to full of reachable objects, the GC will spend lots of time marking, and not find many objects that can be deleted. Clearly, the GC will be more efficient if it can finds lots of actual garbage to reclaim each time it runs. This implies that the heap needs to be large enough to hold lots of garbage in addition to all of the reachable objects.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

That flags is fully recommended to use especially in production, for avoiding the OutOfMemory Error. But sometimes happens memory leak. This can eat heap memory. You can use java profiler tool for monitoring your jvm heap, figure out the memory leaks and understand for you which configurations will be good. If you are using Intellij you can you the integration of Java profiler: Intellij<->JProfiler

The Xms flag has no default value, and Xmx typically has a default value of 256 MB. Your total heap size must not exceed the amount of physical RAM available. You must leave some physical RAM for other applications to run on your machine. You should set Xms and Xmx to the same value for best performance. These options determine your total heap size.