这里有点困惑。我的 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).
关于javascript - Node 内存使用情况和内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56493753/