gpt4 book ai didi

ruby-on-rails - 如何在 Heroku 上使用 send_file(或 send_data)解决内存泄漏?

转载 作者:行者123 更新时间:2023-12-04 18:13:58 24 4
gpt4 key购买 nike

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

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

然而,Heroku 只支持通过 Mongrel 进行流式传输,它保留了内存。然后这会导致 Heroku 变慢,然后在十几个请求后终止线程。

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

我目前正在使用来自 ActionController::DataStreaming 的 send_data 或 send_file

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

Heroku 不支持 Rack::Sendfile 或 x-sendfile。

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

“ruby-mongrel-x-sendfile”项目说:“通过 mongrel 流式传输大量数据是一件坏事;会引发严重的内存泄漏”并提供“in-mongrel 解决方案”。但这看起来不是一个好的解决方案。

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

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

请问有人有什么想法吗?

最佳答案

答案是开始垃圾收集:

GC.start

我在发送数据之后将该行放在 Rails Controller 操作的底部。

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

关于ruby-on-rails - 如何在 Heroku 上使用 send_file(或 send_data)解决内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12068680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com