Yesterday I tried to create file with huge JSON using small JSONs via concating them. After my file size became 1,5 Gb program got stuck. I tried to understand, what is the reason and found one post on v8 forum. Somebosy said, that v8 has 1Gb memory limit for X64 architecture.But it was posted in 2010. So is there any memory usage limit in modern Node?
var hrTimeStart = process.hrtime();
var hrTimeStartNS = hrTimeStart[0] * 1000000000 + hrTimeStart[1];
say("Starting");
function hrTimeDelta(){
var hrTime = process.hrtime();
var ns = hrTime[0] * 1000000000 + hrTime[1] - hrTimeStartNS;
var ns_del = "000000000" + ns % 1000000000;
return "" + Math.floor(ns / 1000000000) + ":" + ns_del.substring(ns_del.length - 9, ns_del.length);
}
function say(message) {
console.log("[MAIN] (" + hrTimeDelta() + "): " + message);
};
say("before original json load");
var _json = require('./jsons/40k.json');
say("after original json load");
var _zoom = Zoom(_json);
say("after json zooming");
process.on('exit', function(){
say("That's All");
process.exit();
})
//=============================================================
function Zoom(_json){
// just for clone only
var _json_ = JSON.parse(JSON.stringify(_json));
// to create additional group of items and push to "_json_" array
// they are equal to the original, but item.name will be different
// litera from "A" (== 65) to "Z" (== 90) will be added
// up to 69(E) will be OK, but after - it is stoned
for (var i = 65; i < 91; i++){
say("try to add -----> " + i + " (" + String.fromCharCode(i) + "), Current Lenght == " + _json_.length);
console.log(process.memoryUsage());
for (var j = 0; j < _json.length; j++){
// This line is parsed for clone one item.
var item = JSON.parse(JSON.stringify(_json[j]));
item.name += String.fromCharCode(32, i);
_json_.push(item);
}
say("after adding -----> " + i + " (" + String.fromCharCode(i) + "), Current Lenght == " + _json_.length);
console.log(process.memoryUsage());
}
return _json_;
}
Here you can see log of program http://prntscr.com/8j5hcz .Everything is ok there because for loop border was 70, not 91.