让一名工作人员在Unicorn Nginx Rails中持续运行

时间:2012-08-10 06:57:30

标签: ruby-on-rails nginx unicorn

我在使用capistrano部署后首次加载网站时出现了很长时间的延迟。之后,新请求真的很快。然后在我再次加载网站一小时左右后,第一个请求需要先行。通常它甚至会返回500错误页面(我猜是因为超时)。然后,当我点击刷新时,它立即加载。

我猜测在服务器收到新请求一段时间后,它会重新加载整个rails环境。有什么方法可以保持环境的一个副本不断运行吗?

这是我的独角兽配置:

root = "/home/user/apps/app_name/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"

listen "/tmp/unicorn.app_name.sock"
worker_processes 2
timeout 60

Production.log

Started GET "/" for 1.2.3.4 at 2012-08-10 09:59:13 +0000
Connecting to database specified by database.yml


Started GET "/" for 1.2.3.4 at 2012-08-10 10:03:14 +0000
Connecting to database specified by database.yml


Started GET "/" for 1.2.3.4 at 2012-08-10 10:04:38 +0000
Processing by PagesController#home as HTML
  Rendered layouts/_top_bar_public.html.erb (1.1ms)
  Rendered shared/_flash.html.erb (0.3ms)
  Rendered pages/home.html.erb within layouts/application (8.4ms)
Completed 200 OK in 48ms (Views: 47.5ms | ActiveRecord: 0.0ms)

Unicorn.log

E, [2012-08-10T10:00:14.449348 #6005] ERROR -- : worker=1 PID:4951 timeout (61s > 60s), killing
E, [2012-08-10T10:00:14.458442 #6005] ERROR -- : reaped #<Process::Status: pid 4951 SIGKILL (signal 9)> worker=1
I, [2012-08-10T10:00:14.458796 #6005]  INFO -- : worker=1 spawning...
I, [2012-08-10T10:00:14.465259 #6458]  INFO -- : worker=1 spawned pid=6458
I, [2012-08-10T10:00:14.465639 #6458]  INFO -- : Refreshing Gem list
I, [2012-08-10T10:00:18.115613 #6458]  INFO -- : worker=1 ready
E, [2012-08-10T10:04:15.706315 #6005] ERROR -- : worker=0 PID:4929 timeout (61s > 60s), killing
E, [2012-08-10T10:04:15.716064 #6005] ERROR -- : reaped #<Process::Status: pid 4929 SIGKILL (signal 9)> worker=0
I, [2012-08-10T10:04:15.716566 #6005]  INFO -- : worker=0 spawning...
I, [2012-08-10T10:04:15.723733 #6461]  INFO -- : worker=0 spawned pid=6461
I, [2012-08-10T10:04:15.724111 #6461]  INFO -- : Refreshing Gem list
I, [2012-08-10T10:04:19.298475 #6461]  INFO -- : worker=0 ready

ps ux:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
deployer  6005  0.0  3.3 149880 20292 ?        Sl   Aug01   0:15 unicorn master -D -c /home/deployer/apps/app_name
deployer  6458  0.2  9.6 234544 58036 ?        Sl   10:00   0:03 unicorn worker[1] -D -c /home/deployer/apps/app_name
deployer  6461  0.2  9.3 232924 56564 ?        Sl   10:04   0:03 unicorn worker[0] -D -c /home/deployer/apps/app_name
deployer  6563  0.0  0.2  73352  1804 ?        S    10:29   0:00 sshd: deployer@pts/0
deployer  6564 13.3  1.3  25744  8196 pts/0    Ss   10:29   0:00 -bash
deployer  6743  0.0  0.2  16872  1264 pts/0    R+   10:29   0:00 ps ux

1 个答案:

答案 0 :(得分:1)

这是奇怪的行为,因为在部署时它应该清理并触摸tmp / restart以重新启动服务器。

上面的配置表明有两个进程,即工作者和独角兽的主进程,您可以通过在命令行中插入$:.ps ux来检查它们

为了更清楚地了解出现了什么问题,您可以与您的网络服务器建立ssh连接,并使用$tail -f log/file.extention

拖尾production.log和unicorn.err