4

我不知道如何让我的独角兽工作人员只在他们真正“准备好”处理请求时才接受连接。我发现前几个请求很慢,然后它们会急剧加速(从几秒到一百毫秒左右)。这个问题似乎因为独角兽似乎在一定时间后杀死工人这一事实而更加复杂,这意味着我一直面临着缓慢的第一次请求的性能打击。有没有其他人看到这个或知道我能做什么?

4

1 回答 1

6

事实证明,我们的 i18n yml 文件在第一次请求时被延迟加载到视图中导致了性能问题。只需将以下内容添加到我的 config/unicorn.rb 似乎已经解决了这个问题:

before_fork do |server, worker|
  # The following is highly recomended for Rails + "preload_app true" as
  # there's no need for the master process to hold a connection.
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!

  # No need to disconnect from Redis servers--they are connected to lazily.

  # Force translations to be loaded into memory.
  I18n.t('activerecord')
end
于 2012-11-06T05:47:01.127 回答