在Heroku上使用Unicorn时.向上扩展会产生问题,因为当它仍在加载应用程序时,请求可以访问新扩展的web dyno.这主要导致超时错误.
我在http://codelevy.com/2010/02/09/getting-started-with-unicorn.html和https://github.com/blog/517-unicorn做了一些阅读
这两篇文章建议使用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