node.js 在 Nodejs 中配置最大旧空间大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34079918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
configuration max old space size in Nodejs
提问by user1697646
Im a newbie in nodejs and mongodb. I have a problem when i read about 100000 records from my mongodb in nodejs application. When I try to get 100000 records, I got this error:
我是 nodejs 和 mongodb 的新手。当我在 nodejs 应用程序中从 mongodb 读取大约 100000 条记录时遇到问题。当我尝试获取 100000 条记录时,出现此错误:
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
致命错误:CALL_AND_RETRY_LAST 分配失败 - 进程内存不足
I search google and everyone said that configure max old space size parameter because v8 engine have about 1,9Gb heap memmory.
我搜索谷歌,每个人都说配置最大旧空间大小参数,因为 v8 引擎有大约 1,9Gb 堆内存。
My point is, I run my app by eclispe, and i dont know how to configure max-old-space-size parameter.
我的观点是,我通过 eclispe 运行我的应用程序,但我不知道如何配置 max-old-space-size 参数。
Can anybody give a hint?
有人可以给一个提示吗?
Thank you so much!
非常感谢!
ps: my english is bad so if you cannot understand my question, it's fine.
ps:我的英语不好,所以如果你不能理解我的问题,没关系。
回答by ZachB
Use node --max_old_space_size=5000 yourapp.jsto allow 5000 mb. Look in your eclipse launch settings for command-line parameters, where you can add this.
使用node --max_old_space_size=5000 yourapp.js允许5000万桶。查看命令行参数的 eclipse 启动设置,您可以在其中添加它。
However, as the comments say, you should reconsider loading this into memory, and stream it to the client instead.
但是,正如评论所说,您应该重新考虑将其加载到内存中,并将其流式传输到客户端。
回答by arasif
you could add the following to your package.json
您可以将以下内容添加到您的 package.json
"scripts": {
"start": "node --max-old-space-size=102400 ./app.js",
......
}
this is unlike the other way has to write only once and configured each run time. Note: you no need to run explicitly this command the npm start will take care of configuring it each time
这与其他方式不同,只需编写一次并在每次运行时进行配置。注意:您无需显式运行此命令,npm start 将负责每次配置它

