3

在使用 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

生产日志

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)

独角兽.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 用户体验:

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
4

1 回答 1

1

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

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

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

于 2012-08-10T07:25:57.273 回答