Does JVM memory overhead scale linearly, or is it constant?

In my experience, a C program that uses around 10 megabytes of resident memory may use around 40 to 50 MB when translated into Java, and around 100 in Clojure or Scala. My question is whether this JVM memory overhead scales linearly; if the C version used 1 gigabyte, would the Java version require 4 GB? Or is the JVM memory overhead more a constant factor, such that the 1 GB C program might only use 1.5 GB in Java?

I'm aware that I could benchmark this, but I think hearing people's experience regarding JVM memory use in production would be more informative than an artificial benchmark, which could be skewed to favour either result depending on how it was designed.

Answers


The overhead is about 10MB + 4xC-memory.

The 10MB is the JVM without anything. Java 7 64bit version uses about this much.

The 4x memory is obviously a "guesstimate" because it depends on which data types you use. If you use 100% references in java they take up about 4 times as much memory. The same difference there is between int and Integer.

If there are a lot of malloc/new in your C code there will be that in Java too, and Java's GC might not run when you want it to, so there's also an overhead of "dead references not yet cleaned up" that depends greatly on things out of your control (GC timing).


Need Your Help

Are AMRMClientAsync and AMNMClientAsync thread-safe?

yarn

I'm writing yarn applications and I wonder if these interfaces are thread-safe. When I look up their api, I cannot find any message of it.