I am pretty sure I found a major memory leak. It seems to be related to the gzipResponse and bodyParser plugins. I use node-memwatch to inspect the memory usage and force a garbage collection.
Version Info
ubuntu: 12.04
node: 0.10.4
restify: 2.6.0
Server
var fs = require('fs');
var memwatch = require('memwatch');
var restify = require('restify');
var hd = null;
function startDiff(req, res, next) {
memwatch.gc();
hd = new memwatch.HeapDiff();
return next();
}
function endDiff(req, res, next) {
memwatch.gc();
var diff = hd.end();
console.log('before: ' + diff.before.size);
console.log('after: ' + diff.after.size);
console.log('change: ' + diff.change.size);
console.log('---------------------');
return next();
}
var server = restify.createServer();
// removing either plugin also exhibits the memory leak
// remove both plugins and no memory leak
server.use(restify.gzipResponse());
server.use(restify.bodyParser());
server.get('/', [
startDiff,
function(req, res, next) {
// large-file.json is a just a large JSON file, content does not matter
var data = fs.readFileSync('large-file.json'));
res.send(JSON.parse(data));
return next();
},
endDiff,
]);
server.listen(4001, function() {
console.log('listening at ' + server.url);
});
Client
curl --compressed http://localhost:4001 > /dev/null
Output after 3 client calls, with memory leak
before: 5.99 mb
after: 175.48 mb
change: 169.5 mb
---------------------
before: 175.83 mb
after: 318.21 mb
change: 142.38 mb
---------------------
before: 318.4 mb
after: 460.75 mb
change: 142.35 mb
---------------------
Output after 3 client calls, with no memory leak
before: 5.87 mb
after: 147.82 mb
change: 141.94 mb
---------------------
before: 5.36 mb
after: 147.86 mb
change: 142.5 mb
---------------------
before: 5.4 mb
after: 147.88 mb
change: 142.48 mb
---------------------
I am pretty sure I found a major memory leak. It seems to be related to the
gzipResponseandbodyParserplugins. I use node-memwatch to inspect the memory usage and force a garbage collection.Version Info
Server
Client
Output after 3 client calls, with memory leak
Output after 3 client calls, with no memory leak