Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak Help #21

Closed
kirrg001 opened this issue Oct 28, 2015 · 6 comments
Closed

Memory Leak Help #21

kirrg001 opened this issue Oct 28, 2015 · 6 comments

Comments

@kirrg001
Copy link

hey!

i discovered that one of my files is causing a memory leak. the memory grows over days. i'm checking everyday with htop and it grows every day more and more. i don't understand what is the reason for the memory leak. i hope somebody can help me.

var config = require(__dirname + '/config'),
  async = require('async'),
  meminfo = require('meminfo'),
  os = require('os-utils'),
  ip = require('ip'),
  timeout = null;


(function reportStats() {
  var cpuUsage = null,
    memUsage = null;

  async.waterfall([
    function(asyncDone) {
      os.cpuUsage(function(_cpuUsage) {
        cpuUsage = _cpuUsage;
        asyncDone();
      });
    },
    function(asyncDone) {
      meminfo(asyncDone);
    },
    function(_memUsage, asyncDone) {
      memUsage = _memUsage;

      // this will send a request to AWS via SQS
      config.logger.request({ cpuUsage: cpuUsage, memUsage: memUsage });
      asyncDone();
    }
  ], function(err) {
    if (err) {
      ....
    }

    clearTimeout(timeout);
    timeout = setTimeout(reportStats, 60 * 1000);
  });
}());

Thanks
kirrg

@bnoordhuis
Copy link
Member

Can you post numbers? Is it VMEM or RSS that is growing? Have you tried node-inspector or node-heapdump yet?

@kirrg001
Copy link
Author

when i have a fresh deploy:
RES ~70mb

after one day:
RES ~100mb

after a couple of days i had 30% memory usage (1GB max):
RES ~300mb

we played only with memwatch a little. but i thought there is an obvious memory leak problem in the code. if you say "no there isn't", i will investigate using more tools.

thanks a lot!

@Fishrock123
Copy link

@kirrg001 What OS are you running and which Node version?

@kirrg001
Copy link
Author

node v0.10.33
Linux version 3.14.48-33.39.amzn1.x86_64 (mockbuild@gobi-build-60007) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Tue Jul 14 23:43:07 UTC 2015

@danielkhan
Copy link
Contributor

Here is an example on how to use v8-profiler to create heapdumps if memory is constantly climbing: https://gist.github.com/danielkhan/0a98ae0ae2b5ddfd443e

You can the load this into chrome developer tools. Try to get 3 dumps. one from the start, one after some time and one after an equal amount of time.
In chrome developer tools you can display the difference between two heap dumps. This might show you the data structures that are constantly growing = your leak.

Here's also a slide deck on this topic: www.slideshare.net/DanielKhan3/hunting-performance-problems-in-nodejs.

@bnoordhuis
Copy link
Member

300 MB RSS doesn't seem that out of the ordinary to me. The garbage collector will opportunistically grow the heap so it's not unexpected that RSS (and VMEM too) go up over time. It should plateau when it reaches the hard limit (~1.5 GB by default, configurable with --max_old_space_size.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants