I am trying to understand how GC works on node.js. The v8 engine does not seem to free up memory.
I made a very simple script that implements an http server, and I save memory usage in the stream every 3 seconds.
var http = require('http'), fs = require('fs'), heapdump = require('heapdump'), memwatch = require('memwatch'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8888); console.log('Server running on port 8888.'); memwatch.on('leak', function(info) { // look at info to find out about what might be leaking console.log('============= MEMWATCH ON LEAK ============\n',info) }); memwatch.on('stats', function(stats) { // do something with post-gc memory usage stats console.log('============= MEMWATCH STATS ============\n', stats) }); var myStream = fs.createWriteStream('/tmp/logmem.log'); setInterval( function() { var t = new Date().getTime(); var memUsage = process.memoryUsage(); var str = t+';heapUsed;'+memUsage.heapUsed+';0;0;0\n'+ t+';heapTotal;'+memUsage.heapTotal+';0;0;0\n'+ t+';rss;'+memUsage.rss+';0;0;0\n'; myStream.write( str ); }, 3000 );
I am using the latest version of node.js 0.10.33
I use Gatling to send a request to my http server (15 requests / sec for 30 seconds and then 30 requests / sec for 30 seconds and then 100 requests / sec for 30 seconds).
The following diagrams show heapUsed , heapTotal and rss data process.memoryUsage() memory usage after 3 tests
After these tests, there is no activity on the server, but memory is not freed even after more than 1 hour.
memory usage after 80 minutes
Can someone explain to me if this is the standard behavior of v8 memory if in my script?
is there a memory leak?
thanks for the help
source share