1

I would like to unterstand the GC Process a little bit better in Nodejs/V8.

Could you provide some information for the following questions:

  • When GC is triggered, does this block the event loop of node js?

  • Is GC running in it's own process or is just a submethod of the event-loop ?

  • When spawning nodejs process via Pm2 (clustered mode) does the instance really have it's own process or is the GC shared between the instances ?

  • For Logging Purposes I am using Grafana (https://github.com/RuntimeTools/appmetrics-statsd), can someone explain the differences \ more details about these gauges:

    gc.size the size of the JavaScript heap in bytes.

    gc.used the amount of memory used on the JavaScript heap in bytes.

Memory usage

  • Are there any scenarios where GC is not freeing memory (gc.used) in relation with stress tests?

The questions are related to an issue that I am currently facing. The used memory of GC is rising and doesn't release any memory (classical memory leak). The problem is that it only appears when we a lot of requests.

I played around with max-old-space-size to avoid pm2 restarts, but it looks like that GC is not freeing up anymore and the whole application is getting really slow...

Any ideas ?

ChrLipp
  • 15,526
  • 10
  • 75
  • 107

2 Answers2

0

ok some questions, I already figured out:

gc.size = Total Heap Size (https://nodejs.org/api/v8.html -> getHeapStatistics),

gc.used = used_heap_size

it looks ok that when gc_size hits a plateu that it never goes down again =>

Memory usage doesn't decrease in node.js? What's going on?

Community
  • 1
  • 1
0

Why is garbage collection expensive? The V8 JavaScript engine employs a stop-the-world garbage collector mechanism. In practice, it means that the program stops execution while garbage collection is in progress.

https://blog.risingstack.com/finding-a-memory-leak-in-node-js/