我正在尝试在AWS服务器上设置Unicorn,但工作进程一直超时,我不知道原因。
我正在使用Ubuntu Server 14.04 LTS AMI,在安装标准的Ruby on Rails安装所需的所有内容。使用rails new,我生成了一个空应用程序,第一次尝试访问似乎很快,但之后工作进程就一直超时,需要很长时间才能提供网页服务。加载标准的WEBrick服务器没有这个问题,并且几乎立即加载页面。我已经尝试回滚ruby和unicorn的多个版本,但没有成功。此行为在本地虚拟机中不会发生。
以下是调试模式下服务器的日志:
我正在使用Ubuntu Server 14.04 LTS AMI,在安装标准的Ruby on Rails安装所需的所有内容。使用rails new,我生成了一个空应用程序,第一次尝试访问似乎很快,但之后工作进程就一直超时,需要很长时间才能提供网页服务。加载标准的WEBrick服务器没有这个问题,并且几乎立即加载页面。我已经尝试回滚ruby和unicorn的多个版本,但没有成功。此行为在本地虚拟机中不会发生。
以下是调试模式下服务器的日志:
I, [2014-11-04T18:30:13.290599 #17134] INFO -- : listening on addr=0.0.0.0:5000 fd=10 I, [2014-11-04T18:30:13.362993 #17134] INFO -- : master process ready I, [2014-11-04T18:30:13.363098 #17137] INFO -- : worker=0 ready I, [2014-11-04T18:30:13.365175 #17140] INFO -- : worker=1 ready I, [2014-11-04T18:30:13.365314 #17142] INFO -- : worker=2 ready Exception 'LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:443 - cannot load such file -- rails/application_helper.rb Exception 'LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:352 - cannot load such file -- rails/application_helper.rb Exception 'LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:313 - No such file to load -- rails/application_helper Exception 'AbstractController::Helpers::MissingHelperError' at /var/lib/gems/2.1.0/gems/actionpack-4.1.7/lib/abstract_controller/helpers.rb:154 - Missing helper file helpers/rails/application_helper.rb Exception 'LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:443 - cannot load such file -- rails/welcome_helper.rb Exception 'LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:352 - cannot load such file -- rails/welcome_helper.rb Exception 'LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:313 - No such file to load -- rails/welcome_helper Exception 'AbstractController::Helpers::MissingHelperError' at /var/lib/gems/2.1.0/gems/actionpack-4.1.7/lib/abstract_controller/helpers.rb:154 - Missing helper file helpers/rails/welcome_helper.rb **** - - [04/Nov/2014 18:30:13] "GET / HTTP/1.1" 200 - 0.0693 **** - - [04/Nov/2014 18:30:14] "GET %2Ffavicon.ico HTTP/1.1" 304 - 0.0441 E, [2014-11-04T18:30:45.395879 #17134] ERROR -- : worker=0 PID:17137 timeout (31s > 30s), killing E, [2014-11-04T18:30:45.395995 #17134] ERROR -- : worker=1 PID:17140 timeout (31s > 30s), killing E, [2014-11-04T18:30:45.396072 #17134] ERROR -- : worker=2 PID:17142 timeout (31s > 30s), killing E, [2014-11-04T18:30:45.397748 #17134] ERROR -- : reaped # worker=2 E, [2014-11-04T18:30:45.397882 #17134] ERROR -- : worker=0 PID:17137 timeout (31s > 30s), killing E, [2014-11-04T18:30:45.397990 #17134] ERROR -- : worker=1 PID:17140 timeout (31s > 30s), killing E, [2014-11-04T18:30:45.401016 #17134] ERROR -- : reaped # worker=1 E, [2014-11-04T18:30:45.401177 #17134] ERROR -- : worker=0 PID:17137 timeout (31s > 30s), killing I, [2014-11-04T18:30:45.402352 #17148] INFO -- : worker=2 ready E, [2014-11-04T18:30:45.403784 #17134] ERROR -- : reaped # worker=0 I, [2014-11-04T18:30:45.405625 #17152] INFO -- : worker=1 ready I, [2014-11-04T18:30:45.406871 #17155] INFO -- : worker=0 ready Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception `LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:443 - cannot load such file -- rails/application_helper.rb Exception `LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:352 - cannot load such file -- rails/application_helper.rb Exception `LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:313 - No such file to load -- rails/application_helper Exception `AbstractController::Helpers::MissingHelperError' at /var/lib/gems/2.1.0/gems/actionpack-4.1.7/lib/abstract_controller/helpers.rb:154 - Missing helper file helpers/rails/application_helper.rb Exception `LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:443 - cannot load such file -- rails/welcome_helper.rb Exception `LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:352 - cannot load such file -- rails/welcome_helper.rb Exception `LoadError' at /var/lib/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:313 - No such file to load -- rails/welcome_helper Exception `AbstractController::Helpers::MissingHelperError' at /var/lib/gems/2.1.0/gems/actionpack-4.1.7/lib/abstract_controller/helpers.rb:154 - Missing helper file helpers/rails/welcome_helper.rb **** - - [04/Nov/2014 18:31:14] "GET / HTTP/1.1" 200 - 0.0680 Exception 'EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached Exception 'EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - end of file reached E, [2014-11-04T18:31:45.465765 #17134] ERROR -- : worker=2 PID:17148 timeout (31s > 30s), killing E, [2014-11-04T18:31:45.468770 #17134] ERROR -- : reaped # worker=2 I, [2014-11-04T18:31:45.472177 #17162] INFO -- : worker=2 ready E, [2014-11-04T18:31:49.474506 #17134] ERROR -- : worker=1 PID:17152 timeout (31s > 30s), killing E, [2014-11-04T18:31:49.474633 #17134] ERROR -- : worker=0 PID:17155 timeout (31s > 30s), killing E, [2014-11-04T18:31:49.476313 #17134] ERROR -- : reaped # worker=1 E, [2014-11-04T18:31:49.476451 #17134] ERROR -- : worker=0 PID:17155 timeout (31s > 30s), killing I, [2014-11-04T18:31:49.481324 #17166] INFO -- : worker=1 ready E, [2014-11-04T18:31:49.481548 #17134] ERROR -- : reaped # worker=0 I, [2014-11-04T18:31:49.484368 #17169] INFO -- : worker=0 ready E, [2014-11-04T18:32:17.511012 #17134] ERROR -- : worker=2 PID:17162 timeout (31s > 30s), killing E, [2014-11-04T18:32:17.512733 #17134] ERROR -- : reaped # worker=2 I, [2014-11-04T18:32:17.516074 #17174] INFO -- : worker=2 ready E, [2014-11-04T18:32:21.518316 #17134] ERROR -- : worker=0 PID:17169 timeout (31s > 30s), killing E, [2014-11-04T18:32:21.520011 #17134] ERROR -- : reaped # worker=0 I, [2014-11-04T18:32:21.523230 #17177] INFO -- : worker=0 ready
以下是独角兽配置文件
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) timeout 30 preload_app true before_fork do |server, worker| Signal.trap 'TERM' do puts '独角兽主进程捕捉到 TERM 信号,发送 QUIT 信号关闭自己' 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 '独角兽工作进程捕捉到 TERM 信号,不做任何事情,等待主进程发送 QUIT 信号' end
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
我注意到了 EOF 错误,并怀疑这可能与超时有关,但我无法确定。
Exception `EOFError' at /var/lib/gems/2.1.0/gems/unicorn-4.8.1/lib/unicorn/http_request.rb:79 - 到达文件结尾