node.j에서 GC가 어떻게 작동하는지 이해하려고합니다. v8 엔진이 메모리를 해제하지 않는 것 같습니다.node.js가 메모리를 해제하지 않는 이유는 무엇입니까?
나는 HTTP 서버를 구현하는 매우 간단한 스크립트를 만들었고 메모리 사용량을 매 3 초마다 스트림에 저장합니다. 나는 동안 다음 30 개 요청/초 30 초 동안 마지막 내 HTTP 서버에 요청을 보낼 개틀링을 사용하고 Node.js를 0.10.33
버전 (15 개 요청/초를 사용하고
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);
30 초 후, 100 개의 요청시 30/초)
다음 차트 나타내는 heapUsed
, heapTotal
및 process.memoryUsage()
memory usage after 3 tests
선미 주어진 rss
그 테스트에서 서버에는 아무런 활동도 없지만 1 시간이 지난 후에도 메모리는 해제되지 않습니다. 내 스크립트에서 메모리 누수가있는 경우의 V8 메모리의 표준 동작 인 경우에
누군가가 나를 설명 할 수 있습니까?
해결 방법을 찾으셨습니까? 나는 지금 비슷한 문제에 직면 해있다. – ilse2005