My app is up and running on heroku on 5 parallel dynos. There is constant load of 500-1500 req/min so up to 25 req/sec. The problem is that RSS memory is constantly growing. For now I am manually restarting app when memory reaches dangerous level (maximum memory used by 1 heroku dyno is 512mb). Memory chart looks like this (upper gray axis is at 512mb limit):
Moments (on chart) when memory is released are when I am restarting app.
The strange thing is that it happens only when there is constant load on server. When there is for example 2 minutes load on server then memory increases and after that in goes down again. So it seems that for some reason garbage collector is not working properly (it is no collecting the garbage until server load is finished and app is not busy).
Is there anything I can do about it? It is not memory leak I think because memory is released when there is no load on a server...
What I tried so far was:
Maybe there are other options that could help?
Node version is 0.10.20
I used node memwatch
package and I managed to gather heap diffs from app:
So there must be kind of leak I guess. The biggest memory changes from first diff:
...
{
"what": "Array",
"size_bytes": 9320312,
"size": "8.89 mb",
"+": 79086,
"-": 10215
},
...
{
"what": "Closure",
"size_bytes": 2638224,
"size": "2.52 mb",
"+": 36826,
"-": 184
},
{
"what": "Native",
"size_bytes": 21471232,
"size": "20.48 mb",
"+": 546,
"-": 0
},
{
"what": "String",
"size_bytes": 2068264,
"size": "1.97 mb",
"+": 36968,
"-": 1223
},
...
What is Native
object (it allocated 20mb mem!)? Could you give me advice on how to investigate what exactly is causing the leak?
This post goes over how to optimize Heroku dyno memory for Node.js applications. 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 512 MB).
Heroku memory limits free, hobby, and standard-1X dynos can use 512 MB of memory, while standard-2X dynos have access to 1 GB. performance-M and performance-L dynos provide 2.5 and 14 GB of memory. Memory use over these limits writes to disk at much slower speeds than direct RAM access.
When subsequent dependencies are added, npm will make changes to this file, so be sure to add those changes to git too. When an app is deployed, Heroku reads the package.jsonto install the appropriate node version and the package-lock.jsonto install the dependencies. Run the app locally
The problem is that Heroku doesn’t offer this functionality out of the box, instead it lets you deploy apps in various languages (Ruby, Node.js, Python, Java, and PHP). I’m gonna guide you through how to create a simple static web server in node.js deployed on Heroku!
The problem was fixed by simply not using postgres native bindings (https://github.com/brianc/node-postgres#native-bindings). When I stopped using native bindings (I am using Sequelize.js so I just changed native
flag to false) memory started to behave normally...
It seems that there might be leak in pg native bindings?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With