【问题标题】:Running out of band garbage collection with Unicorn + Rack使用 Unicorn + Rack 进行带外垃圾收集
【发布时间】:2012-11-19 23:31:09
【问题描述】:

我正在尝试在我的 Ruby on Rails 应用程序中运行带外垃圾收集(一旦请求完成了其响应)。我在 config.ru 中添加了以下内容:

# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment',  __FILE__)
begin
  require 'unicorn/oob_gc'
rescue LoadError, NameError
end
# Out-of-band GC, runs GC after every 10th request and after the response
# has been delivered.
begin
  use Unicorn::OobGC, interval=10
rescue NameError
end

run MyApp::Application

GC.start

但是,我正在查看我的 NewRelic 门户,大多数网络事务确实表明平均至少 110-150 毫秒用于垃圾收集。 Unicorn::OoobGC 是否应该超出实际请求的范围?如果是,为什么这会出现在网络交易中?如何让垃圾收集所花费的时间发生在 Web 请求的上下文之外,以便感知的客户端响应时间更快?所花费的 CPU 时间仍然是相同的,因为它需要在后台进行,但是,在后台比保持请求管道更好。

【问题讨论】:

    标签: ruby-on-rails ruby performance garbage-collection unicorn


    【解决方案1】:

    如果单个请求分配了足够多的对象来触发 GC,尽管使用 unicorn 中间件移动了最终的 GC OOB,您仍然会看到为该请求报告的 gc 时间。

    使用 ruby​​ 1.9.3 和 REE,您可以旋转各种 GC 旋钮来帮助控制触发 gc 的频率。有关设置 RUBY_HEAP_MIN_SLOTS、RUBY_GC_MALLOC_LIMIT 和 RUBY_FREE_MIN 的示例,请参阅 Tuning the GC in Ruby 1.9.3,以便在长时间运行的服务应用程序中获得更好的行为。

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 1970-01-01
      • 1970-01-01
      • 2012-06-15
      • 2011-03-10
      • 2019-09-04
      • 2018-06-10
      • 2011-07-16
      相关资源
      最近更新 更多