镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Memory Leak Help #21

Description

@kirrg001

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

Activity

  1. bnoordhuis commented on Oct 28, 2015

    @bnoordhuis
    Member

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

  2. kirrg001 commented on Oct 28, 2015

    @kirrg001
    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!

  3. Fishrock123 commented on Oct 28, 2015

    @Fishrock123

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

  4. kirrg001 commented on Oct 28, 2015

    @kirrg001
    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

  5. danielkhan commented on Oct 28, 2015

    @danielkhan
    Contributor

    Here is an example on how to use v8-profiler to create heapdumps if memory is constantly climbing: https://github.com/proxy/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.

  6. bnoordhuis commented on Oct 28, 2015

    @bnoordhuis
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions