Skip to content

Commit 8284295

Browse files
heiskrCopilot
andauthored
Move V8 heap config to Dockerfile with --max-old-space-size-percentage (#60311)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 27310c8 commit 8284295

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# This Dockerfile is used solely for production deployments to Moda
22
# For building this file locally, see src/deployments/production/README.md
3-
# Environment variables are set in the Moda configuration:
3+
# Most environment variables are set in the Moda configuration:
44
# config/moda/configuration/*/env.yaml
5+
# V8 heap sizing is set here via NODE_OPTIONS and mirrored in
6+
# the Moda config files for defense-in-depth.
57

68
# ---------------------------------------------------------------
79
# BASE STAGE: Install linux dependencies and set up the node user
@@ -151,5 +153,11 @@ COPY --chown=node:node --from=precompute_stage $APP_HOME/.pageinfo-cache.json.br
151153
ARG BUILD_SHA
152154
ENV BUILD_SHA=$BUILD_SHA
153155

156+
# V8 heap limit as a percentage of the container cgroup memory limit.
157+
# Uses --max-old-space-size-percentage (Node 24+) so the heap adapts
158+
# automatically when K8s memory limits change. 75% leaves ~25% headroom
159+
# for off-heap memory (Buffers, V8 code cache, libuv) and OS overhead.
160+
ENV NODE_OPTIONS="--max-old-space-size-percentage=75"
161+
154162
# Entrypoint to start the server
155163
CMD ["node_modules/.bin/tsx", "src/frame/server.ts"]

config/kubernetes/default/deployments/webapp.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ spec:
3232
# Absolute minimum to start app is 4500Mi
3333
# Would increase with more pages, versions, or languages supported
3434
# The additional memory helps during traffic surges
35-
# Keep ~600 MB headroom above --max-old-space-size in
36-
# config/moda/configuration/default/env.yaml for Node
37-
# off-heap memory and OS overhead.
35+
# V8 heap is set to 75% of the cgroup memory limit via
36+
# --max-old-space-size-percentage in the Dockerfile.
3837
limits:
3938
cpu: 8000m
4039
memory: 16Gi

config/kubernetes/production/deployments/webapp.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ spec:
3434
# Absolute minimum to start app is 4500Mi
3535
# Would increase with more pages, versions, or languages supported
3636
# The additional memory helps during traffic surges
37-
# Keep ~600 MB headroom above --max-old-space-size in
38-
# config/moda/configuration/production/env.yaml for Node
39-
# off-heap memory and OS overhead.
37+
# V8 heap is set to 75% of the cgroup memory limit via
38+
# --max-old-space-size-percentage in the Dockerfile.
4039
limits:
4140
cpu: 16000m
4241
memory: 16Gi

config/moda/configuration/default/env.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
data:
22
MODA_APP_NAME: docs-internal
33
NODE_ENV: production
4-
# V8 heap limit (--max-old-space-size) should leave at least ~600 MiB
5-
# below the K8s memory request for Node off-heap memory (Buffers,
6-
# V8 code cache, libuv) and OS overhead. If you change the memory
7-
# request in config/kubernetes/default/deployments/webapp.yaml,
8-
# update this value to match.
9-
# Current: 8.0 Gi (8192 MiB) request, 7168 MiB heap = 1024 MiB headroom
10-
NODE_OPTIONS: '--max-old-space-size=7168'
4+
# Matches the Dockerfile ENV. Both set the same value so that
5+
# the heap limit is correct regardless of config-layering order.
6+
NODE_OPTIONS: '--max-old-space-size-percentage=75'
117
PORT: '4000'
128
ENABLED_LANGUAGES: 'en,es,ja,pt,zh,ru,fr,ko,de'
139
RATE_LIMIT_MAX: '21'

config/moda/configuration/production/env.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
data:
22
MODA_APP_NAME: docs-internal
33
NODE_ENV: production
4-
# V8 heap limit (--max-old-space-size) should leave at least ~600 MiB
5-
# below the K8s memory request for Node off-heap memory (Buffers,
6-
# V8 code cache, libuv) and OS overhead. If you change the memory
7-
# request in config/kubernetes/production/deployments/webapp.yaml,
8-
# update this value to match.
9-
# Current: 8.0 Gi (8192 MiB) request, 7168 MiB heap = 1024 MiB headroom
10-
NODE_OPTIONS: '--max-old-space-size=7168'
4+
# Matches the Dockerfile ENV. Both set the same value so that
5+
# the heap limit is correct regardless of config-layering order.
6+
NODE_OPTIONS: '--max-old-space-size-percentage=75'
117
PORT: '4000'
128
ENABLED_LANGUAGES: 'en,es,ja,pt,zh,ru,fr,ko,de'
139
RATE_LIMIT_MAX: '21'

0 commit comments

Comments
 (0)