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

Aperta
#65,235 1 commento 7 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, kubernetes, nodejs

Direzione di ricerca

Inizia con l’implementazione di --max-old-space-size-percentage e dei parametri di memoria cgroup che legge, quindi esamina come aggiornare a runtime i limiti degli isolate V8. Convalida il design con Kubernetes InPlacePodVerticalScaling e sia con l’aumento sia con la riduzione della memoria; il lavoro è completato quando la percentuale viene riapplicata dopo le modifiche al limite di runtime senza un riavvio.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature request
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

Lingua principale
JavaScript
Stelle
122k
Fork
37.4k
Merge medio
4g 3h
PR unite (30g)
273

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/node

Tutte le issue di nodejs/node

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.