10

我遇到了ActiveRecord::StatementInvalid (PG::Error: SSL error: decryption failed or bad record mac错误,所以我遵循了关于将 Unicorn 部署到 Heroku 的指南,它似乎已经修复了它。然而,在警告下,它显示了如何Resque为这样的设置进行配置 - 我是否必须做类似的事情Sidekiq

Heroku 的示例代码:

before_fork do |server, worker|

  ...

  # If you are using Redis but not Resque, change this
  if defined?(Resque)
    Resque.redis.quit
    Rails.logger.info('Disconnected from Redis')
  end
end

after_fork do |server, worker|

  ...

  # If you are using Redis but not Resque, change this
  if defined?(Resque)
    Resque.redis = ENV['REDIS_URI']
    Rails.logger.info('Connected to Redis')
  end
end

这是我目前设置的:

配置/独角兽.rb

worker_processes 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

配置/初始化程序/sidekiq.rb

require 'sidekiq'

Sidekiq.configure_client do |config|
  config.redis = { :size => 1 }
end

Sidekiq.configure_server do |config|
  config.redis = { :size => 6 }
end

档案

web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb
worker: bundle exec sidekiq -e production -c 4
4

2 回答 2

17

从 sidekiq 的 2.9.0 版本开始,在 unicorn/passenger 中不需要配置after_fork

以下是版本 2.9.0 的发行说明,其中提到了该问题。

这是解决分叉连接的已解决问题。

最后,这里是维护者的评论,确认after_fork不再需要配置。

于 2014-05-04T23:04:28.167 回答
6

这就是我所拥有的并且它有效:

配置/独角兽.rb

worker_processes Integer(ENV["WEB_CONCURRENCY"] || 5)
timeout 15
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

  Sidekiq.configure_client do |config|
    config.redis = { size: 1, namespace: 'sidekiq' }
  end
end

配置/初始化程序/sidekiq.rb

ENV["REDIS_URL"] ||= "redis://localhost:6379"

Sidekiq.configure_server do |config|
  config.redis = { url: ENV["REDIS_URL"], namespace: 'sidekiq' }
end

unless Rails.env.production?
  Sidekiq.configure_client do |config|
    config.redis = { url: ENV["REDIS_URL"], namespace: 'sidekiq'  }
  end
end

注意:我thin在开发和unicornheroku 上使用。

于 2013-05-15T07:11:58.717 回答