Skip to content

Commit

Permalink
Automatically set Java -Xmx to 90% of Docker memory. (#1111)
Browse files Browse the repository at this point in the history
When seeding/updating a repo, if the project does not explicitly set any
`robot_java_args`, generate code in the run.sh script to automatically
compute a default max memory setting that is dependent on the total
amount of memory that Docker is allowed to use.

The code is used if (1) we are indeed using Docker (and not Singularity)
and (2) no contradicting option is set in ODK_JAVA_OPTS (either in the
environment or in a run.sh.conf file).

closes #1074
  • Loading branch information
gouttegd authored Oct 23, 2024
1 parent b4cbdc3 commit edf0520
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion template/src/ontology/run.sh.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ if [ -n "$TAG_IN_IMAGE" ]; then
ODK_IMAGE=$(echo $ODK_IMAGE | awk -F':' '{ print $1 }')
fi
ODK_TAG=${ODK_TAG:-latest}
ODK_JAVA_OPTS={% if project.robot_java_args is defined and project.robot_java_args|length %}${ODK_JAVA_OPTS:-{{ project.robot_java_args }}}{% else %}${ODK_JAVA_OPTS:--Xmx8G}{% endif %}
{% if project.robot_java_args is defined and project.robot_java_args|length %}
ODK_JAVA_OPTS=${ODK_JAVA_OPTS:-{{ project.robot_java_args }}}
{% else %}
if [ -z "$USE_SINGULARITY" ]; then
{% raw %}DEFAULT_MAX_MEM=$(bc <<<"($(docker info --format={{.MemTotal}}) * .9) / (1024*1024*1024)")G{% endraw %}
else
DEFAULT_MAX_MEM=8G
fi
ODK_JAVA_OPTS=${ODK_JAVA_OPTS:--Xmx$DEFAULT_MAX_MEM}
{% endif %}
ODK_DEBUG=${ODK_DEBUG:-no}

ODK_USER_ID=${ODK_USER_ID:-{% if project.run_as_root %}0{% else %}$(id -u){% endif %}}
Expand Down

0 comments on commit edf0520

Please sign in to comment.