Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js memory filling up

Tags:

node.js

memory

I'm trying to write a program that downloads a large zip file, unzips it in memory, and then pushes the contents (a series of CSV files) to MongoDB. However, I keep hitting a point where the program halts and prints

FATAL ERROR: CodeRange::GetNextAllocationBlock Allocation failed - process out of memory

I've been setting buffers to null when they're no longer in use, setting records to null once they're in Mongo, and preventing more than one file from processing at a time. None of this has helped. Are there any more tricks to releasing memory?

like image 589
Ryan Kennedy Avatar asked Aug 03 '12 18:08

Ryan Kennedy


People also ask

How much RAM is required for node JS?

At least 2GB of RAM.

How do I stop memory leaks in node JS?

Avoid Accidental Globals This could be the result of a typo and could lead to a memory leak. Another way could be when assigning a variable to this within a function in the global scope. To avoid issues like this, always write JavaScript in strict mode using the 'use strict'; annotation at the top of your JS file.

Why does Node run out of memory?

This error usually occurs when the default memory allocated by your system to Node. js is not enough to run a large project. The error is common whether you run your project on Windows, macOS, or a Linux distribution like Ubuntu.


1 Answers

Somethings I would consider would be(not sure if it will all work out as desired):

Make sure references are gone:

  • https://groups.google.com/d/msg/nodejs/ddXqNI_e_pU/NKMHmz4RLsoJ

Performing GC manually and increase v8 heap size:

  • http://blog.caustik.com/2012/04/11/escape-the-1-4gb-v8-heap-limit-in-node-js/

Spawning(and killing) child process from parent process to do work:

  • http://www.robsearles.com/2011/09/28/nodejs-experiments-with-processes/

That way I think the OS will reclaim memory for child process even if it is not returning memory.

Ram as filesystem:

  • http://www.cyberciti.biz/faq/howto-create-linux-ram-disk-filesystem/

That way you can treat filesystem as memory(let operating system put it into memory).

Use freelist:

  • https://groups.google.com/d/msg/nodejs/ddXqNI_e_pU/EP0xUi04xl8J
like image 73
Alfred Avatar answered Sep 28 '22 14:09

Alfred