6

I'm building a nodeJS app which purpose is to convert documents to images. As a consequence, it's pretty heavy on RAM, so when there is a peak I can go up to 100% RAM usage on my server.

My problem is that when it happens, node crashes (out of memory exception), so I'd like to find a way for it not to crash and just do its job "as well as it can".

I know there are alternatives (scaling, queuing, using 'forever' to bring it back up automatically), and am working on that, but in case something fails, it would be cool to know that my server will not just die if RAM happens to be full.

Is there a way to achieve that ?

BPruvost
  • 503
  • 2
  • 5
  • 16
  • 1
    Related: http://stackoverflow.com/questions/16797423/how-to-handle-v8-engine-crash-when-process-runs-out-of-memory – Tomalak Jul 29 '16 at 15:35

1 Answers1

0

I'd do it like this:

  • tasks are queued in a persistent queue
  • several separate node (worker) processes consume the tasks from queue and compute results. Each worker is limited to (say) 1.7GB memory (maximum for node.js process)
  • I presume that the task is rather synchronous and computation heavy so it doesn't make much sense for worker to process more than 1 task at a time.

This gives you the guarantee of not exhausting all the RAM and utilizes the resources of your machine quite efficiently.

Tomas Kulich
  • 14,388
  • 4
  • 30
  • 35