将一个巨大的json对象附加到现有的json数组,得到标记扫描错误

时间:2017-12-22 08:54:03

标签: javascript json

我目前正在尝试生成一个巨大的文件作为项目的数据集。我的getTickersgetAllTickers功能如下:

function getTickers(){
    var tickers = [];
    symbols.forEach(function(s){
        request.get(url+"/pubticker/"+s,
        function(error,response,body){
            jsonObject = {}
            var ticker = body;
            console.log(prettyjson.render(JSON.parse(ticker)))
            jsonObject[s] = ticker;
            tickers.push(jsonObject);
        })
    })
    return tickers;
}
function getAllTickers(){
    tickers = getTickers();
    setTimeout(function(){
    jsonObject = {};
    var time = (new Date()).getTime();
    jsonObject[time] = tickers;
    console.log(jsonObject)
    var jsonToWrite = JSON.stringify(jsonObject);
    fs.appendFile('data.json', jsonToWrite, (err) => {  
        if (err) throw err;
        console.log('tickers at ' +time+ ' saved!');
    });
    }, 15000);
}

然而,当我尝试在while循环中执行此操作时,我收到一个奇怪的错误:

while(true){
    setTimeout(getAllTickers,60000)
}

想知道是否有人知道发生了什么。

错误在这里:

最后几个GC:

6428 ms: Mark-sweep 1381.5 (1426.0) -> 1381.4 (1435.0) MB, 475.5 / 0.0 ms [allocation failure] [scavenge might not succeed].
7098 ms: Mark-sweep 1390.1 (1435.0) -> 1390.2 (1435.0) MB, 658.6 / 0.0 ms (+ 0.1 ms in 139 steps since start of marking, biggest step 0.0 ms) [allocation failure] [scavenge might not succeed].

JS stacktrace:

Cannot get stack trace in GC.
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local, v8::Local) [/usr/local/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
 4: v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::AllocateTargetObject(v8::internal::HeapObject*, v8::internal::HeapObject**) [/usr/local/bin/node]
 5: v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*) [/usr/local/bin/node]
 6: v8::internal::MarkCompactCollector::VisitLiveObjects(v8::internal::MemoryChunk*, v8::internal::MarkCompactCollector::HeapObjectVisitor*, v8::internal::MarkCompactCollector::IterationMode) [/usr/local/bin/node]
 7: v8::internal::MarkCompactCollector::Evacuator::EvacuatePage(v8::internal::MemoryChunk*) [/usr/local/bin/node]
 8: v8::internal::PageParallelJob::Task::RunInternal() [/usr/local/bin/node]
 9: v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [/usr/local/bin/node]
10: v8::internal::MarkCompactCollector::EvacuateNewSpaceAndCandidates() [/usr/local/bin/node]
11: v8::internal::MarkCompactCollector::CollectGarbage() [/usr/local/bin/node]
12: v8::internal::Heap::MarkCompact() [/usr/local/bin/node]
13: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
14: v8::internal::Heap::CollectGarbage(v8::internal::GarbageCollector, char const*, char const*, v8::GCCallbackFlags) [/usr/local/bin/node]
15: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
16: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
17: 0x30adbb6062bf
18: 0x30adbb91a09f
Abort trap: 6

0 个答案:

没有答案