help icon indicating copy to clipboard operation
help copied to clipboard

process.memoryUsage() on Windows is a memory hog?

Open josezulu opened this issue 8 years ago • 2 comments

  • Node.js Version: 8.9.0
  • OS: Windows 7
  • Scope (install, code, runtime, meta, other?): runtime
  • Module (and version) (if relevant): n.a.

Hello, I'm no expert on Node.js, but I want to bring this up in the help repository, so please forgive me if I misunderstood anything.

It seems that process.memoryUsage() is increasing the memory usage by about 4 to 6 MB every time I run it, just directly in the REPL. I confirm with the Task Manager that the process' memory usage goes up. It doesn't seem to get garbage collected either (perhaps it shouldn't anyways?).

But this seems to me like a huge jump in memory usage.

This doesn't seem to be happening in Linux, same node version; where I barely get an increase of ~500 KB when I run the same process function.

process.memoryUsage().rss / 1024 / 1024

Again, apologies if I misunderstood anything and this turns up being a non-issue. If did, please let me know what I got wrong.

Thanks in advance.

josezulu avatar Dec 11 '17 10:12 josezulu

RSS (Resident Set Size) is not an intrinsic measure of your process size. It is only a measure of how much of your allocated committed memory is presently in physical main memory, and the latter is competing with the demands on main memory from the rest of the workload. That is, if you process is moderately busy/active (in allocation terms) but you are part of a workload beside a very active process, like a database or web server, or the operating system(!), then your process is likely to be more subject to having part of its pages paged out (especially if as a garbage collected system, only the generational storage where allocation activity is focused and where copy collection occurs on the same pages that host your Javascript heap) which reduces your RSS measure, but changed nothing about what the process allocated and is using. And, this doesn't even take into consideration the Linux over-commit memory model, etc.

shellberg avatar Dec 11 '17 10:12 shellberg

@shellberg Thank you for your prompt response!

josezulu avatar Dec 23 '17 13:12 josezulu