about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-06-29 16:22:17 -0700
committerEric Wong <normalperson@yhbt.net>2012-08-02 20:52:34 +0000
commit53c375dc933b62b24df2c54d3938b03fa9da1f06 (patch)
tree820bfd0ba5370eda870dec975dfeab941e74667b /t
parent91a3cde091d4ae6ff436681f155b3907daae1c04 (diff)
downloadunicorn-53c375dc933b62b24df2c54d3938b03fa9da1f06.tar.gz
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
Diffstat (limited to 't')
-rw-r--r--t/listener_names.ru4
-rw-r--r--t/t0022-listener_names-preload_app.sh32
2 files changed, 36 insertions, 0 deletions
diff --git a/t/listener_names.ru b/t/listener_names.ru
new file mode 100644
index 0000000..edb4e6a
--- /dev/null
+++ b/t/listener_names.ru
@@ -0,0 +1,4 @@
+use Rack::ContentLength
+use Rack::ContentType, "text/plain"
+names = Unicorn.listener_names.inspect # rely on preload_app=true
+run(lambda { |_| [ 200, {}, [ names ] ] })
diff --git a/t/t0022-listener_names-preload_app.sh b/t/t0022-listener_names-preload_app.sh
new file mode 100644
index 0000000..d07a26c
--- /dev/null
+++ b/t/t0022-listener_names-preload_app.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+. ./test-lib.sh
+
+# Raindrops::Middleware depends on Unicorn.listener_names,
+# ensure we don't break Raindrops::Middleware when preload_app is true
+
+t_plan 4 "Unicorn.listener_names available with preload_app=true"
+
+t_begin "setup and startup" && {
+        unicorn_setup
+        echo preload_app true >> $unicorn_config
+        unicorn -E none -D listener_names.ru -c $unicorn_config
+        unicorn_wait_start
+}
+
+t_begin "read listener names includes listener" && {
+        resp=$(curl -sSf http://$listen/)
+        ok=false
+        t_info "resp=$resp"
+        case $resp in
+        *\"$listen\"*) ok=true ;;
+        esac
+        $ok
+}
+
+t_begin "killing succeeds" && {
+        kill $unicorn_pid
+}
+
+t_begin "check stderr" && check_stderr
+
+t_done