Node.JS中是否有内存限制?

时间:2015-09-22 07:53:40

标签: json node.js v8

昨天我尝试使用小JSON创建带有巨大JSON的文件,通过查询它们。我的文件大小变为1,5 Gb程序后卡住了。我试图了解,原因是什么,并在v8论坛上发现了一篇帖子。 Somebosy说,v8对X64架构有1Gb的内存限制。但它是在2010年发布的。现代节点中是否存在内存使用限制?

    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_;
}

在这里你可以看到程序http://prntscr.com/8j5hcz的日志。那里一切都很好,因为循环边框是70而不是91。

0 个答案:

没有答案