Node.js(和 chrome V8)中的内存限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7193959/
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
memory limit in Node.js (and chrome V8)
提问by chacko
In many places in the web, you will see:
在网络的许多地方,您会看到:
What is the memory limit on a node process?
节点进程的内存限制是多少?
and the answer:
和答案:
Currently, by default V8 has a memory limit of 512mb on 32-bit systems, and 1gb on 64-bit systems. The limit can be raised by setting --max-old-space-size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits.
目前,默认情况下,V8 在 32 位系统上的内存限制为 512mb,在 64 位系统上为 1gb。可以通过将 --max-old-space-size 设置为最大 ~1gb(32 位)和 ~1.7gb(64 位)来提高限制,但建议您将单个进程拆分为多个 worker如果您遇到内存限制。
Can somebody confirm this is the case as Node.js seems to update frequently?
有人可以确认这是因为 Node.js 似乎经常更新吗?
And more importantly, will it be the case in the near future?
更重要的是,在不久的将来会是这样吗?
I want to write JavaScript code which might have to deal with 4gb of javascript objects (and speed might not be an issue).
我想编写可能需要处理 4gb javascript 对象的 JavaScript 代码(速度可能不是问题)。
If I can't do it in Node, I will end up doing in java (on a 64bit machine) but I would rather not.
如果我不能在 Node 中做到这一点,我最终会在 Java(在 64 位机器上)进行,但我宁愿不这样做。
回答by Sampsa Suoninen
This has been a big concern for some using Node.js, and there are good news. The new memory limit for V8 is now unknown (not tested) for 64bit and raised to as much as 32bit address space allows in 32bit environments.
对于一些使用 Node.js 的人来说,这一直是一个大问题,并且有好消息。V8 的新内存限制现在对于 64 位未知(未测试),并提高到 32 位环境中允许的 32 位地址空间。
Read more here: http://code.google.com/p/v8/issues/detail?id=847
在此处阅读更多信息:http: //code.google.com/p/v8/issues/detail?id=847
回答by Piyush Katariya
Starting nodejs app with a heap memory of 8 GB
以 8 GB 的堆内存启动 nodejs 应用程序
node --max-old-space-size=8192 app.js
节点 --max-old-space-size=8192 app.js
回答by j03m
I'm running a proc now on Ubuntu linux that has a definite memory leak and node 0.6.0 is pushing 8gb. Think it's handled :).
我现在在 Ubuntu linux 上运行一个 proc,它有一个明确的内存泄漏,节点 0.6.0 正在推动 8gb。认为它已处理:)。
回答by Paul Rumkin
Looks like a true. When i had been tried to allocate 50 Mb string in buffer var buf = new Buffer(50*1024*1024);I got fatal error FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory. I've fixed something around 457 Mb of nodejs memory usage in process monitor.
看起来是真的。当我试图在缓冲区中分配 50 Mb 字符串时,var buf = new Buffer(50*1024*1024);我遇到了致命错误FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory。我在进程监视器中修复了大约 457 Mb 的 nodejs 内存使用量。
回答by Huan
Memory Limit Max Value is 3049for 32bit users
32 位用户的内存限制最大值为3049
If you are running Node.js with os.arch() === 'ia32'is true, the max value you can set is 3049
如果您在运行 Node.js 时设置os.arch() === 'ia32'为 true,则可以设置的最大值为3049
under my testing with node v11.15.0 and windows 10
在我对 node v11.15.0 和 windows 10 的测试下
- if you set it to 3050, then it will overflow and equal to be set to 1.
- if you set it to 4000, then it will equal to be set to 51 (4000 - 3049)
- 如果将其设置为 3050,则它将溢出并等于设置为 1。
- 如果您将其设置为 4000,那么它将等于设置为 51 (4000 - 3049)
node --max-old-space-size=3049
使用 TypeScript 将 Node.js 的内存设置为 Max
node -r ts-node/register --max-old-space-size=3049
See: https://github.com/TypeStrong/ts-node/issues/261#issuecomment-402093879
参见:https: //github.com/TypeStrong/ts-node/issues/261#issuecomment-402093879

