How to get V8 GarageCollection-related metrics in Node application

132 views
Skip to first unread message

Wei

unread,
Oct 24, 2014, 2:00:45 AM10/24/14
to nod...@googlegroups.com
Hi folks:

I am trying to determine if the GC behavior for a Node application. What's the recommended way to have Node application get some information like:
1. V8 heap size at each minute
2. # of GCs in a second
etc.

From what I see in Google, there are some commercial products from AppDynamics & NewRelic, but haven't seen much beyond that. Any suggestions?

Thanks,
-Wei

Dhanesh Kasinathan

unread,
Oct 29, 2014, 7:54:47 AM10/29/14
to nod...@googlegroups.com

place this code at start of index.js it will provide memory usage statistics for every 30,000 milliseconds


var util = require('util');
setInterval(function() {
console.log(util.inspect(process.memoryUsage()));
}, 30000);

i.e
{ rss: 40812544, heapTotal: 32171264, heapUsed: 18636952 } 

Where in 
rss = residential set a.k.a. the pages that are actually in memory
heap(Total|Used) = the chunk of memory that's used for dynamic
allocations

Phillip Johnsen

unread,
Oct 30, 2014, 8:21:03 AM10/30/14
to nod...@googlegroups.com
Hi Wei,

I've also been trying to find good ways of measuring GC related stuff lately. Havent found a simple answer yet, seems like there's no way around native bindings to get a hold of the real nitty gritties.
There's a small list of modules on npmjs.org matching "gc" atm, i.e. node-gc. Unfortunately I havent been able to try any of them yet..
Also there might be some inspiration in StrongLoops commercial strong-agent module which gather tons of detailed metrics.

- Phillip

Wei

unread,
Oct 31, 2014, 12:40:55 AM10/31/14
to nod...@googlegroups.com
Thanks for the information, Philip. That's my impression as well. I'd be hesitant to use a module that has not been battle-tested in production environment. The other way I can think of is to throw some simulated prod traffic to my node app with UMEM_DEBUG turned on. This is inspired by
https://www.joyent.com/blog/walmart-node-js-memory-leak
It would require significant analysis on the memory trace although and not a fit for real-time monitoring.

Phillip Johnsen

unread,
Nov 16, 2014, 11:12:40 AM11/16/14
to nod...@googlegroups.com
I just stumbled upon the new core module "tracing". Its part of v0.11 so this is more for future reference than production use for most projects I guess.
It brings with it a gc-event which seems promising with before / after stats: https://github.com/joyent/node/blob/master/doc/api/tracing.markdown#v8

- Phillip

julien...@joyent.com

unread,
Nov 17, 2014, 6:18:38 PM11/17/14
to nod...@googlegroups.com
Hi,


On Sunday, November 16, 2014 8:12:40 AM UTC-8, Phillip Johnsen wrote:
I just stumbled upon the new core module "tracing". Its part of v0.11 so this is more for future reference than production use for most projects I guess.
It brings with it a gc-event which seems promising with before / after stats: https://github.com/joyent/node/blob/master/doc/api/tracing.markdown#v8

My understanding is that this API (and possibly the underlying implementation in src/node_v8.cc) will be removed shortly, so I wouldn't count too much on it.

Julien

julien...@joyent.com

unread,
Nov 17, 2014, 6:39:49 PM11/17/14
to nod...@googlegroups.com

Hi again,
I just realized that I should have said that this API and its implementation will probably _change_ in the near future. They won't necessarily be removed. See http://logs.libuv.org/libuv/latest#23:20:01.518 for more information.

Sorry for the confusion,

Julien
Reply all
Reply to author
Forward
0 new messages