19

Im a newbie in nodejs and mongodb. I have a problem when i read about 100000 records from my mongodb in nodejs application. When I try to get 100000 records, I got this error:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

I search google and everyone said that configure max old space size parameter because v8 engine have about 1,9Gb heap memmory.

My point is, I run my app by eclispe, and i dont know how to configure max-old-space-size parameter.

Can anybody give a hint?

Thank you so much!

ps: my english is bad so if you cannot understand my question, it's fine.

user1697646
  • 333
  • 2
  • 6
  • 15

2 Answers2

25

Use node --max_old_space_size=5000 yourapp.js to allow 5000 mb. Look in your eclipse launch settings for command-line parameters, where you can add this.

However, as the comments say, you should reconsider loading this into memory, and stream it to the client instead.

ZachB
  • 13,051
  • 4
  • 61
  • 89
  • thank you for your comment. as you said "loading this into memory, and stream it to the client". can you show me docs or whatever can help to do that, because i have no idea to start. – user1697646 Dec 04 '15 at 03:49
  • Check out this question: http://stackoverflow.com/questions/7372626/how-to-stream-mongodb-query-results-with-nodejs – ZachB Dec 04 '15 at 04:17
  • 9
    is it "--max_old_space_size=5000" or "--max-old-space-size=5000" ?! this is confusing – Fareed Alnamrouti Jul 18 '16 at 04:22
  • 4
    @ZachB according to the node documentation: v8 options allow words to be separated by both dashes (-) or underscores (_). For example, --stack-trace-limit is equivalent to --stack_trace_limit. (from https://nodejs.org/api/cli.html#cli_v8_options) – Kevin Borders Apr 24 '17 at 01:02
  • 1
    do we have to run this command everytime i run the node in Terminal or once run, sets forever? – Techdive Jan 07 '19 at 12:05
  • 1
    @Techdive Yes, you have to include this option each time you run the `node` command – OtotheA Feb 28 '19 at 03:12
-3

you could add the following to your package.json

"scripts": {
    "start": "node --max-old-space-size=102400 ./app.js",
     ......
}

this is unlike the other way has to write only once and configured each run time. Note: you no need to run explicitly this command the npm start will take care of configuring it each time

arasif
  • 216
  • 2
  • 6
  • 3
    The default value of `--max-old-space-size` is 1024, i.e. 1GB. You're giving it over 100GB of memory! – cst1992 Apr 14 '20 at 08:06