This post goes over how to optimize Heroku dyno memory for Node.js applications.
If your Node.js app is crashing with the error:
Or your Heroku memory usage looks like this:
Then you need to check your app for memory leaks or upgrade to a larger dyno size.
If your dyno has more than
512 MB RAM, then you’re not making use of all the available memory (depending on your Node.js version, the default memory limit can be
To increase the Node.js memory limit, set
--max-old-space-size in the CLI:
node --max-old-space-size=1024 app.js
Or set it as an environment variable with key
NODE_OPTIONS and value
1024 MB is equivalent to 1 GB so to set the size to 2 GB, double the number.
Read more on optimizing dyno usage.
Enable visibility into memory usage with Heroku Labs log-runtime-metrics.
Librato is an add-on for performance monitoring.