HerokuでUnicornを使用する場合。スケールアップすると、問題が発生します。なぜなら、新しくスケーリングされたWeb dynoには、まだアプリケーションをロードしているときに要求によってアクセスできるからです。ほとんどがタイムアウトエラーになります。私はHeroku + Unicornでアプリを正しくプリロードしていますか?
私はhttp://codelevy.com/2010/02/09/getting-started-with-unicorn.htmlとhttps://github.com/blog/517-unicorn
2件の記事で読書のビットがpreload_app true
を使うことを提案しました。そしてafter_fork
とbefore_fork
ブロック。
Rails 3+では、まだbefore_block
のコードは必要ですか?私はどこかで読んだ。以前にこれを設定した経験があり、共有したい人は誰ですか?
私には他に何かがありますか?アプリをあらかじめ正しく読み込んでいますか?
# config/initializers/unicorn.rb
# Read from:
# http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/
worker_processes 3 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 90 seconds
# Noted from http://codelevy.com/2010/02/09/getting-started-with-unicorn.html
# and https://github.com/blog/517-unicorn
preload_app true
after_fork do |server, worker|
ActiveRecord::Base.establish_connection
end
before_fork do |server, worker|
##
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
# immediately start loading up a new version of itself (loaded with a new
# version of our app). When this new Unicorn is completely loaded
# it will begin spawning workers. The first worker spawned will check to
# see if an .oldbin pidfile exists. If so, this means we've just booted up
# a new Unicorn and need to tell the old one that it can now die. To do so
# we send it a QUIT.
#
# Using this method we get 0 downtime deploys.
old_pid = Rails.root + '/tmp/pids/unicorn.pid.oldbin'
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end
こんにちはNeil。解決策は、dyno(ユニコーンマスター)がアプリを完全に読み込むまでリクエストが入るのを防ぐために、アプリをプリロードすることです。私の心配は、 'before_fork'ブロックにコードが必要かどうかです。 –
あなたのbefore_forkは何も達成できません。前にも述べたように、問題は、あなたのユニコーンが始まる前にHerokuルーティングメッシュがリクエストを送信するという事実にあります。アプリケーションをあらかじめロードしても、これは解決されません。 –
これが当てはまる場合。ヘロクで新しいウェブダイノスを回転/拡大するときにタイムアウトエラーが発生するのを防ぐには? –