node 内存限制的问题
发布于 10 年前 作者 name5566 29896 次浏览 最后一次编辑是 8 年前

看了一下关于 node 内存限制的资料,发现众说不一,朴灵的《深入浅出 NodeJS》说道可以通过 --max-old-space-size 和 --max-new-space-size 来设置 v8 使用内存的上限。官方 git 微博上说道:

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.

设置以后最大上限为 1G 和 1.7G。

后来自己测试了一下,貌似最大上限 64 位也就是 1.7G 左右。请问有没有什么办法可以设置内存使用上限的?

22 回复

改改參數 重新編譯一下node。。。

其实这个内存限制是v8… 如果你要用大内存…自己new 一个buff 对象…吧.

两年前的贴… http://cnodejs.org/topic/500904be4764b72902d30f4d

贴这个link 可能跑题了…不过可能是需要用到大内存的一个场景吧…

多用用buffer把,buffer内存的分配是c++层面完成的,不会利用V8的堆内存。。。

Raw data is stored in instances of the Buffer class. A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap.

Windows上的话, 用cluster多开几个核, 内存占用就上去了. 因为会多出好几个node.exe进程

忽然感到很纠结…

你跑什么,要用这么大内存?

@kingapple 游戏服务器

多进程不就行了?非得在一个进程里面跑?

@name5566 为何不直接用C来写:( 是渣渣页游么?

@kingapple 一直用 C++,目前研究研究新的可能。

如果是 web 的话,可能比较好做,但有一些应用场合不太容易做。

@name5566 亲用游戏服务器多久鸟?

@kingapple 刚刚开始研究是否可用在游戏服务器上

@kingapple 手游。页游应该也可以搞。端游用 Node 太激进。

@name5566 端游用 Node 太激进,因为通信量大?

@kingapple 端游比较复杂,大多用 C++。虽然没仔细考虑过,但估计 v8 在 GC 上会有压力。

@name5566 亲做过端游服务器么:)

@kingapple 做了几年。

回到顶部