3

In order to understand the memory usage pattern of NodeJS's V8 engine, I wrote a simple web program as shown below:

contents of server.js:
var http = require("http");

var server = http.createServer(function(req, res) {
   res.write("Hello World");
   res.end();
});
server.listen(3000);

When the program is launched using node server.js, the initial memory snapshot is as below: enter image description here

After I kept making multiple URL hits to this server, I could see a pattern of increased heap usage. To be more precise, for every 6 or 7 hits, there is an increase of 4K. I kept repeating the hits continuously for about 2 minutes, then this is the snapshot. enter image description here

I didn't see any eventual decrease in heap usage, even if I kept it idle without load.

My question is:

Is this a normal behavior, or there is a memory leak in nodeJS? Or, am I understanding or interpreting it incorrectly?

Mopparthy Ravindranath
  • 3,014
  • 6
  • 41
  • 78
  • strongloop usually has some legit articles on node.js and V8. Might want to read up on this one: https://strongloop.com/strongblog/node-js-performance-garbage-collection/ and use a profiler that shows deltas between GC times to better estimate how well heap increases and decreases. – bbuckley123 Oct 05 '15 at 20:50

1 Answers1

2

Node uses V8 under the hood, so the answer to this question most likely applies: How does V8 manage its heap?

The code appears to be valid, so to test you could write a small application to repeatedly call your api and then examine Node's memory while running. Use this to help detect possible leakage (if there is any over 5 consecutive runs of the garbage collector): http://www.nearform.com/nodecrunch/self-detect-memory-leak-node/

Community
  • 1
  • 1
Jon Fast
  • 171
  • 6