3

Is there a way to share core library between Java processes (or other way to minimize JVM initial memory impact)

So here's my case. I'm playing with microservices. I'm runing quite a lot of them. I'm setting their heap for 128M as it's enough for them. But I've noticed that the Linux process is consuming much more.

If I understand correctly from here

Max memory = [-Xmx] + [-XX:MaxPermSize] + number_of_threads * [-Xss]

although I am using Java 8 so probably perm size is no longer the issue? or is it.

There is initial "core" JVM memory footprint... and I was wondering if you heard a way to somehow share that "core" memory between processes (as it's really the same). Or any way to deal with that extra cost when running many processes of java.

Khaled.K
  • 5,828
  • 1
  • 33
  • 51
keyer
  • 53
  • 3

1 Answers1

0

Conceptually you're asking if you can fork a JVM - since forking (generally) uses copy-on-write memory semantics this can be an effective space-saving measure. Unfortunately as discussed in this answer forking the JVM is not supported, and generally not practical. Non-Unix systems cannot fork efficiently, and there are numerous other side-effects that a forked JVM would have to resolve in messy ways. Theoretically you could probably fork a JVM process, but you'd be walking squarely into "undefined behavior" territory.

The "right" way to avoid JVM startup costs is to reduce the number of JVMs you need to start up in the first place. Java is a highly-concurrent language that supports shared access to common memory out of the box via its threading model. If you can refactor your code to run concurrently in the same JVM you'll see much better performance.

Community
  • 1
  • 1
dimo414
  • 47,227
  • 18
  • 148
  • 244