From 53c375dc933b62b24df2c54d3938b03fa9da1f06 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 29 Jun 2012 16:22:17 -0700 Subject: bind listeners after loading for preload_app users In the case where preload_app is true, delay binding new listeners until after loading the application. Some applications have very long load times (especially Rails apps with Ruby 1.9.2). Binding listeners early may cause a load balancer to incorrectly believe the unicorn workers are ready to serve traffic even while the app is being loaded. Once a listener is bound, connect() requests from the load balancer succeed until the listen backlog is filled. This allows requests to pile up for a bit (depending on backlog size) before getting rejected by the kernel. By the time the application is loaded and ready-to-run, requests in the listen backlog are likely stale and not useful to process. Processes inheriting listeners do not suffer this effect, as the old process should still be capable of serving new requests. This change does not improve the situation for the preload_app=false (default) use case. There may not be a solution for preload_app=false users using large applications. Fortunately Ruby 1.9.3+ improves load times of large applications significantly over 1.9.2 so this should be less of a problem in the future. Reported via private email sent on 2012-06-29T22:59:10Z --- lib/unicorn.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/unicorn.rb') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index b882ce3..d96ff91 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -82,7 +82,7 @@ module Unicorn def self.listener_names Unicorn::HttpServer::LISTENERS.map do |io| Unicorn::SocketHelper.sock_name(io) - end + end + Unicorn::HttpServer::NEW_LISTENERS end def self.log_error(logger, prefix, exc) -- cgit v1.2.3-24-ge0c7