-->

如何解决内存泄漏与在Heroku由send_file(或SEND_DATA)?(How to sol

2019-10-17 04:07发布

我有一个Rails应用程序3需要生成图像和数据发送到浏览器。

该应用程序必须部署在Heroku上。

然而,Heroku的只支持通过杂种持有到内​​存流。 这进而导致Heroku的要慢,然后杀死十几请求后,该线程。

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

我目前使用SEND_DATA或由send_file从ActionController的:: DataStreaming

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

Heroku的不支持机架:: SENDFILE或x-sendfile的。

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

该项目“红宝石杂种-X-的sendfile”说:“通过杂种流非常多的数据是一件坏事;弹簧弦内存泄漏”,并提供了一个“内杂种的解决方案”。 不过,这并不像一个很好的解决方案。

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

缓慢的解决方法是先上传每个文件到Amazon S3。

有没有人有任何想法吗?

Answer 1:

答案是启动垃圾收集:

GC.start

我把该行之后在SEND_DATA滑轨控制器动作的底部。

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



文章来源: How to solve the memory-leak with send_file (or send_data) on Heroku?