Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Fix #3086: Adjust node max_old_space_size to a percentage of availabl…
Browse files Browse the repository at this point in the history
…e container memory (#3099)
  • Loading branch information
k-wall committed Aug 16, 2019
1 parent e90b8ee commit df92675
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions agent/bin/launch_node.sh
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

OLD_SPACE_SIZE_PERCENT=${OLD_SPACE_SIZE_PERCENT:-80}
CGROUP_FILE='/sys/fs/cgroup/memory/memory.limit_in_bytes'

# Ensure that we have a suitable node interpreter. This ought to be declared declaratively in the package.json, within an engines section,
# but we currently don't install the package so this wouldn't be enforced.
REQUIRED_NODE_MAJOR=6
Expand All @@ -13,4 +16,19 @@ if [[ ! -z "${_NODE_OPTIONS}" ]]; then
set -- ${_NODE_OPTIONS} "${@}"
fi

# Set max_old_space_size w.r.t the container's memory, unless caller has supplied --max_old_space_size
for arg; do
if [[ "${arg}" =~ ^--max_old_space_size.* ]]; then
OLD_SPACE_SIZE_PERCENT=0
break
fi
done

if [[ -f "${CGROUP_FILE}" && "${OLD_SPACE_SIZE_PERCENT}" -gt 0 ]]; then
CONTAINTER_BYTES=$(cat ${CGROUP_FILE})
MAX_OLD_SPACE_SIZE=$(( ${CONTAINTER_BYTES} / 100 * ${OLD_SPACE_SIZE_PERCENT} ))
MAX_OLD_SPACE_SIZE_MI=$(( ${MAX_OLD_SPACE_SIZE} / ( 1024 * 1024 ) ))
set -- "--max_old_space_size=${MAX_OLD_SPACE_SIZE_MI}" "${@}"
fi

exec node "${@}"

0 comments on commit df92675

Please sign in to comment.