Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node/Express memory increase on every request

I have a simple express 3.2 app that returns a 200 when posted to. I watch the memory RSS of the node (v0.10.5) process and every request increases the memory by 4kb or so.

The server code is quite simple:

var express = require('express');

var app = module.exports = express();

app.set('port', process.env.PORT || 3000);
app.use(express.favicon());
app.use(express.bodyParser());

require('./apps/events/index')(app);

app.listen(app.get('port'), function(){
  console.log("Express server starting...");
});

and the corresponding controller code is :

// ./apps/events/index.js
var events = function(app) {

  app.post('/events', function(req, res) {
    res.writeHead(200);
    res.end();
  });

}    
module.exports = events;

Is there something in my code that is causing this? Is this normal (hopefully not). Or am I measuring the wrong thing? I put a version of this script into production and the node process started at 16mb memory use, and after some load testing (20,000 hits) it increased to 32mb.

like image 677
robzolkos Avatar asked May 08 '13 13:05

robzolkos


1 Answers

Keep profiling your server. You will probably find that memory usage levels off over time. Try 200,000 requests and see if things change

Also if there is memory available the operating system will try to use it. 32mb of ram is not enough to be concerned about.

This talk is worth watching. It is about python but the concepts are the same for node.js

like image 190
Noah Avatar answered Sep 22 '22 00:09

Noah