2012-08-10 43 views
3

在与capistrano部署后首次加载我的网站时有很长的延迟。之后,新的请求非常快。然后,当我再次加载站点一个小时左右后,第一个请求将采用forerver。通常它甚至会返回500错误页面(我猜是因为超时)。然后当我刷新时,它瞬间加载。保持一名工作人员在Unicorn Nginx 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: [email protected]/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

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

上面的配置表明,有2个进程,这些都是工人和麒麟主流程,您可以通过在命令行中插入$:.ps ux检查出来

要得到什么错误的一个更清晰的概念你可以通过ssh连接到你的网络服务器,并使用$tail -f log/file.extention

+0

将production.log和unicorn.err放在一起当我输入'%:. ps ux'时,我得到'bash:fg:%:. ps:no这样的工作'。我已经用日志信息更新了我的问题。谢谢你的帮助! – Diatomic 2012-08-10 10:08:52

+0

$ :.部分显示它是一个控制台命令,只需运行ps ux EDIT:我不好,我看到我把一个%而不是$ – dennis 2012-08-10 10:15:36

+0

没有后顾之忧。我已经用输出更新了我的问题。 – Diatomic 2012-08-10 10:31:53