javascript - Node 内存使用情况和内存不足

标签 javascript node.js v8

这里有点困惑。我的 Node 服务崩溃了。但是,使用的堆远远低于堆总数?

{"rss":8120283136,"heapTotal":7640494080,"heapUsed":4244076904,"external":33576},"msg":"STATS","v":1}

<--- Last few GCs --->

[1:0x2a1edc0] 30954759 ms: Mark-sweep 4017.1 (7221.0) -> 4017.1 (7152.0) MB, 2222.4 / 0.0 ms  (average mu = 0.889, current mu = 0.000) last resort GC in old space requested

使用 --max-old-space-size=7168 运行

我认为至少应该有 3 GB 可用堆?

最佳答案

V8 中,内置对象有很多硬编码的大小限制,您可以达到其中之一。这里有几个例子:

FWIW, there are limits to everything: besides the maximum heap size, there's a maximum String length, a maximum Array length, a maximum ArrayBuffer length, a maximum BigInt size, a maximum stack size, etc. Any one of those limits is potentially debatable, and sometimes it makes sense to raise them, but the limits as such will remain. Off the top of my head I don't know what it would take to bump this particular limit by, say, a factor of two -- and I also don't know whether a factor of two would be enough to satisfy your expectations.

V8 开发者 jmrk

In summer 2017, V8 increased the maximum size of strings from ~256MB to ~1GB. Specifically, from 2^28 - 16 to 2^30 - 25 on 64-bit platforms.

V8/Node.js increase max allowed String length

The limit is determined by:

The FixedArray backing store of the Map has a maximum size of 1GB (independent of the overall heap size limit) On a 64-bit system that means 1GB / 8B = 2^30 / 2^3 = 2^27 ~= 134M maximum elements per FixedArray A Map needs 3 elements per entry (key, value, next bucket link), and has a maximum load factor of 50% (to avoid the slowdown caused by many bucket collisions), and its capacity must be a power of 2. 2^27 / (3 * 2) rounded down to the next power of 2 is 2^24, which is the limit you observe.

Maximum number of entries in Node.js Map?

However, the maximum length of an array according to the ECMA-262 5th Edition specification is bound by an unsigned 32-bit integer due to the ToUint32 abstract operation, so the longest possible array could have 232-1 = 4,294,967,295 = 4.29 billion elements.

Maximum size of an Array in Javascript

Maximum length of a typed array in V8 is currently set to kSmiMaxValue which depending on the platform is either:

1Gb - 1byte on 32-bit 2Gb - 1byte on 64-bit Relevant constant in the code is v8::internal::JSTypedArray::kMaxLength (source).

V8 team is working on increasing this even further on 64-bit platforms, where currently ArrayBuffer objects can be up to Number.MAX_SAFE_INTEGER large (2**53 - 1).

What's the maximum size of a Node.js Buffer

关于javascript - Node 内存使用情况和内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56493753/

相关文章:

javascript - jQuery 未捕获范围错误 : Maximum call stack size exceeded in google chrome

javascript - 对象的部分垃圾收集可能吗? (服务器端JS)

javascript - jquery xml解析查找具有特定属性的节点而不循环

javascript - 使用 jquery 验证 Facebook 和 Twitter URL

javascript - 尝试 console.log 我从 socket.io 收到的消息时收到 401~UNAUTHORIZED

node.js - 如何清除指数项目中未满足的对等依赖错误

javascript - 目前是否有任何引擎可将 JavaScript 编译为具有图形支持的独立应用程序?

javascript - 为什么在这种情况下原生 promise 似乎比 chrome 中的回调更快?

javascript - ajax 的 ajax 硬编码值(新手)

node.js - SELECT 具有多列主键的行