Created
June 9, 2013 15:28
-
-
Save aschmitz/5743935 to your computer and use it in GitHub Desktop.
This appears to leak something in Node.js 0.10.10. Requires the `heapdump` module, `npm install heapdump`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var files = fs.readdirSync(__dirname).sort(); | |
for(var fileOn = 0; fileOn < files.length; fileOn++) { | |
if (files[fileOn].indexOf('heapsnapshot') > -1) { | |
if (isLeaking(files[fileOn])) { | |
console.log('Still leaking.'); | |
} else { | |
console.log('NOT leaking?'); | |
} | |
} | |
} | |
function isLeaking(heapFile) { | |
var heap = JSON.parse(fs.readFileSync(heapFile, {encoding: 'utf8'})); | |
var nodes = heap['nodes'], | |
numNodes = nodes.length / 5, | |
largeNodes = []; | |
for (var nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) { | |
if (nodes[nodeIndex*5 + 4] > 5000) { | |
console.log('Node '+nodeIndex+' has '+nodes[nodeIndex*5 + 4]+ | |
' references, and is a '+heap['strings'][nodes[nodeIndex*5 + 1]]+'.'); | |
largeNodes.push(nodeIndex); | |
} | |
} | |
return (largeNodes.length > 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
rm -f heapdump-* | |
node --expose-gc server.js & | |
sleep 1 | |
ab -n 10050 -c 100 http://localhost:3463/ | |
kill -USR2 `cat pid` | |
sleep 1 | |
kill `cat pid` | |
node check.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var heapdump = require('heapdump'), | |
fs = require('fs'); | |
var server = http.createServer(function (req, res) { | |
res.end('hi'); | |
global.gc(); | |
}); | |
server.listen(3463); | |
fs.writeFileSync('pid', process.pid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment