I have an Ubuntu 18.04 VM image that runs a Java 8-based server process. When running on a single core EC2 t2.small instance (2GB RAM) it starts with an RSS of 432M. Running the exact same server image as a t3.small (dual core, same 2GB RAM), the service rockets up to 876M RSS on start. On Java 10, the difference is even more profound: sometimes it starts at 1586M RSS. And performance takes a noticeable hit.

At no point is any swap being used.

Exact same server image, very different results. The only significant variable seems to be the number of cores.

HOWEVER after running jmap to see how the heap's being used, I noticed the RSS had fallen by half, about where I'd expect it to be on the t2. And the heap dumps showed no real difference in actual allocation across t2 or t3, Java 8 or Java 10.

So, I'm wondering: is this the JVM or OS that's acting differently? I know I can play with MaxHeapFreeRatio to get the JVM to release memory quicker, but is this the JVM reacting to memory conditions, or the OS?

  • Guess: the more system RAM available, the more the JVM allocates to Java. – Tim Dec 23 '18 at 19:39
  • @Tim the RAM available to the JVM is the same on both systems though. – Matthew Phillips Dec 23 '18 at 22:50
  • Interesting question. The solution is likely to use arguments to the JVM to control memory use. I think it's the heap that uses the most ram, look for that argument. – Tim Dec 24 '18 at 0:24

The default heap size is really processor-count dependent, and comes from the JVM. From Java 8 documentation: server-class machine is one with at least 2 CPUs and at least 2GB of physical memory.

t2.small is a single-core instance, so java by default uses the Client JVM settings, and starts with a lower heap size.

t3.small falls into the Server JVM settings, the JVM starts with higher heap size.

The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. It is only allocated for possible future use.

More information about Java 8 available here, and I believe Java 10 has only newer/higher defaults, but the logic is the same.

  • Thanks, that's about what I had gathered too after trawling though all the docs. I've since set the server's -Xms and -Xmx to be the same value, which is a better idea anyway for my environment. – Matthew Phillips Mar 29 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.