How to fix FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
I know i am dealing with large data sets (almost around 8GB) but while doing it i am getting the following exception
MacBook-Pro:mongo-stress-test experimental$ node index.js
Mongodb connected
<--- Last few GCs --->
[73547:0x103000000] 156484 ms: Mark-sweep 1417.2 (1466.3) -> 1417.2 (1449.8) MB, 461.2 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 461 ms) last resort
[73547:0x103000000] 156950 ms: Mark-sweep 1417.2 (1449.8) -> 1417.1 (1449.8) MB, 466.2 / 0.0 ms last resort
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x281a45d1bbd9 <JS Object>
1: mergeOptionsAndWriteConcern(aka mergeOptionsAndWriteConcern) [/Users/experimental/Documents/githome/mongo-stress-test/node_modules/mongodb/lib/utils.js:~327] [pc=0x18a836371372](this=0x281a45d02241 <undefined>,targetOptions=0x15081ed04e1 <an Object with map 0x1c34af5f8971>,sourceOptions=0xa31de208389 <an Object with map 0x1c34af5ee629>,keys=0xa31de203cc1 <JS Array[9]>,mergeWriteConcern=0...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewStruct(v8::internal::InstanceType) [/usr/local/bin/node]
5: v8::internal::Factory::NewTuple3(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
6: v8::internal::LoadIC::UpdateCaches(v8::internal::LookupIterator*) [/usr/local/bin/node]
7: v8::internal::LoadIC::Load(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>) [/usr/local/bin/node]
8: v8::internal::KeyedLoadIC::Load(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
9: v8::internal::Runtime_KeyedLoadIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
10: 0x18a8362040bd
Abort trap: 6
MacBook-Pro:mongo-stress-test experimental$
1 Answer
7 years ago by Divya
Default limit of NodeJS applications on 64 bit machines is 1.76 GB
You can use --max_old_space_size
argument to increase the default limit
Let say if you want to run your NodeJS application with 8GB memory then start your app with following command
node --max-old-space-size=8142 index.js
7 years ago by Karthik Divi