I am running a strongloop API on Heroku, and have had no issues till I made a few minor changes and now I get massive memory use problems, such that the application crashes:
2015-04-20T09:48:02.414727+00:00 heroku[web.1]: Process running mem=728M(142.2%)
2015-04-20T09:48:02.414771+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
The weird thing is that this does NOT happen when I run locally using NODE_ENV='production' slc run
When I monitor memory usage while running locally, I get a total (between the 4 worker processes) of about 330MB vs 728MB+ when running exactly the same thing on Heroku.
Rolling back to a previous version of my application works just fine, but I cannot see how the changes I implemented could have caused the memory use to go out of control like this. Here's what I essentially changed:
fixed a mis-typed check for custom environment variable on boot
created a datasources.development.json as well datasources.production.json files, to ensure that in development mode I connect to a memory database instead of the live MongoLab hosted database
made some ACL changes to two of my models to allow an admin user to write via the API (works fine locally)
datasources.development.json looks like this:
{
"KaranMongo_live": {
"name": "KaranMongo_live",
"connector": "memory",
"file": "db.json"
},
"MyEmail": {
"name": "MyEmail",
"connector": "mail",
"transports": [
{
"type": "smtp",
"host": "smtp.mandrillapp.com",
"secure": true,
"port": 465,
"tls": {
"rejectUnauthorized": false
},
"auth": {
"user": "HIDDEN",
"pass": "HIDDEN"
}
}
]
}
}
And datasources.production.json looks like this:
{
"KaranMongo_live": {
"host": "ds043471-a0.mongolab.com",
"port": 43471,
"database": "HIDDEN",
"username": "HIDDEN",
"password": "HIDDEN",
"name": "KaranMongo_live",
"connector": "mongodb"
},
"MyEmail": {
"name": "MyEmail",
"connector": "mail",
"transports": [
{
"type": "smtp",
"host": "smtp.mandrillapp.com",
"secure": true,
"port": 465,
"tls": {
"rejectUnauthorized": false
},
"auth": {
"user": "HIDDEN",
"pass": "HIDDEN"
}
}
]
}
}
I am really stumped. Any ideas what might be happening? Or at least how I would go about tracing the cause of the problem?
UPDATE:
I'm getting a little closer to an answer. It seems that setting NODE_ENV=production
is the culprit, since it has a side effect I didn't anticipate - it make loopback launch with 4 worker nodes instead of just a single process, and this overwhelms the memory provided by Heroku. I'm renaming my datasources.production.json to datasources.live.json and setting NODE_ENV=live
to see whether the problem goes away.