Imagemagick On Heroku-16

I recently encountered some strange memory issues after upgrading to Heroku-16. I was a little surprised at what I found regarding Imagemagick on Heroku.

Posted by Curtis Miller Curtis Miller

We recently upgraded from Heroku's Cedar-14 stack to their Heroku-16 stack after receiving a stack deprecation warning.

First we prototyped this upgrade with our staging server and, after a week, did not encounter any issues. Feeling pretty confident with Heroku, we initiated the update. Within 24 hours we were experiencing extreme memory issues (R15 - Memory quota vastly exceeded), causing the site to be unreachable.

Break Out The Fire Extenguisher

Okay, so we set our app on fireā€¦ this is fine.

We looked at a lot of different possibilities, added extra monitoring, and ultimately made some changes to help improve the memory usage of the app. I may detail that in separate posts. However, something strange stuck out to us when we were investigating Imagemagick on Heroku.

Heroku typically gives each user a slice of the total system resources, a dyno. Unless you're on a performance dyno, you'll share the overall system resources with other applications. It seems like Heroku gives apps a little leeway when it comes to resources. For example, an app might temporarily use more memory than it was alloted, without serious repercussions, just some warnings.

We expected that Imagemagick would have some reasonable default limits in place that corresponded to the dyno size, but what we found surprised us. There were no limits set at all.

So, if you do want to prevent Imagemagick from using too many resources, you can user Heroku's config option to set Imagemagick environment variables.

What do you think? Have a different workaround or solution?

Velocity Labs

Need web application development, maintenance for your existing app, or a third party code review?

Velocity Labs can help.

Hire us!