REST 클라이언트 역할을하며 큰 JSON 객체를 요청하는 간단한 NodeJs 애플리케이션이 있습니다. 문제는 항상 메모리가 부족하다는 것입니다 (6Gb 이상 소요). 수동 가비지 수집 (--expose_gc로 시작한 응용 프로그램)을 사용하고 있지만 도움이되지 않습니다.큰 JSON 객체를 요청하면 메모리 누수가 발생합니다.
여기 내 코드입니다 : 내가 요청 라이브러리를 시도
var needle = require('needle');
function getAllData() {
getDataFromUrl("http://puppygifs.tumblr.com/api/read/json");
getDataFromUrl("http://puppygifs.tumblr.com/api/read/json");
getDataFromUrl("http://puppygifs.tumblr.com/api/read/json");
getDataFromUrl("http://puppygifs.tumblr.com/api/read/json");
getDataFromUrl("http://puppygifs.tumblr.com/api/read/json");
setInterval(function() {
getAllData();
}, 10 * 1000);
}
function getDataFromUrl(url) {
needle.get(url, function (error, response) {
if (!error && response.statusCode == 200) {
console.log("do something");
}
});
}
function scheduleGc() {
global.gc();
setTimeout(function() {
scheduleGc();
}, 100 * 1000);
}
getAllData();
scheduleGc();
하지만 동일한 결과가 있었다. 내가 도대체 뭘 잘못하고있는 겁니까?
p.s. 내 nodejs 버전 6.9.1, 바늘 버전 1.3.0
json으로는 많이 이하, 6 기가 바이트되지 않습니다 :
다음은 예입니다. 6Gb는 setTimeout 대신 setInterval을 사용했기 때문에 사용 된 RAM의 양이었습니다 ... – Jkam