Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sensible Xmx/GC defaults for a microservice with a small heap

At my company we are trying an approach with JVM based microservices. They are designed to be scaled horizontally and so we run multiple instances of each using rather small containers (up to 2G heap, usually 1-1.5G). The JVM we use is 1.8.0_40-b25.

Each of such instances typically handles up to 100 RPS with max memory allocation rate around 250 MB/s.

The question is: what kind of GC would be a safe sensible default to start off with? So far we are using CMS with Xms = Xmx (to avoid pauses during heap resizing) and Xms = Xmx = 1.5G. Results are decent - we hardly ever see any Major GC performed.

I know that G1 could give me smaller pauses (at the cost of total throughput) but AFAIK it requires a bit more "breathing" space and at least 3-4G heap to perform properly.

Any hints (besides going for Azul's Zing :D) ?

like image 845
Rafal G. Avatar asked Nov 04 '25 21:11

Rafal G.


2 Answers

Hint # 1: Do experiments!

Assuming that your microservice is deployed at least on two nodes run one on CMS, another on G1 and see what response times are.

Not very likely, but what if you can find that with G1 performance is so good that need half of original cluster size?

Side notes:

  • re: "250Mb/s" -> if all of this is stack memory (alternatively, if it's young gen) then G1 would provide little benefit since collection form these areas is free.
  • re: "100 RPS" -> in many cases on our production we found that reducing concurrent requests in system (either via proxy config, or at application container level) improves throughput. Given small heap it's very likely that you have small cpu number as well (2 to 4).
  • Additionally there are official Oracle Hints on tuning for a small memory footprint. It might not reflect latest config available on 1.8_40, but it's good read anyway.
like image 114
Petro Semeniuk Avatar answered Nov 07 '25 11:11

Petro Semeniuk


Measure how much memory is retained after a full GC. add to this the amount of memory allocated per second and multiply by 2 - 10 depending on how often you would like to have a minor GC. e.g. every 2 second or every 10 second.

E.g. say you have up to 500 MB retained after a full GC and GCing every couple of seconds is fine, you can have 500 MB + 2 * 250 MB, or a heap of around 1 GB.

The number of RPS is not important.

like image 25
Peter Lawrey Avatar answered Nov 07 '25 10:11

Peter Lawrey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!