nodejs / nodejs/node

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

Đang mở
#65,235 1 bình luận 7 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature request
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.4k
Merge trung bình
4 ngày 3 giờ
Pull request đã merge (30 ngày)
272

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với việc triển khai --max-old-space-size-percentage và các tham số bộ nhớ cgroup mà nó đọc, sau đó kiểm tra cách có thể cập nhật các giới hạn của V8 isolate trong thời gian chạy. Xác thực thiết kế dựa trên Kubernetes InPlacePodVerticalScaling và cả việc tăng lẫn giảm bộ nhớ; hoàn thành có nghĩa là phần trăm được áp dụng lại sau khi các giới hạn thời gian chạy thay đổi mà không cần khởi động lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, kubernetes, nodejs
Lĩnh vực
backend, cloud, operating-systems, performance
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.