Heap Size Ergonomics in docker containers
Thomas Schatzl
thomas.schatzl at oracle.com
Tue Oct 31 15:22:38 UTC 2017
Hi Ruslan,
On Mon, 2017-10-30 at 19:06 +0100, Ruslan Synytsky wrote:
> Hi guys, I'm interested in improvements in this direction as well.
> Let me share the statistical experience from Jelastic customers who
> run Java stacks in containers for a long time.
>
> We set the minimum Xmx to 32m by default as we believe majority wants
> to start from the minimum, specifically in the "micro" world
> (services, containers). G1 GC provides good enough elasticity of
> memory allocation. You can grow up quickly, and important to scale
> down later when the load goes away.
>
> By default, Xmx is 80% of available RAM with container limits. It
> works great for the majority of our users. We track OOM Kill events
> and send alerts to the users. So the numbers are based on the real
> end users applications.
>
> We keep 80% from max by default always, even if users allocate a
> bigger amount of RAM, for two reasons: 1 - it's easier to remember
> the defaults and 2 - unused resources are not reserved with
> containers, so if Java does not use it - no problem, they are free,
> and at the same time additional memory available for native non-heap
> data or for other processes, just like an insurance.
Thanks for your insights into real-world usage. So maybe the suggested
50% as default for small heaps is indeed a bit too conservative.
> Big memory and big data solutions - everything like this requires a
> fine-tuning, the customers who run such stacks definitely do not rely
> on the default heuristic. You can always find instructions and
> recommended RAM usage configs for these stacks. Some solutions even
> use direct memory access, a small heap size is preferable for them.
> In general, it means you have to do a customization if you want to
> get a stable solution.
>
> To make it simple, we came up with a supervisor script that
> applies custom memory configs. As result, customers can define the
> needed parameters with env variables in a container if they do not
> want to rely on the heuristic.
>
> Btw, is there any guaranteed way to pass Xmx and Xms to java process
> w/o any external scripts? I mean, it will be cool if java can check
> env variable like XMX and if it exists apply.
>
There is JAVA_TOOL_OPTIONS, which are always prepended to the java VM
command line. See the description [0] for more information.
I think this is what you were looking for.
Thanks,
Thomas
[0] https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot
/envvars002.html
More information about the hotspot-gc-dev
mailing list