Search code examples
node.jspm2

fork: Cannot allocate memory - Ubuntu NGINX running NodeJS with PM2


I have an Ubuntu droplet on DigitalOcean running NGINX with a reverse proxy to two NodeJS apps which are running on different ports and are managed with PM2.

The issue I am seeing is:

The apps do some screenshotting using puppeteer and then offload the image to a cloud service. But I think when the image processing is done Node runs out of memory and I end up seeing this message:

-bash: fork: Cannot allocate memory

Then the droplet runs slowly and often crashes.

I have this command which I use to start the PM2 service:

pm2 start npm --name "Production" -- start

I have tried the following also but this has not worked. If I change the command order, I simply get error: unknown option--max_old_space_size'`:

pm2 start npm --name "Development" -- start --max-old-space-size=8192 --max-memory-restart 300M

I am running node v12.13.0 and Ubuntu 18.04.3 LTS

Could anyone gives any suggestions on how to solve this please, or at least debug and I can provide more detail?


Solution

  • Use node-args

    —-node-args="max-old-space-size=6144"