ronag
ronag

Reputation: 51255

Node Memory Usage & Out Of Memory

A bit of confusion here. I have a node service crashing. However, heap used is much lower than heap total?

{"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

Running with --max-old-space-size=7168

It looks to me that there should be at least 3 GB heap available?

Upvotes: 2

Views: 546

Answers (1)

ponury-kostek
ponury-kostek

Reputation: 8060

In V8 there is a lot of hard coded size limits on built-in objects, you could reach one of them. Here's couple examples:

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 developer 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

Upvotes: 2

Related Questions