问题描述
我有一个Rails 3应用,该应用需要生成图像并将数据发送到浏览器.
I have a Rails 3 app that needs to generate an image and send the data to the browser.
该应用必须部署在Heroku上.
The app must be deployed on Heroku.
但是,Heroku仅支持通过保留在内存中的Mongrel进行流传输.然后,这导致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/错误代码#r14-内存配额超额
我当前正在使用ActionController :: DataStreaming中的send_data或send_file
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不支持Rack :: Sendfile或x-sendfile.
Heroku does not support Rack::Sendfile or x-sendfile.
https://devcenter.heroku.com/articles/rack-sendfile
"ruby-mongrel-x-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/
一个慢速解决方案是首先将每个文件上传到Amazon S3.
A slow solution to this is to upload every file to Amazon S3 first.
请问有人有什么想法吗?
Does anyone have any ideas please?
推荐答案
答案是从以下位置开始垃圾收集:
The answer is to start garbage collection with:
GC.start
我将该行放在send_data之后的Rails控制器操作的底部.
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
这篇关于如何用Heroku上的send_file(或send_data)解决内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!