Last active
October 12, 2015 11:40
-
-
Save shogo82148/5150dccc7cbe1b33b5fa to your computer and use it in GitHub Desktop.
testing Starlet/Gazelle graceful shutdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start_server --port 5000 --pid app.pid -- plackup -s Starlet --max-workers 20 app.psgi > /dev/null 2>&1 | |
# while true; do kill -HUP `cat app.pid`; sleep 1; done | |
my $app = sub { | |
my $env = shift; | |
return [ | |
200, | |
[ 'Content-Type' => 'text/plain' ], | |
[ "Hello World" ], | |
]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ab -c 20 -n 100000 -r http://localhost:5000/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests | |
Completed 90000 requests | |
Completed 100000 requests | |
Finished 100000 requests | |
Server Software: gazelle | |
Server Hostname: localhost | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 11 bytes | |
Concurrency Level: 20 | |
Time taken for tests: 10.294 seconds | |
Complete requests: 100000 | |
Failed requests: 0 | |
Write errors: 0 | |
Total transferred: 12900774 bytes | |
HTML transferred: 1100066 bytes | |
Requests per second: 9714.85 [#/sec] (mean) | |
Time per request: 2.059 [ms] (mean) | |
Time per request: 0.103 [ms] (mean, across all concurrent requests) | |
Transfer rate: 1223.92 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 1 0.4 0 10 | |
Processing: 0 1 0.7 2 36 | |
Waiting: 0 1 0.7 1 36 | |
Total: 0 2 0.7 2 36 | |
ERROR: The median and mean for the initial connection time are more than twice the standard | |
deviation apart. These results are NOT reliable. | |
WARNING: The median and mean for the processing time are not within a normal deviation | |
These results are probably not that reliable. | |
Percentage of the requests served within a certain time (ms) | |
50% 2 | |
66% 2 | |
75% 2 | |
80% 2 | |
90% 3 | |
95% 3 | |
98% 3 | |
99% 4 | |
100% 36 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ab -c 20 -n 100000 -r http://localhost:5000/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests | |
Completed 90000 requests | |
Completed 100000 requests | |
Finished 100000 requests | |
Server Software: Plack::Handler::Starlet | |
Server Hostname: localhost | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 11 bytes | |
Concurrency Level: 20 | |
Time taken for tests: 20.319 seconds | |
Complete requests: 100000 | |
Failed requests: 0 | |
Write errors: 0 | |
Total transferred: 14500725 bytes | |
HTML transferred: 1100055 bytes | |
Requests per second: 4921.53 [#/sec] (mean) | |
Time per request: 4.064 [ms] (mean) | |
Time per request: 0.203 [ms] (mean, across all concurrent requests) | |
Transfer rate: 696.93 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 1 1.0 1 13 | |
Processing: 0 3 2.5 3 104 | |
Waiting: 0 3 2.5 3 104 | |
Total: 1 4 2.5 4 105 | |
Percentage of the requests served within a certain time (ms) | |
50% 4 | |
66% 4 | |
75% 4 | |
80% 5 | |
90% 6 | |
95% 6 | |
98% 8 | |
99% 9 | |
100% 105 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ab -c 20 -n 100000 -r http://localhost:5000/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests | |
Completed 90000 requests | |
Completed 100000 requests | |
Finished 100000 requests | |
Server Software: gazelle | |
Server Hostname: localhost | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 11 bytes | |
Concurrency Level: 20 | |
Time taken for tests: 11.251 seconds | |
Complete requests: 100000 | |
Failed requests: 0 | |
Write errors: 0 | |
Total transferred: 12901548 bytes | |
HTML transferred: 1100132 bytes | |
Requests per second: 8888.15 [#/sec] (mean) | |
Time per request: 2.250 [ms] (mean) | |
Time per request: 0.113 [ms] (mean, across all concurrent requests) | |
Transfer rate: 1119.83 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 1 0.7 1 20 | |
Processing: 0 1 0.7 2 27 | |
Waiting: 0 1 0.7 1 27 | |
Total: 0 2 1.0 2 28 | |
WARNING: The median and mean for the processing time are not within a normal deviation | |
These results are probably not that reliable. | |
Percentage of the requests served within a certain time (ms) | |
50% 2 | |
66% 2 | |
75% 2 | |
80% 3 | |
90% 3 | |
95% 3 | |
98% 4 | |
99% 5 | |
100% 28 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ab -c 20 -n 100000 -r http://localhost:5000/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests | |
Completed 90000 requests | |
Completed 100000 requests | |
Finished 100000 requests | |
Server Software: Plack::Handler::Starlet | |
Server Hostname: localhost | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 11 bytes | |
Concurrency Level: 20 | |
Time taken for tests: 22.405 seconds | |
Complete requests: 100000 | |
Failed requests: 0 | |
Write errors: 0 | |
Total transferred: 14500725 bytes | |
HTML transferred: 1100055 bytes | |
Requests per second: 4463.36 [#/sec] (mean) | |
Time per request: 4.481 [ms] (mean) | |
Time per request: 0.224 [ms] (mean, across all concurrent requests) | |
Transfer rate: 632.05 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 1 1.4 1 29 | |
Processing: 0 3 1.9 3 147 | |
Waiting: 0 3 1.9 3 147 | |
Total: 1 4 2.2 4 149 | |
Percentage of the requests served within a certain time (ms) | |
50% 4 | |
66% 5 | |
75% 5 | |
80% 6 | |
90% 6 | |
95% 8 | |
98% 9 | |
99% 11 | |
100% 149 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Starlet/Server.pm b/lib/Starlet/Server.pm | |
index 520cd37..2c6afae 100644 | |
--- a/lib/Starlet/Server.pm | |
+++ b/lib/Starlet/Server.pm | |
@@ -125,14 +125,10 @@ sub accept_loop { | |
my($self, $app, $max_reqs_per_child) = @_; | |
my $proc_req_count = 0; | |
- $self->{can_exit} = 1; | |
my $is_keepalive = 0; | |
local $SIG{TERM} = sub { | |
- exit 0 if $self->{can_exit}; | |
$self->{term_received}++; | |
- exit 0 | |
- if ($is_keepalive && $self->{can_exit}) || $self->{term_received} > 1; | |
- # warn "server termination delayed while handling current HTTP request"; | |
+ exit 0 if $self->{term_received} > 1; | |
}; | |
local $SIG{PIPE} = 'IGNORE'; | |
@@ -207,6 +203,9 @@ sub _get_acceptor { | |
if (my ($conn, $peer) = $listen->{sock}->accept) { | |
return ($conn, $peer, $listen); | |
} | |
+ elsif ($! == EINTR) { | |
+ exit 0 if $self->{term_received}; | |
+ } | |
} | |
}; | |
} | |
@@ -228,10 +227,21 @@ sub _get_acceptor { | |
return sub { | |
while (1) { | |
while (! flock($lock_fh, LOCK_EX)) { | |
- next if $! == EINTR; | |
+ if ($! == EINTR) { | |
+ exit 0 if $self->{term_received}; | |
+ next; | |
+ } | |
die "failed to lock file:@{[$self->{lock_path}]}:$!"; | |
} | |
my $nfound = select(my $rout = $rin, undef, undef, undef); | |
+ if ($nfound == -1) { # trap err | |
+ if ($! == EINTR) { | |
+ flock($lock_fh, LOCK_UN); | |
+ exit 0 if $self->{term_received}; | |
+ next; | |
+ } | |
+ die "failed to select file:@{[$self->{lock_path}]}:$!"; | |
+ } | |
for (my $i = 0; $nfound > 0; ++$i) { | |
my $fd = $fds[$i]; | |
next unless vec($rout, $fd, 1); | |
@@ -241,6 +251,9 @@ sub _get_acceptor { | |
flock($lock_fh, LOCK_UN); | |
return ($conn, $peer, $listen); | |
} | |
+ elsif ($! == EINTR) { | |
+ exit 0 if $self->{term_received}; | |
+ } | |
} | |
flock($lock_fh, LOCK_UN); | |
} | |
@@ -256,7 +269,6 @@ sub handle_connection { | |
my $pipelined_buf=''; | |
my $res = $bad_response; | |
- local $self->{can_exit} = (defined $prebuf) ? 0 : 1; | |
while (1) { | |
my $rlen; | |
if ( $rlen = length $prebuf ) { | |
@@ -269,7 +281,6 @@ sub handle_connection { | |
$is_keepalive ? $self->{keepalive_timeout} : $self->{timeout}, | |
) or return; | |
} | |
- $self->{can_exit} = 0; | |
my $reqlen = parse_http_request($buf, $env); | |
if ($reqlen >= 0) { | |
# handle request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ab -c 20 -n 100000 -r http://localhost:5000/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests | |
Completed 90000 requests | |
Completed 100000 requests | |
Finished 100000 requests | |
Server Software: gazelle | |
Server Hostname: localhost | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 11 bytes | |
Concurrency Level: 20 | |
Time taken for tests: 11.350 seconds | |
Complete requests: 100000 | |
Failed requests: 13 | |
(Connect: 0, Receive: 0, Length: 13, Exceptions: 0) | |
Write errors: 0 | |
Total transferred: 12899226 bytes | |
HTML transferred: 1099934 bytes | |
Requests per second: 8810.82 [#/sec] (mean) | |
Time per request: 2.270 [ms] (mean) | |
Time per request: 0.113 [ms] (mean, across all concurrent requests) | |
Transfer rate: 1109.89 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 1 0.6 1 22 | |
Processing: 0 2 0.8 2 28 | |
Waiting: 0 1 0.8 1 28 | |
Total: 0 2 1.0 2 29 | |
Percentage of the requests served within a certain time (ms) | |
50% 2 | |
66% 2 | |
75% 2 | |
80% 3 | |
90% 3 | |
95% 4 | |
98% 4 | |
99% 5 | |
100% 29 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ab -c 20 -n 100000 -r http://localhost:5000/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests | |
Completed 90000 requests | |
Completed 100000 requests | |
Finished 100000 requests | |
Server Software: Plack::Handler::Starlet | |
Server Hostname: localhost | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 11 bytes | |
Concurrency Level: 20 | |
Time taken for tests: 22.619 seconds | |
Complete requests: 100000 | |
Failed requests: 135 | |
(Connect: 0, Receive: 45, Length: 45, Exceptions: 45) | |
Write errors: 0 | |
Total transferred: 14495505 bytes | |
HTML transferred: 1099659 bytes | |
Requests per second: 4421.02 [#/sec] (mean) | |
Time per request: 4.524 [ms] (mean) | |
Time per request: 0.226 [ms] (mean, across all concurrent requests) | |
Transfer rate: 625.83 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 1 1.4 1 26 | |
Processing: 0 3 2.0 3 81 | |
Waiting: 0 3 2.0 3 80 | |
Total: 1 5 2.2 4 81 | |
Percentage of the requests served within a certain time (ms) | |
50% 4 | |
66% 5 | |
75% 5 | |
80% 6 | |
90% 7 | |
95% 8 | |
98% 10 | |
99% 12 | |
100% 81 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ start_server --port 5000 --pid app.pid -- plackup -s Starman --workers 20 app.psgi | |
$ ab -c 20 -n 100000 -r http://localhost:5000/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests | |
Completed 90000 requests | |
Completed 100000 requests | |
Finished 100000 requests | |
Server Software: | |
Server Hostname: localhost | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 11 bytes | |
Concurrency Level: 20 | |
Time taken for tests: 31.966 seconds | |
Complete requests: 100000 | |
Failed requests: 351 | |
(Connect: 0, Receive: 2, Length: 179, Exceptions: 170) | |
Write errors: 0 | |
Total transferred: 11180848 bytes | |
HTML transferred: 1098119 bytes | |
Requests per second: 3128.35 [#/sec] (mean) | |
Time per request: 6.393 [ms] (mean) | |
Time per request: 0.320 [ms] (mean, across all concurrent requests) | |
Transfer rate: 341.58 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 3 1.3 3 33 | |
Processing: 0 3 1.6 3 35 | |
Waiting: 0 3 1.5 3 34 | |
Total: 2 6 2.2 6 39 | |
Percentage of the requests served within a certain time (ms) | |
50% 6 | |
66% 7 | |
75% 7 | |
80% 7 | |
90% 8 | |
95% 9 | |
98% 11 | |
99% 14 | |
100% 39 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ start_server --port 5000 --pid app.pid --signal-on-hup=QUIT --signal-on-term=QUIT -- starman --workers 20 app.psgi | |
$ ab -c 20 -n 100000 -r http://localhost:5000/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests | |
Completed 90000 requests | |
Completed 100000 requests | |
Finished 100000 requests | |
Server Software: | |
Server Hostname: localhost | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 11 bytes | |
Concurrency Level: 20 | |
Time taken for tests: 22.525 seconds | |
Complete requests: 100000 | |
Failed requests: 240 | |
(Connect: 0, Receive: 0, Length: 120, Exceptions: 120) | |
Write errors: 0 | |
Total transferred: 11187008 bytes | |
HTML transferred: 1098724 bytes | |
Requests per second: 4439.48 [#/sec] (mean) | |
Time per request: 4.505 [ms] (mean) | |
Time per request: 0.225 [ms] (mean, across all concurrent requests) | |
Transfer rate: 485.01 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 2 1.8 2 44 | |
Processing: 0 2 1.9 2 44 | |
Waiting: 0 2 1.7 2 43 | |
Total: 1 4 2.8 4 48 | |
Percentage of the requests served within a certain time (ms) | |
50% 4 | |
66% 4 | |
75% 5 | |
80% 5 | |
90% 6 | |
95% 6 | |
98% 8 | |
99% 12 | |
100% 48 (longest request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment