bind listeners after loading for preload_app users
commit53c375dc933b62b24df2c54d3938b03fa9da1f06
authorEric Wong <normalperson@yhbt.net>
Fri, 29 Jun 2012 23:22:17 +0000 (29 16:22 -0700)
committerEric Wong <normalperson@yhbt.net>
Thu, 2 Aug 2012 20:52:34 +0000 (2 20:52 +0000)
tree820bfd0ba5370eda870dec975dfeab941e74667b
parent91a3cde091d4ae6ff436681f155b3907daae1c04
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
lib/unicorn/http_server.rb
t/listener_names.ru [new file with mode: 0644]
t/t0022-listener_names-preload_app.sh [new file with mode: 0644]