Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: Why pm2 list shows memory keeps on increasing?

I am using HAPI.JS framework with NodeJS and created a proxy. Think that proxy means i am just maintaining session in redis. Other than that i am not doing anything in the code. May be only thing is i am using setInterval to log my process.memoryUsage() for every 3 mintues.

enter image description here

My Questions:

  1. Why my Memory Keeps on Increasing?
  2. Will it get down?
  3. Is this occurs due to setInterval keeps on logging the process usage?
  4. Is this occurs due to console logging of every request and response?
  5. My Redis Database is kept open till my server crashes, it this causes this ?
  6. Do i need use process mananger like new relic or strong loop to identify this?
  7. So how long this memory will keep on increasing, at some point it must stop (i want to know which point is that?)
  8. I am using sequelize of MSSQL transaction using pooling concept? Does pooling makes this?

P.S I am new to node JS.

like image 813
Sathish Avatar asked Apr 17 '15 07:04

Sathish


People also ask

How much memory does PM2 use?

Monitoring With PM2 The default memory consumption is about 50M for the maintenance and 70M for the homepage project. That's all the magic. Keymetrics (the developers of PM2) uses this feature to report the current process utilization directly to their dashboard which is accessible via web interface.

How do I stop memory leaks in Node JS?

Avoid Accidental Globals This could be the result of a typo and could lead to a memory leak. Another way could be when assigning a variable to this within a function in the global scope. To avoid issues like this, always write JavaScript in strict mode using the 'use strict'; annotation at the top of your JS file.

How do I limit memory in Node JS?

Currently, by default v8 has a memory limit of 512mb on 32-bit systems, and 1gb on 64-bit systems. The limit can be raised by setting --max_old_space_size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits.

What is heap size in PM2?

The heap is the RAM used by the program you're asking PM2 to manage and monitor. Heap space, in Javascript and similar language runtimes, is allocated when your program creates objects and released upon garbage collection.


1 Answers

  1. Why my Memory Keeps on Increasing?

You got a memory leak

  1. Will it get down?

Sometimes GC kicks in and cleans up some things (that are not leaking)

  1. Is this occurs due to setInterval keeps on logging the process usage?

Usually not, but w/o seeing the code I can't say this for sure

  1. Is this occurs due to console logging of every request and response?

Usually not, but w/o seeing the code I can't say this for sure

  1. My Redis Database is kept open till my server crashes, it this causes this ?

Should not be a problem.

  1. Do i need use process mananger like new relic or strongloop to identify this?

It is one way to do it ... but there are also others.

  1. So how long this memory will keep on increasing, at some point it must stop (i want to know which point is that?)

Depends on the server setup. How much RAM + what else is running etc.

  1. I am using sequelize of MSSQL transaction using pooling concept? Does pooling makes this?

Usually not, but w/o seeing the code I can't say this for sure

Maybe this post helps you find the leak:
https://www.nearform.com/blog/how-to-self-detect-a-memory-leak-in-node/

like image 58
Philipp Kyeck Avatar answered Oct 12 '22 03:10

Philipp Kyeck