nodejs / nodejs/node

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

Abierto
#65,235 1 comentario 7 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature request
Lenguaje dominante
JavaScript
Estrellas
122k
Forks
37.3k
Merge medio
4 d 2 h
PR fusionados (30 d)
283

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la implementación de --max-old-space-size-percentage y los parámetros de memoria de cgroup que lee; después, inspecciona cómo se pueden actualizar en tiempo de ejecución los límites de los isolates de V8. Valida el diseño con Kubernetes InPlacePodVerticalScaling y tanto con el aumento como con la reducción de memoria; se considera terminado cuando el porcentaje se vuelve a aplicar después de cambios en el límite de ejecución sin reiniciar.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, kubernetes, nodejs
Área
backend, cloud, operating-systems, performance
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.