From 31ee6b4daa1da9cd02e75b27924b2729345e999d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 29 Dec 2009 12:59:01 -0800 Subject: quiet spurious wakeups for accept() in Thread* models Under all MRI 1.8, a blocking Socket#accept Ruby method (needs to[1]) translate to a non-blocking accept(2) system call that may wake up threads/processes unnecessarily. Unfortunately, we failed to trap and ignore EAGAIN in those cases. This issue did not affect Ruby 1.9 running under modern Linux kernels where a _blocking_ accept(2) system call is not (easily, at least) susceptible to spurious wakeups. Non-Linux systems running Ruby 1.9 may be affected. [1] - using a blocking accept(2) on a shared socket with green threads is dangerous, as noted in commit ee7fe220ccbc991e1e7cbe982caf48e3303274c7 (and commit 451ca6997b4f298b436605b7f0af75f369320425) --- t/t0012-spurious-wakeups-quiet.sh | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 t/t0012-spurious-wakeups-quiet.sh (limited to 't') diff --git a/t/t0012-spurious-wakeups-quiet.sh b/t/t0012-spurious-wakeups-quiet.sh new file mode 100755 index 0000000..23557b7 --- /dev/null +++ b/t/t0012-spurious-wakeups-quiet.sh @@ -0,0 +1,41 @@ +#!/bin/sh +nr=${nr-4} +. ./test-lib.sh + +# ApacheBench (ab) is commonly installed in the sbin paths in Debian-based +# systems... +AB="$(which ab 2>/dev/null || :)" +if test -z "$AB" +then + AB=$(PATH=/usr/local/sbin:/usr/sbin:$PATH which ab 2>/dev/null || :) +fi + +if test -z "$AB" +then + t_info "skipping $T since 'ab' could not be found" + exit 0 +fi + +t_plan 4 "quiet spurious wakeups for $model" + +t_begin "setup and start" && { + rainbows_setup $model + echo "preload_app true" >> $unicorn_config + echo "worker_processes $nr" >> $unicorn_config + rainbows -D env.ru -c $unicorn_config -E none + rainbows_wait_start +} + +t_begin "spam the server with requests" && { + $AB -c1 -n100 http://$listen/ +} + +t_begin "killing succeeds" && { + kill -QUIT $rainbows_pid +} + +t_begin "check stderr" && { + check_stderr +} + +t_done -- cgit v1.2.3-24-ge0c7