How to solve the memory-leak with send_file (or send_data) on Heroku?

房东的猫 提交于 2019-12-24 14:06:26

问题


I have a Rails 3 app that needs to generate an image and send the data to the browser.

The app must be deployed on Heroku.

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.

https://devcenter.heroku.com/articles/error-codes#r14-memory-quota-exceeded

I am currently using send_data or send_file from ActionController::DataStreaming

http://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_data

Heroku does not support Rack::Sendfile or x-sendfile.

https://devcenter.heroku.com/articles/rack-sendfile

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.

http://code.google.com/p/ruby-mongrel-x-sendfile/

A slow solution to this is to upload every file to Amazon S3 first.

Does anyone have any ideas please?


回答1:


The answer is to start garbage collection with:

GC.start

I placed that line at the bottom of the Rails controller action after send_data.

http://www.ruby-doc.org/core-1.9.3/GC.html



来源:https://stackoverflow.com/questions/12068680/how-to-solve-the-memory-leak-with-send-file-or-send-data-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!