我一直在分析我的 Web 应用程序,延迟非常糟糕。我观察到初始页面加载可能需要 200 毫秒到 1 秒以上才能解决!随后的请求可能会更快,但仍然相当慢〜 300 毫秒。
我的堆栈由 Rails 4、Ruby 2.0、Unicorn、Apache2、Postgres、Redis 和 Sidekiq(使用 redis)组成。
我已阅读以下可能相关的信息。如何重新启动共享的 redis 套接字?这可能是造成延迟的原因吗?
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis. TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
阿帕奇默认:
https://gist.github.com/fogonthedowns/6588751
我的 Unicorn.rb 文件如下所示:
worker_processes 2
preload_app true
timeout 30
listen 5000
after_fork do |server, worker|
ActiveRecord::Base.establish_connection
end
生产.rb:
MyApp::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.assets.precompile += %w( tag.js )
config.action_mailer.default_url_options = { host: "foo.com" }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "foo.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "no-reply@foo.com",
password: "foooo"
}
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
是什么导致了如此糟糕的延迟?
生产日志
Rendered home/index.html.haml within layouts/application (26.8ms)
Completed 200 OK in 31ms (Views: 29.3ms | ActiveRecord: 1.4ms)
Started GET "/assets/google_button.jpg" for 24.53.176.189 at 2013-09-18 04:19:36 +0000
Started GET "/tags/" for 24.53.176.189 at 2013-09-18 04:19:38 +0000
Processing by TagsController#index as HTML
Rendered tags/index.html.haml within layouts/application (12.1ms)
Completed 200 OK in 20ms (Views: 16.9ms | ActiveRecord: 1.8ms)
Started GET "/assets/google_button.jpg" for 24.53.176.189 at 2013-09-18 04:19:38 +0000
Started GET "/jason-wade-for-mayor" for 24.53.176.189 at 2013-09-18 04:19:39 +0000
Processing by CommitteesController#show as HTML
Parameters: {"id"=>"jason-wade-for-mayor"}
Rendered committees/show.html.haml within layouts/application (35.2ms)
Completed 200 OK in 49ms (Views: 41.8ms | ActiveRecord: 1.8ms)
Started GET "/assets/committee-b8c8544f44424bd9e0234cd1a1fcd796.js" for 24.53.176.189 at 2013-09-18 04:19:40 +0000
Started GET "/assets/google_button.jpg" for 24.53.176.189 at 2013-09-18 04:19:40 +0000
Started GET "/jason-wade-for-mayor" for 24.53.176.189 at 2013-09-18 04:19:54 +0000
Processing by CommitteesController#show as HTML
Parameters: {"id"=>"jason-wade-for-mayor"}
Redirected to http://redmeetsblue.us/
Filter chain halted as :beta_test rendered or redirected
Completed 302 Found in 25ms (ActiveRecord: 0.0ms)
Started GET "/" for 24.53.176.189 at 2013-09-18 04:19:55 +0000
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (4.6ms)
Completed 200 OK in 8ms (Views: 7.4ms | ActiveRecord: 0.0ms)
Started GET "/assets/google_button.jpg" for 24.53.176.189 at 2013-09-18 04:19:57 +0000
Started GET "/assets/favicon.ico" for 24.53.176.189 at 2013-09-18 04:19:58 +0000
Started GET "/jason-wade-for-mayor" for 24.53.176.189 at 2013-09-18 04:20:10 +0000
Processing by CommitteesController#show as HTML
Parameters: {"id"=>"jason-wade-for-mayor"}
Redirected to http://redmeetsblue.us/
Filter chain halted as :beta_test rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.0ms)
Started GET "/" for 24.53.176.189 at 2013-09-18 04:20:10 +0000
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (5.3ms)
Completed 200 OK in 9ms (Views: 8.5ms | ActiveRecord: 0.0ms)
Started GET "/jason-wade-for-mayor/contributions/new" for 24.53.176.189 at 2013-09-18 04:22:15 +0000
Processing by ContributionsController#new as HTML
Parameters: {"committee_id"=>"jason-wade-for-mayor"}
Rendered contributions/new.html.haml within layouts/application (6.4ms)
Completed 200 OK in 16ms (Views: 10.5ms | ActiveRecord: 1.8ms)
Started GET "/assets/google_button.jpg" for 24.53.176.189 at 2013-09-18 04:22:15 +0000
Started GET "/tags/" for 24.53.176.189 at 2013-09-18 04:22:18 +0000
Processing by TagsController#index as HTML
Rendered tags/index.html.haml within layouts/application (28.2ms)
Completed 200 OK in 153ms (Views: 36.6ms | ActiveRecord: 4.2ms)
Started GET "/assets/google_button.jpg" for 24.53.176.189 at 2013-09-18 04:22:18 +0000
Started GET "/" for 24.53.176.189 at 2013-09-18 04:22:22 +0000
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (11.1ms)
Completed 200 OK in 16ms (Views: 13.8ms | ActiveRecord: 1.6ms)
Started GET "/assets/google_button.jpg" for 24.53.176.189 at 2013-09-18 04:22:22 +0000
Started GET "/" for 24.7.86.40 at 2013-09-18 04:23:04 +0000
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (8.5ms)
Completed 200 OK in 15ms (Views: 13.9ms | ActiveRecord: 0.0ms)
Started GET "/assets/google_button.jpg" for 24.7.86.40 at 2013-09-18 04:23:04 +0000
Started GET "/assets/favicon.ico" for 24.7.86.40 at 2013-09-18 04:23:05 +0000