title: How to solve the memory-leak with send_file (or send_data) on Heroku?
body: <p>I have a Rails 3 app that needs to generate an image and send the data to the browser.</p>
  
  <p>The app must be deployed on Heroku.</p>
  
  <p>However, Heroku only supports streaming through Mongrel which holds on to the memory. This then causes Heroku to slow, then kill the thread after a dozen or so requests.</p>
  
  <p><a href="https://devcenter.heroku.com/articles/error-codes#r14-memory-quota-exceeded" rel="nofollow">https://devcenter.heroku.com/articles/error-codes#r14-memory-quota-exceeded</a></p>
  
  <p>I am currently using send_data or send_file from ActionController::DataStreaming</p>
  
  <p><a href="http://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_data" rel="nofollow">http://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_data</a></p>
  
  <p>Heroku does not support Rack::Sendfile or x-sendfile.</p>
  
  <p><a href="https://devcenter.heroku.com/articles/rack-sendfile" rel="nofollow">https://devcenter.heroku.com/articles/rack-sendfile</a></p>
  
  <p>The project "ruby-mongrel-x-sendfile" says: "Streaming very much data through mongrel is a bad thing; springs stringy memory leaks" and provides an "in-mongrel solution". But it doesn't look like a good solution.</p>
  
  <p><a href="http://code.google.com/p/ruby-mongrel-x-sendfile/" rel="nofollow">http://code.google.com/p/ruby-mongrel-x-sendfile/</a></p>
  
  <p>A slow solution to this is to upload every file to Amazon S3 first.</p>
  
  <p>Does anyone have any ideas please?</p>