Easy way to book your doctor appointment in kanpur

Booking doctor appointments can be a hassle, but with the EasyToken platform, it doesn’t have to be. EasyToken is a cutting-edge platform that makes booking doctor appointments quick and easy…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Debugging Memory Issues for a Rails App on Heroku

I am running a small-but-robustly-used Rails app cheaply on Heroku (hobby dynos). After seeing warnings (R14 errors) that the app was exceeding the 512MB memory limit, I set out to better understand the app’s memory usage. Was there a specific problem that I needed to fix? Memory leak? Memory bloat? Had the time come to shell out $50/month for two standard dynos on Heroku…or could I optimize it just enough to keep us under the 512MB limit most of the time.

My Situation:

1. Everything relies on memory being allocated. Initially, I was looking at only my application code, and not at the many other ways the application consumed memory…Rails, gems, ActiveRecord lookups, database connections, caching, etc.

2. What does a ‘normal’ memory graph look like? Here are a couple of mine. Once I started to dig into what was behind the memory usage, the less I suspected that memory leak or memory bloat/fragmentation was the culprit.

4. What happens when memory crosses that 512 MB red line? It starts using swap memory, which is super slow. Swap memory is the portion of a dyno’s memory, in megabytes, stored on disk. Reading from disk is slow, which means that using swap memory is significantly slower.

5. Why is my application using 768 MB of memory at 3am when there is no traffic on the application?!

6. Do I have a memory leak? Nope. That would be linear growth (a straight line going up, without ever leveling off.)

For example, the AccompanimentLeader::ActivitiesController#index action.

Fixing the n+1 problem mitigated the memory issues enough for me to let it go for a while. A few months after writing this, I was poking around in Skylight again and found some lines of code that were definitely causing memory issues, which I was able to fix. When I first encountered these memory issues, it felt like they came out of nowhere…but in reality, these were seeds that I had inadvertently planted a year ago that had grown slowly as our application scaled.

Add a comment

Related posts:

A take on approach to Design Management

The Design Management class started with the notion to test ourselves how well we do manage design as a creative field starting from as basic as trying to find your first job to pitching a design…

Who? Me?

You want to hear about me? If you insist. I’m a twenty-two-year-old from south east England, the youngest of four children and currently a student of Creative and Professional Writing at Canterbury…

Moving a movement forward

In the final days of July, the 21Wilberforce team participated in an historic event, which could prove to be a watershed moment for international religious freedom. Hosted by the U.S. Department of…