0

Can mounting jre directory from host system reduce ram memory usage by sharing heapspace? Or will this cause some problems?

I have a lot of containers running java service inside. The problem is, that sometimes when the services have very strong workload, they need (eventually) a lot if heapspace. When i assign for each container (for example) -Xmx2g, then im pretty fast running out of RAM on my host system. Unfortunately once java allocated heap, it will not be free anymore (for the container RAM, host RAM). Restarting the container will free the allocated memory for the heapspace used in the peak, but for container with solr inside it will (probably) take several hours to index all the data again, what makes the downtime only possible on the weekend.

The idea is to using common jre in the host system to share the heapspace between single services. Probably i can assign -Xmx the following value (only an example): 250m times a number of services plus 3g for the workload peaks. This way i will using much less memory, because the services sharing the heap space.

Is there an error in my idea or can it really be worth?

Maybe someone is already faced such a problem and and probably solved it in another way?

d3rbastl3r
  • 463
  • 1
  • 6
  • 16
  • 1
    The setup you describe is essentially what a Java application server does; [Apache Tomcat](http://tomcat.apache.org) is the most prominent open-source one. There's nothing wrong with doing this, and it's very well-established technology, but I wouldn't try to combine this setup with Docker. – David Maze Aug 22 '19 at 10:31

2 Answers2

0

I don't think it is a good idea to share memory between containers. Docker is designed to isolate different environments and reduce the effects from other containers. So run with their own jvm is the current way to use Docker and other containers.

Also if you shared memory, it is hard to migrate the container.

Gawain
  • 1,017
  • 8
  • 17
  • Also if one service takes the JVM down you lose all of your services. – mwarren Aug 22 '19 at 08:35
  • I agree to both, but it is also the wrong way to take several services in to one container to save a little bit of memory. Reducing the heapspace for every container is also not possible ... i did it but this has an effect that sometimes this container run out of heapspace. Also how to deal with it the nice way (keep container nice, the services encapsulated and solve the ram limit problem)? Rework implementation is not work for container we not responsible for and anyway this will produce bugs and cost a lot of time. – d3rbastl3r Aug 22 '19 at 08:42
  • We also thought about to use "GO", "RUST" or "C++" for services with huge amount of workload, but this will also produce a lot of bugs and it will be hard (for now) to find nice developer with this skills :P – d3rbastl3r Aug 22 '19 at 08:47
  • Are you using cloud services like AWS ECS or google cloud? I think ECS can dynamic align the resources for your container automatically so you don't need to manage the host manually. – Gawain Aug 23 '19 at 10:01
  • Yes, but for on premises installation we can not expect to have an infinit amount of resources and we must stick to our recommendation values (and not increase those with every new released version) – d3rbastl3r Aug 26 '19 at 06:15
0

I already found a solution here (schrinking java heapspace): https://stackoverflow.com/a/4952645/2893873

I assumed that shrinking java heap space is not possible, but it is. I think it will be a better solution instead of sharing the JVM between the container.

d3rbastl3r
  • 463
  • 1
  • 6
  • 16