landlord / flatmate

Reduce memory usage by running multiple applications in the same JVM.
Apache License 2.0
13 stars 1 forks source link

Improve disk space usage #8

Open longshorej opened 5 years ago

longshorej commented 5 years ago

Given many JVM applications with similar dependencies, where fatjars are not used:

flatmate could provide a build-time tool that copies all jars into a directory, named by the hash of their contents, and then sets up symbol links into the lib folder of each application. This way, only one copy of each jar would need to be in the resulting image.

Potential directory structure:

# files
/opt/docker/lib/a928d969b4b1b135b80b9674d81806476eef409206a9d86ec4a59811ab533ff8.jar
/opt/docker/lib/152efcb68cfb5a1690e798f45ce2053e8df810c42d6145ca4fc54676c13931d7.jar
/opt/docker/lib/1/lib/app.jar
/opt/docker/lib/2/lib/app.jar

# links
/opt/docker/lib/a928d969b4b1b135b80b9674d81806476eef409206a9d86ec4a59811ab533ff8.jar -> /opt/docker/1/lib/akka.jar
/opt/docker/lib/152efcb68cfb5a1690e798f45ce2053e8df810c42d6145ca4fc54676c13931d7.jar -> /opt/docker/1/lib/akka-http.jar
/opt/docker/lib/a928d969b4b1b135b80b9674d81806476eef409206a9d86ec4a59811ab533ff8.jar -> /opt/docker/2/lib/akka.jar
/opt/docker/lib/152efcb68cfb5a1690e798f45ce2053e8df810c42d6145ca4fc54676c13931d7.jar -> /opt/docker/2/lib/akka-http.jar
longshorej commented 5 years ago

I wonder if this could help with memory usage as well? Does the JIT compiling of classfiles happen per class loader, or per JVM somehow? My guess is per classloader, so it may not necessarily help, but perhaps worth investigation.

huntc commented 5 years ago

I believe it is per class loader - there’s some info here: https://github.com/landlord/landlord/blob/master/README.md#considerationstrade-offs