NODE.JS:FATAL ERROR- JS分配失败 - 解析大型excel文件时,内存不足 [英] NODE.JS: FATAL ERROR- JS Allocation failed - process out of memory, while parsing large excel files

查看:170
本文介绍了NODE.JS:FATAL ERROR- JS分配失败 - 解析大型excel文件时,内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nodejs解析xlsx文件,并使用模块jsxlsx_async,并将值存储在mongodb中。
我的代码:

  xlsx(file,function(err,wb)){
if(err) {
//处理错误
}
//获取数据数组
wb.getSheetDataByName('Sheet1',function(err,data){
if(err) (
});
});
}

使用:Nodejs:v0.10.25,MongoDB:v2.2.6,
操作系统:win8 ,RAM:6GB



我的步骤:
1.读取上传的xlsx文件,并将这些读取值保存到JS对象中。
2.通过迭代JS对象的值,将读取的值保存到mongodb集合中。



这可以用较小的xlsx文件正常工作,但是我想解析xlsx文件大于50MB。



我的问题是我将整个xlsx值存储在单个JS对象中。
请为解决方案提供一些更好的想法。
有没有更好的方法来读取xlsx行,并且一次读取一行时保存值?

解决方案

之前我有类似的问题。我需要从txt文件中读取一个巨大的JSON对象,但是由于内存不足而导致进程死机。关于这个问题,我的解决方案是将这个巨大的文件分成2个文件。



关于你的问题,我的建议是:


  1. 尝试增加v8引擎的内存限制。 https://github.com/joyent/node/wiki/FAQ 示例(8192表示8GB):

      node --max-old-space-size = 8192 server.js 
    pre>

  2. 如果#1不起作用,请尝试使用此lib逐行阅读xlsx文件: https://github.com/ffalt/xlsx-extract


  3. 如果#1,#2不工作,请尝试 https://github.com/extrabacon/xlrd-parser



I am using nodejs to parse xlsx files with module "jsxlsx_async" and values will be stored in mongodb. My code:

    xlsx(file, function(err,wb){
        if (err){
            //handling err
        }
        //get data array 
        wb.getSheetDataByName('Sheet1', function(err,data){
            if (err){
                //handling err
            }
            //handling data
            console.log(data);
        });
    });

Using: Nodejs: v0.10.25, MongoDB: v2.2.6, OS: win8, RAM:6GB

My steps: 1.read uploaded xlsx file and saving those read values into an JS object. 2.Save the read values into mongodb collections by iterating the values on the JS object.

This works fine with smaller xlsx files but I wanted to parse xlsx files larger than 50MB.

My problem is where I am storing the entire xlsx values in a single JS object. Please provide some better ideas for a solution. Is there any better way to read xlsx by row and saving the values at once a row is read?

解决方案

I had a similar problem before. I need to read a huge JSON object from a txt file, but the process was killed because it ran out of memory. Regarding this problem, my solution was to split this huge file into 2 files.

Regarding your problem, my suggestions are:

  1. Try increasing memory limit of v8 engine. https://github.com/joyent/node/wiki/FAQ Example (8192 means 8GB):

    node --max-old-space-size=8192 server.js 
    

  2. If #1 does not work, try reading xlsx file row by row with this lib: https://github.com/ffalt/xlsx-extract

  3. If #1, #2 do not work, try https://github.com/extrabacon/xlrd-parser

这篇关于NODE.JS:FATAL ERROR- JS分配失败 - 解析大型excel文件时,内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆