nodejs / nodejs/node

Dynamic V8 Heap Resizing for Kubernetes In-Place Scaling (--max-old-space-size-percentage)

未关闭
#65,235 1 条评论 7 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

What is the problem this feature will solve?

Node.js supports percentage-based heap configuration via --max-old-space-size-percentage. However, this flag currently calculates V8's maximum old space size only once at process startup based on initial system or cgroup memory limits.

Kubernetes supports in-place resource resizing (InPlacePodVerticalScaling), which alters container memory limits dynamically at runtime without restarting the container. Because --max-old-space-size-percentage evaluates only at startup, it cannot react to runtime cgroup changes:

  1. Memory Upscaling: If Kubernetes increases a running container's memory limit, Node.js remains restricted to the initial V8 heap limit calculated at startup, failing to utilize the newly available RAM.
  2. Memory Downscaling: If Kubernetes decreases the container's memory limit below the initial V8 heap allocation, the container risks being terminated by the Linux Out-Of-Memory (OOM) killer before V8 triggers garbage collection or lowers its heap boundary.

To fully support zero-downtime Kubernetes in-place resizing, --max-old-space-size-percentage needs to dynamically recalculate and apply heap limits when cgroup memory parameters change at runtime.

What is the feature you are proposing to solve the problem?

Extend --max-old-space-size-percentage to actively monitor cgroup memory limit changes and adjust the V8 heap size dynamically during process execution.

Example Workflow
# Enable percentage-based allocation
node --max-old-space-size-percentage=80 app.js

  1. Initialization: Container starts with a 2 GiB memory limit. Node.js evaluates --max-old-space-size-percentage=80 and sets V8 max old space to ~1.6 GiB.
  2. Kubernetes Event: Kubernetes resizes the running pod in-place from 2 GiB to 4 GiB memory limit.
  3. Event Detection: Node.js detects the cgroup change event.
  4. Runtime Update: Node.js recalculates 80% of 4 GiB (~3.2 GiB) and adjusts V8's isolate limits dynamically while the application continues processing traffic.
What alternatives have you considered?

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先实现 --max-old-space-size-percentage 及其读取的 cgroup 内存参数,然后检查如何在运行时更新 V8 isolate 限制。针对 Kubernetes InPlacePodVerticalScaling 以及内存扩容和缩容两种情况验证设计;完成标准是在运行时限制发生变化后,无需重启即可重新应用该百分比。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, kubernetes, nodejs
领域
backend, cloud, operating-systems, performance
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。