I have a simple NodeJs application that acts as a REST client and requests large JSON object. The problem is that it always runs out of memory (taking more than 6Gb). I am using manual garbage collection (app started with --expose_gc) but that doesn't seem to help much.
Here's my code:
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();
I have tried request library but I had the same results. What am I doing wrong?
P.s. My nodejs version is 6.9.1, needle version 1.3.0