title: Heroku Error R14 (Memory quota exceeded): How do I solve this?
body: <p>I have a Rails 3.1 app on Heroku. I am seeing a lot of these errors:</p>
  
  <blockquote>
    <p>Error R14 (Memory quota exceeded)</p>
  </blockquote>
  
  <p>Typically the preceding log entry is showing:</p>
  
  <blockquote>
    <p>Process running mem=522M(102.1%)</p>
  </blockquote>
  
  <p>This does vary a little but never by much and can occur after almost any URL request, so it's not related to a specific controller action as far as I can tell.</p>
  
  <p>This is a classic block of log entries:</p>
  
  <pre><code>2012-01-16T02:35:57+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=55ms status=401 bytes=27
  2012-01-16T02:35:58+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=155ms status=200 bytes=1
  2012-01-16T02:36:02+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=13ms status=401 bytes=27
  2012-01-16T02:36:02+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=147ms status=200 bytes=1
  2012-01-16T02:36:09+00:00 heroku[router]: POST prizequiz.herokuapp.com/mobile_users dyno=web.1 queue=0 wait=0ms service=87ms status=201 bytes=624
  2012-01-16T02:36:11+00:00 heroku[router]: GET prizequiz.herokuapp.com/quizzes/1/questions dyno=web.1 queue=0 wait=0ms service=5ms status=401 bytes=27
  2012-01-16T02:36:11+00:00 heroku[router]: GET prizequiz.herokuapp.com/quizzes/1/questions dyno=web.1 queue=0 wait=0ms service=290ms status=200 bytes=81412
  2012-01-16T02:36:15+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=10ms status=401 bytes=27
  2012-01-16T02:36:16+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=67ms status=200 bytes=1
  2012-01-16T02:36:33+00:00 heroku[router]: POST prizequiz.herokuapp.com/quizzes/1/scores dyno=web.1 queue=0 wait=0ms service=10ms status=401 bytes=27
  2012-01-16T02:36:33+00:00 heroku[router]: POST prizequiz.herokuapp.com/quizzes/1/scores dyno=web.1 queue=0 wait=0ms service=132ms status=201 bytes=230
  2012-01-16T02:36:55+00:00 heroku[web.1]: Process running mem=522M(102.1%)
  2012-01-16T02:36:55+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-16T02:37:17+00:00 app[web.1]: 
  2012-01-16T02:37:17+00:00 app[web.1]: 
  2012-01-16T02:37:17+00:00 app[web.1]: Started POST "/quizzes/1/scores" for 177.53.80.25 at 2012-01-16 02:37:17 +0000
  2012-01-16T02:37:17+00:00 app[web.1]: cache: [POST /quizzes/1/scores] invalidate, pass
  2012-01-16T02:37:17+00:00 app[web.1]: 
  2012-01-16T02:37:17+00:00 app[web.1]: 
  2012-01-16T02:37:17+00:00 app[web.1]: Started POST "/quizzes/1/scores" for 177.53.80.25 at 2012-01-16 02:37:17 +0000
  2012-01-16T02:37:17+00:00 app[web.1]: cache: [POST /quizzes/1/scores] invalidate, pass
  2012-01-16T02:37:17+00:00 heroku[router]: POST prizequiz.herokuapp.com/quizzes/1/scores dyno=web.1 queue=0 wait=0ms service=44ms status=201 bytes=230
  2012-01-16T02:37:17+00:00 heroku[web.1]: Process running mem=522M(102.1%)
  2012-01-16T02:37:17+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-16T02:37:17+00:00 heroku[router]: POST prizequiz.herokuapp.com/quizzes/1/scores dyno=web.1 queue=0 wait=0ms service=16ms status=401 bytes=27
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: Started GET "/quizzes/1/scores/current_game" for 177.53.80.25 at 2012-01-16 02:37:20 +0000
  2012-01-16T02:37:20+00:00 app[web.1]: cache: [GET /quizzes/1/scores/current_game] miss
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: Started GET "/quizzes/1/scores/current_game" for 177.53.80.25 at 2012-01-16 02:37:20 +0000
  2012-01-16T02:37:20+00:00 heroku[router]: GET prizequiz.herokuapp.com/quizzes/1/scores/current_game dyno=web.1 queue=0 wait=0ms service=8ms status=401 bytes=27
  2012-01-16T02:37:20+00:00 app[web.1]: cache: [GET /quizzes/1/scores/current_game] miss
  2012-01-16T02:37:20+00:00 heroku[router]: GET prizequiz.herokuapp.com/quizzes/1/scores/current_game dyno=web.1 queue=0 wait=0ms service=6ms status=401 bytes=27
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: Started POST "/quizzes/1/scores" for 177.53.80.25 at 2012-01-16 02:37:20 +0000
  2012-01-16T02:37:20+00:00 heroku[router]: POST prizequiz.herokuapp.com/quizzes/1/scores dyno=web.1 queue=0 wait=0ms service=33ms status=401 bytes=27
  2012-01-16T02:37:20+00:00 app[web.1]: cache: [POST /quizzes/1/scores] invalidate, pass
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: Started GET "/quizzes/1/scores/current_game" for 177.53.80.25 at 2012-01-16 02:37:20 +0000
  2012-01-16T02:37:20+00:00 app[web.1]: 
  2012-01-16T02:37:20+00:00 app[web.1]: 
  </code></pre>
  
  <p>I have New Relic installed but have been unable to identify anything of any use.</p>
  
  <p>Will gladly supply more info if needed. I also have an outstanding support request on Heroku for this but as yet (2 days marked as urgent) I have had no response.</p>
  
  <p>Adding web dynos makes no difference.</p>
  
  <p><strong>UPDATE</strong>, I have added the oink gem and this is a sample result</p>
  
  <pre><code>2012-01-26T08:24:25+00:00 app[web.1]: 
  2012-01-26T08:24:25+00:00 app[web.1]: 
  2012-01-26T08:24:25+00:00 app[web.1]: Started PUT "/mobile_users/1" for 110.49.234.219 at 2012-01-26 08:24:25 +0000
  2012-01-26T08:24:26+00:00 app[web.1]: Oink Action: mobile_users#update
  2012-01-26T08:24:26+00:00 app[web.1]: Memory usage: 286276 | PID: 16
  2012-01-26T08:24:26+00:00 app[web.1]: Instantiation Breakdown: Total: 2 | MobileUser: 2
  2012-01-26T08:24:26+00:00 app[web.1]: Oink Log Entry Complete
  2012-01-26T08:24:26+00:00 app[web.1]: cache: [PUT /mobile_users/1] invalidate, pass
  2012-01-26T08:24:26+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=460ms status=200 bytes=1
  2012-01-26T08:24:38+00:00 heroku[web.1]: Process running mem=537M(104.9%)
  2012-01-26T08:24:38+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:24:43+00:00 app[web.1]: 
  2012-01-26T08:24:43+00:00 app[web.1]: 
  2012-01-26T08:24:43+00:00 app[web.1]: Started PUT "/mobile_users/1" for 103.1.165.23 at 2012-01-26 08:24:43 +0000
  2012-01-26T08:24:43+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=544ms status=401 bytes=27
  2012-01-26T08:24:43+00:00 app[web.1]: Oink Action: mobile_users#update
  2012-01-26T08:24:43+00:00 app[web.1]: Memory usage: 288876 | PID: 19
  2012-01-26T08:24:43+00:00 app[web.1]: Instantiation Breakdown: Total: 0
  2012-01-26T08:24:43+00:00 app[web.1]: Oink Log Entry Complete
  2012-01-26T08:24:43+00:00 app[web.1]: cache: [PUT /mobile_users/1] invalidate, pass
  2012-01-26T08:24:47+00:00 app[web.1]: 
  2012-01-26T08:24:47+00:00 app[web.1]: 
  2012-01-26T08:24:47+00:00 app[web.1]: Started PUT "/mobile_users/1" for 103.1.165.23 at 2012-01-26 08:24:47 +0000
  2012-01-26T08:24:48+00:00 app[web.1]: Oink Action: mobile_users#update
  2012-01-26T08:24:48+00:00 app[web.1]: Memory usage: 286412 | PID: 16
  2012-01-26T08:24:48+00:00 app[web.1]: Instantiation Breakdown: Total: 2 | MobileUser: 2
  2012-01-26T08:24:48+00:00 app[web.1]: Oink Log Entry Complete
  2012-01-26T08:24:48+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=432ms status=200 bytes=1
  2012-01-26T08:24:48+00:00 app[web.1]: cache: [PUT /mobile_users/1] invalidate, pass
  2012-01-26T08:24:59+00:00 heroku[web.1]: Process running mem=537M(104.9%)
  2012-01-26T08:24:59+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:25:20+00:00 heroku[web.1]: Process running mem=537M(104.9%)
  2012-01-26T08:25:20+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:25:41+00:00 heroku[web.1]: Process running mem=537M(104.9%)
  2012-01-26T08:25:41+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:26:32+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=34ms status=401 bytes=27
  2012-01-26T08:27:04+00:00 app[web.1]: 
  2012-01-26T08:27:04+00:00 app[web.1]: 
  2012-01-26T08:27:04+00:00 app[web.1]: Started PUT "/mobile_users/1" for 103.1.165.23 at 2012-01-26 08:27:04 +0000
  2012-01-26T08:27:04+00:00 app[web.1]: Oink Action: mobile_users#update
  2012-01-26T08:27:04+00:00 app[web.1]: Memory usage: 288876 | PID: 19
  2012-01-26T08:27:04+00:00 app[web.1]: Instantiation Breakdown: Total: 2 | MobileUser: 2
  2012-01-26T08:27:04+00:00 app[web.1]: Oink Log Entry Complete
  2012-01-26T08:27:04+00:00 app[web.1]: cache: [PUT /mobile_users/1] invalidate, pass
  2012-01-26T08:27:04+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=337ms status=200 bytes=1
  2012-01-26T08:27:05+00:00 heroku[web.1]: Process running mem=537M(104.9%)
  2012-01-26T08:27:05+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:27:26+00:00 heroku[web.1]: Process running mem=537M(104.9%)
  2012-01-26T08:27:26+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:27:48+00:00 heroku[web.1]: Process running mem=537M(104.9%)
  2012-01-26T08:27:48+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:28:08+00:00 heroku[web.1]: Process running mem=537M(105.0%)
  2012-01-26T08:28:08+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:28:29+00:00 heroku[web.1]: Process running mem=537M(105.0%)
  2012-01-26T08:28:29+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:28:51+00:00 heroku[web.1]: Process running mem=537M(105.0%)
  2012-01-26T08:28:51+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:29:08+00:00 app[web.1]: 
  2012-01-26T08:29:08+00:00 app[web.1]: 
  2012-01-26T08:29:08+00:00 app[web.1]: Started PUT "/mobile_users/1" for 85.26.234.218 at 2012-01-26 08:29:08 +0000
  2012-01-26T08:29:08+00:00 app[web.1]: Oink Action: mobile_users#update
  2012-01-26T08:29:08+00:00 app[web.1]: Memory usage: 382404 | PID: 13
  2012-01-26T08:29:08+00:00 app[web.1]: Instantiation Breakdown: Total: 0
  2012-01-26T08:29:08+00:00 app[web.1]: Oink Log Entry Complete
  2012-01-26T08:29:08+00:00 app[web.1]: cache: [PUT /mobile_users/1] invalidate, pass
  2012-01-26T08:29:08+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=86ms status=401 bytes=27
  2012-01-26T08:29:09+00:00 app[web.1]: 
  2012-01-26T08:29:09+00:00 app[web.1]: 
  2012-01-26T08:29:09+00:00 app[web.1]: Started PUT "/mobile_users/1" for 85.26.234.218 at 2012-01-26 08:29:09 +0000
  2012-01-26T08:29:09+00:00 app[web.1]: Oink Action: mobile_users#update
  2012-01-26T08:29:09+00:00 app[web.1]: Memory usage: 382404 | PID: 13
  2012-01-26T08:29:09+00:00 app[web.1]: Instantiation Breakdown: Total: 2 | MobileUser: 2
  2012-01-26T08:29:09+00:00 app[web.1]: Oink Log Entry Complete
  2012-01-26T08:29:09+00:00 app[web.1]: cache: [PUT /mobile_users/1] invalidate, pass
  2012-01-26T08:29:09+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=160ms status=200 bytes=1
  2012-01-26T08:29:11+00:00 app[web.1]: 
  2012-01-26T08:29:11+00:00 app[web.1]: 
  2012-01-26T08:29:11+00:00 app[web.1]: Started PUT "/mobile_users/1" for 85.26.234.218 at 2012-01-26 08:29:11 +0000
  2012-01-26T08:29:11+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=101ms status=401 bytes=27
  2012-01-26T08:29:11+00:00 app[web.1]: Oink Action: mobile_users#update
  2012-01-26T08:29:11+00:00 app[web.1]: Memory usage: 382404 | PID: 13
  2012-01-26T08:29:11+00:00 app[web.1]: Instantiation Breakdown: Total: 0
  2012-01-26T08:29:11+00:00 app[web.1]: Oink Log Entry Complete
  2012-01-26T08:29:11+00:00 app[web.1]: cache: [PUT /mobile_users/1] invalidate, pass
  2012-01-26T08:29:12+00:00 app[web.1]: 
  2012-01-26T08:29:12+00:00 app[web.1]: 
  2012-01-26T08:29:12+00:00 app[web.1]: Started PUT "/mobile_users/1" for 85.26.234.218 at 2012-01-26 08:29:12 +0000
  2012-01-26T08:29:12+00:00 heroku[web.1]: Process running mem=537M(105.0%)
  2012-01-26T08:29:12+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  2012-01-26T08:29:12+00:00 app[web.1]: Oink Action: mobile_users#update
  2012-01-26T08:29:12+00:00 app[web.1]: Memory usage: 288876 | PID: 19
  2012-01-26T08:29:12+00:00 app[web.1]: Instantiation Breakdown: Total: 2 | MobileUser: 2
  2012-01-26T08:29:12+00:00 app[web.1]: Oink Log Entry Complete
  2012-01-26T08:29:12+00:00 app[web.1]: cache: [PUT /mobile_users/1] invalidate, pass
  2012-01-26T08:29:12+00:00 heroku[router]: PUT prizequiz.herokuapp.com/mobile_users/1 dyno=web.1 queue=0 wait=0ms service=169ms status=200 bytes=1
  2012-01-26T08:29:33+00:00 heroku[web.1]: Process running mem=537M(105.0%)
  2012-01-26T08:29:33+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
  </code></pre>
  
  <p>I have no idea what that proves other than it seems I am not using as much memory as Heroku thinks I am
  Memory usage: 288876 vs Process running mem=537M(105.0%)</p>