我的Heroku托管应用程序存在一些内存问题。我正在使用一名工人,只使用1x默认dyno。该应用程序使用Ruby 2.0和Rails 4.1.4与unicorn作为Web服务器。
这是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
谢谢!
答案 0 :(得分:0)
优化Ruby垃圾收集可以帮助在heroku实例上保持较低的使用内存。如果Ruby更频繁地触发GC,这会导致一些CPU周期中断,但会降低内存使用率。
Unable to find a suitable version for webcomponentsjs, please choose one:
1) webcomponentsjs#^0.6.0 which resolved to 0.6.3 and is required by polymer#0.5.6
2) webcomponentsjs#^0.7.2 which resolved to 0.7.12 and is required by polymer#1.1.2
3) webcomponentsjs#* which resolved to 0.7.12 and is required by core-component-page#0.5.6
的特别高(默认)值可能会导致RUBY_GC_HEAP_GROWTH_FACTOR
。
它的默认值是Error R14 (Memory quota exceeded)
,这意味着如果需要扩展堆大小,它将增长80%。您可以尝试将此值降低到1.8
和1.1
之间的任何值。