gpt4 book ai didi

ruby-on-rails - R14 - 超出内存配额

转载 作者:数据小太阳 更新时间:2023-10-29 08:12:13 24 4
gpt4 key购买 nike

我的 Heroku 托管应用程序存在一些内存问题。我正在使用一个 worker 并且只使用 1x 默认 dyno。该应用程序使用 Ruby 2.0 和 Rails 4.1.4 以及 unicorn 作为网络服务器。

这是 unicorn 配置文件​​。

worker_processes Integer(ENV["WEB_CONCURRENCY"] || 2)
timeout 30
preload_app true

before_fork do |server, worker|

Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end

defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end

defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end

我显然无缘无故地收到 R14 内存问题。没有对应用程序的请求,但正如您从屏幕截图中看到的那样,使用的内存在短时间内翻了一番。

Aug 21 00:47:22 ABC heroku/web.1:  source=web.1 dyno=heroku.27639500.25827f7d-f927-465a-898d-dd87d4376efb sample#load_avg_1m=0.35 
Aug 21 00:47:22 ABC heroku/web.1: source=web.1 dyno=heroku.27639500.25827f7d-f927-465a-898d-dd87d4376efb sample#memory_total=222.71MB sample#memory_rss=222.70MB sample#memory_cache=0.01MB sample#memory_swap=0.00MB sample#memory_pgpgin=62101pages sample#memory_pgpgout=5088pages
Aug 21 00:47:43 ABC heroku/web.1: source=web.1 dyno=heroku.27639500.25827f7d-f927-465a-898d-dd87d4376efb sample#load_avg_1m=0.25
Aug 21 00:47:43 ABC heroku/web.1: source=web.1 dyno=heroku.27639500.25827f7d-f927-465a-898d-dd87d4376efb sample#memory_total=588.86MB sample#memory_rss=511.95MB sample#memory_cache=0.01MB sample#memory_swap=76.91MB sample#memory_pgpgin=156028pages sample#memory_pgpgout=24968pages
Aug 21 00:47:43 ABC heroku/web.1: Process running mem=588M(115.0%)
Aug 21 00:47:43 ABC heroku/web.1: Error R14 (Memory quota exceeded)
Aug 21 00:48:04 ABC heroku/web.1: source=web.1 dyno=heroku.27639500.25827f7d-f927-465a-898d-dd87d4376efb sample#load_avg_1m=0.17
Aug 21 00:48:04 ABC heroku/web.1: source=web.1 dyno=heroku.27639500.25827f7d-f927-465a-898d-dd87d4376efb sample#memory_total=177.77MB sample#memory_rss=83.40MB sample#memory_cache=0.00MB sample#memory_swap=94.36MB sample#memory_pgpgin=181821pages sample#memory_pgpgout=160469pages

谢谢!

最佳答案

优化 Ruby 垃圾收集可以极大地帮助保持 heroku 实例上的低内存使用率。如果 Ruby 更频繁地触发 GC,这会稍微消耗一些 CPU 周期,但会降低内存使用率。

RUBY_GC_HEAP_GROWTH_FACTOR 的特别高(默认)值会导致错误 R14(超出内存配额)

它的默认值为1.8,这意味着如果需要扩展堆大小,它将增长80%。您可以尝试将此值降低到 1.11.5 之间的任何值。

关于ruby-on-rails - R14 - 超出内存配额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25425050/

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