-2

We have a service that consumes ~600 MB in heap.

The current hosts we have, have 4 GB memory. By default JVM allots 25% of max heap size. So we're getting 1 GB of heap size.

We are seeing multiple brownouts, and I suspect the less memory we have for those. I added a host with 8 GB memory, and double the number of CPUs, and that host never browned out, thus further enforcing my theory.

Wanted to understand what is the optimal value of memory for a process taking 600MB heap.

Also wanted to understand how much it makes sense to increase the heap size.

I tried to increase initial heap size to 2GB, but the hosts crashed when I deployed the changes to them. Would it make sense to increase the heap size to 1.5 GB?

Any pointers appreciated.

Mooncrater
  • 4,146
  • 4
  • 33
  • 62
  • If 2GB wasn't enough what makes you think it only usies 600MB? – user207421 Apr 25 '22 at 04:53
  • 1
    As [already said at your older question](https://stackoverflow.com/questions/71963926/#comment127171943_71963926), we can’t tell you what configuration works for your server, not without any information about it and not on this site which is for *programming questions*. When your servers truly experience *brownouts*, your problem is even less connected to the Java application. Not even with the low memory. That’s a serious hardware problem. So it’s not surprising that a new hardware doesn’t have this problem, regardless of how much memory it has. – Holger Apr 25 '22 at 10:17

1 Answers1

1

The exact amount of memory needed for the heap is very specific to the application - you are better of trying multiple configurations and see yourself.

However, needing 4 GB for something that consumes about 600 MB is quite unusual. What are the other things that consume the host memory?

Note that JVM uses much more than just heap memory and this again can vary a lot from application to application. For an overview of various types of memory used by JVM I recommend this excellent answer: Java using much more memory than heap size (or size correctly Docker memory limit)

Finally, you can adjust the default allocation strategy (25% of available RAM) via -XX:MaxRAMPercentage flag - I typically set this to 60%, but for sure measure first!

Juraj Martinka
  • 3,991
  • 2
  • 23
  • 25