# Julia execution inside a container with restricted RAM

**URL:** <https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173>\
**Category:** Tooling\
**Tags:** docker, garbage-collection, kubernetes\
**Created:** [May 16, 2022, 10:20pm UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173 "2022-05-16T22:20:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rssdev10](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rssdev10](https://discourse.julialang.org/u/rssdev10)\
**Post date:** [May 16, 2022, 10:20pm UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/1 "2022-05-16T22:20:46Z")

</div>

Hello, is any way to restrict Julia’s process in memory consumption when that’s executed inside a Docker container? Sometimes we are getting out-of-memory kills just because Julia’s garbage collector didn’t do memory cleanup at the proper time. As a result, Kubernetes restarts these containers.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [May 16, 2022, 10:33pm UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/2 "2022-05-16T22:33:13Z")

</div>

You can probably increase your containers’ memory limits, or you can use `GC.gc()`.

---

<div class="post-metadata">

**Author:** ![rssdev10](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rssdev10](https://discourse.julialang.org/u/rssdev10)\
**Post date:** [May 16, 2022, 11:07pm UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/3 "2022-05-16T23:07:48Z")

</div>

> [@jar1](#):
>
> `GC.gc()`

`GC.gc()` is asynchronous as I know. I can add it at end of query processing, but there is no guarantee that memory will be freed.

Container limits - that might be expansive if I need to have 2x 3x times more RAM than really used…

What it would be good to have - something like forced garbage collection on the RAM limit reach. Something like -Xms and -Xmx options in JVM.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [May 16, 2022, 11:15pm UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/4 "2022-05-16T23:15:16Z")

</div>

[Updated 32 bit heuristics by chflood · Pull Request #44805 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/44805) adds one internally. It would be a very easy PR to Julia to make it a command line option.

---

<div class="post-metadata">

**Author:** ![rssdev10](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rssdev10](https://discourse.julialang.org/u/rssdev10)\
**Post date:** [May 16, 2022, 11:45pm UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/5 "2022-05-16T23:45:32Z")

</div>

That option would be very useful with any cluster/cloud based deployments.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 16, 2022, 11:48pm UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/6 "2022-05-16T23:48:51Z")

</div>

I thought someone had worked on making Julia cgroups aware. I’m not sure where the merged PR is right now.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [May 17, 2022, 12:39am UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/7 "2022-05-17T00:39:13Z")

</div>

+1 for something like this. I asked about this here as well: [https://discourse.julialang.org/t/is-there-a-way-cap-memory-usage-to-keep-mybinder-from-crashing](https://discourse.julialang.org/t/is-there-a-way-cap-memory-usage-to-keep-mybinder-from-crashing)

Fwiw, I found that using package compiler helped reduce the memory footprint when loading packages.

---

<div class="post-metadata">

**Author:** ![rssdev10](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rssdev10](https://discourse.julialang.org/u/rssdev10)\
**Post date:** [May 17, 2022, 12:45am UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/8 "2022-05-17T00:45:45Z")

</div>

For Docker-based deployments, we are using binary compiled sysimages only with full code coverage by unit tests in a tracing stage. But `gc` is a different issue. When we have a bunch of queries, we cannot guarantee that memory will be available even when we 100% know the memory consumption per query and the number of queries in processing.

---

<div class="post-metadata">

**Author:** ![rssdev10](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rssdev10](https://discourse.julialang.org/u/rssdev10)\
**Post date:** [May 19, 2022, 9:14pm UTC](https://discourse.julialang.org/t/julia-execution-inside-a-container-with-restricted-ram/81173/9 "2022-05-19T21:14:29Z")

</div>

New command-line option `--heap_size_hint` as a part of Julia 1.9

[https://github.com/JuliaLang/julia/pull/45369](https://github.com/JuliaLang/julia/pull/45369)
