nodejs / nodejs/node

node only using half of the available memory

Open
#35,573 15 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

memory never-stale
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

  • Version: 12.19.0
  • Platform: Debian Buster
  • Subsystem:
What steps will reproduce the bug?
  1. Start a container with limited memory (something like docker run --rm -it --memory=1G --memory-swap=1G node:12.19.0-buster-slim bash
  2. Inspect heap size (node -e 'const v8 = require("v8"); console.log(v8.getHeapStatistics());')
How often does it reproduce? Is there a required condition?

100%

What is the expected behavior?

node would use all available memory

What do you see instead?

node is only using half of the memory, so we either need to give the container twice as much memory as we really want it to use (which is problematic) or also specify --max-old-space-size in addition to controlling the container which means we have to keep 2 different settings in sync and that's a big pain

Additional information

It appears that it was changed here, and only using half of memory makes sense when running on a system with multiple process, but when running in a docker container, using all of the memory allocated to the container makes more sense

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided docker run command and the node -e v8.getHeapStatistics() check. Trace how Node.js determines the container memory limit and compare that value with the expected 1G allocation; done means the runtime sizes the heap appropriately without requiring a separate --max-old-space-size setting.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, javascript, linux, node.js
Domain
backend, devops, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.