Time for node.js Garbage Collection

I recently installed https://github.com/lloyd/node-memwatch for development to find out how the GC interacts with my program.

I bound the stat event, arthor states that the event is fired when the GC executes.

I found that with a script with a high load. Stat events are not fired. I'm not sure if this means that the GC is not running, but it is a sign that the GC may not work.

On my production server, loading is even much higher during the day. I am absolutely sure that GC has no chance to speak. Memory usage has no chance of diminishing. It is like a memory leak.

  • Is my observation correct? Can't perform the GC at high load?
  • If so, should I use the open GC interface to force the use of the GC?
  • Is GC Lock? Should I run the GC more often so that the GC does not block for a long time for each GC?

I know that manual GC is not a good idea (there is someone who is against the idea of ​​manual GC in node.js, but I can not find the link for reference), but I see that the memory usage is constantly growing, It really is need to decide.

+8
garbage-collection
source share
1 answer

There are 3 types of GC events in V8

  • kGCTypeMarkSweepCompact
  • kGCTypeScavenge
  • kGCTypeAll

V8 fires the scavenge event quite often, but only on newly created objects. Under heavy load, other types of GC may occur infrequently.

You can try running the NodeFly agent, which uses nodefly-gcinfo to track current memory usage.

You can also directly call nodefly-gcinfo , which has a callback that fires every time a GC event occurs:

 require('nodefly-gcinfo').onGC(function(usage, type, flags){ console.log("GC Event Occurred"); console.log("Heap After GC:",usage, type, flags); }); 
+3
source share

All Articles