JS Memory Profile

169 views
Skip to first unread message

Alex Bustin

unread,
Feb 19, 2010, 12:12:50 PM2/19/10
to nodejs
Hi all,

I've been building a blogging app for the past few weeks with Node.
I'm close to be able to deploy, but I'm noticing an alarming rise in
memory usage when I'm refreshing a page over and over (once a sec) and
it never seems to release it.

Is there a way I can inspect/sample JS object allocation, etc, in
Node?

Thanks

- Alex

Ryan Dahl

unread,
Feb 19, 2010, 12:27:46 PM2/19/10
to nod...@googlegroups.com

You can have a look at the V8 memory usage with process.memoryUsage().
Note that V8 has a really lazy garbage collector and is still
currently tuned for use in Chrome. My daemons tend to grow to about
30mb RSS before they start aggressively collect garbage.

Alex Bustin

unread,
Feb 19, 2010, 1:13:10 PM2/19/10
to nodejs
Thanks for the info, Ryan.

In my simple (manual) test I was seeing a rise from ~10MB to ~27MB for
refreshing the same page over and over. I'll check later to see if I
can get it to go much higher.

- Alex

Louis Santillan

unread,
Feb 19, 2010, 1:24:53 PM2/19/10
to nod...@googlegroups.com
FYI, a garbage collection generation can be forced in V8 by doing the following

V8::IdleNotification()

To do a complete collection,

// V8::IdleNotification() returns a bool
while( V8::IdleNotification() ){}

-Louis

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>

Karl Guertin

unread,
Feb 19, 2010, 1:46:57 PM2/19/10
to nod...@googlegroups.com
On Fri, Feb 19, 2010 at 1:24 PM, Louis Santillan <lpsa...@gmail.com> wrote:
> FYI, a garbage collection generation can be forced in V8 by doing the following
>
> V8::IdleNotification()
>
> To do a complete collection,
>
> // V8::IdleNotification() returns a bool
> while( V8::IdleNotification() ){}

This came up on the serving 100k connections thread and AFAICT it's
not accessible from the JS sandbox. Is there any reason this can't be
exposed to javascript in something like sys.runGCSync()?

Rasmus Andersson

unread,
Feb 19, 2010, 4:43:44 PM2/19/10
to nod...@googlegroups.com

Would be nice to have access to it. Maybe expose it as sys.gc()? (as
it implies being synchronous there would be no need for the "Sync"
suffix and as nothing is "run", the "run" prefix is redundant).

Alex Bustin

unread,
Feb 19, 2010, 7:32:53 PM2/19/10
to nodejs
After a little more testing - It looks like my node apps RSS now
predictably fluctuates between 41MB and 45MB under constant page
refreshing. I was looking for a behavior where GC would bring down RSS
back down around start-up levels. I guess the lazy GC is only removing
a minimum number of objects. I can work with 40MB, I'm just wondering
what that extra stuff is. Part of me still wonders if I have a JS
leak - but I have no easy way of finding one.

sys.gc() +1

I tried looking at running the v8-options, but it looks like they
aren't being handled?

- Alex


On Feb 19, 9:27 am, Ryan Dahl <coldredle...@gmail.com> wrote:

Felix Geisendörfer

unread,
Feb 20, 2010, 8:18:40 AM2/20/10
to nodejs
Ryan: I just implemented a wrapper for V8::IdleNotification() here:

http://github.com/felixge/node/commit/5874f2b3f62dd3d03f95fa938c3a77cc79a12387

Let me know if you like it.

-- fg

Ryan Dahl

unread,
Feb 20, 2010, 9:42:46 PM2/20/10
to nod...@googlegroups.com
2010/2/20 Felix Geisendörfer <fe...@debuggable.com>:

> Ryan: I just implemented a wrapper for V8::IdleNotification() here:
>
> http://github.com/felixge/node/commit/5874f2b3f62dd3d03f95fa938c3a77cc79a12387
>
> Let me know if you like it.

We talked a bit about this on IRC. Basically - I think we can make
pretty good decisions about when the process is idle - and I think
shrugging off GC control to the user will just have it be misused. So
instead I did this patch:

http://github.com/ry/node/commit/daacb81d3ab8008d0aa3437216df32394e46186e

Basically once a second a timer fires and checks if the libev is doing
anything - if it isn't, then it starts an idle watcher - which will
call V8::IdleNotification() on each tick - but only if the process
isn't doing anything. In this way there aren't long period of GC
without returning to the event loop.

This patch has the effect of dramatically compacting process memory
usage while (at least with my trivial benchmarks) not making it any
slower. Try it out and let me know what you think.

Alex Bustin

unread,
Feb 21, 2010, 3:16:32 AM2/21/10
to nodejs
I just moved to v0.1.29-30.

From early observations - my apps RSS now fluctuates between 9MB and
12MB on a regular basis ... awesome Ryan ;)

I'll test some more in the next day or so, but is definitely better
than it was before.

Thanks again for looking into this,

- Alex

On Feb 20, 6:42 pm, Ryan Dahl <coldredle...@gmail.com> wrote:
> 2010/2/20 Felix Geisendörfer <fe...@debuggable.com>:
>
> > Ryan: I just implemented a wrapper for V8::IdleNotification() here:
>

> >http://github.com/felixge/node/commit/5874f2b3f62dd3d03f95fa938c3a77c...


>
> > Let me know if you like it.
>
> We talked a bit about this on IRC. Basically - I think we can make
> pretty good decisions about when the process is idle - and I think
> shrugging off GC control to the user will just have it be misused. So
> instead I did this patch:
>

> http://github.com/ry/node/commit/daacb81d3ab8008d0aa3437216df32394e46...

Reply all
Reply to author
Forward
0 new messages