From 06cee305ccd63ea175770318e12f21afe06f0867 Mon Sep 17 00:00:00 2001 From: Slaven Rezic Date: Tue, 4 Jul 2017 15:56:55 +0200 Subject: [PATCH] implement --max-keepalive-requests (issue #124) --- lib/Starman/Server.pm | 8 ++++++++ script/starman | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/Starman/Server.pm b/lib/Starman/Server.pm index e03f2e7..0a13538 100644 --- a/lib/Starman/Server.pm +++ b/lib/Starman/Server.pm @@ -210,6 +210,8 @@ sub process_request { or die $!; } + my $keepalive_requests = 0; + while ( $self->{client}->{keepalive} ) { last if !$conn->connected; @@ -300,6 +302,8 @@ sub process_request { DEBUG && warn "[$$] Request done\n"; if ( $self->{client}->{keepalive} ) { + $keepalive_requests++; + # If we still have data in the input buffer it may be a pipelined request if ( $self->{client}->{inputbuf} ) { if ( $self->{client}->{inputbuf} =~ /^(?:GET|HEAD)/ ) { @@ -322,6 +326,10 @@ sub process_request { } } + if (exists $self->{options}->{max_keepalive_requests}) { + last if $keepalive_requests >= $self->{options}->{max_keepalive_requests}; + } + DEBUG && warn "[$$] Waiting on previous connection for keep-alive request...\n"; my $sel = IO::Select->new($conn); diff --git a/script/starman b/script/starman index 52d877f..82275b7 100755 --- a/script/starman +++ b/script/starman @@ -122,6 +122,18 @@ failover (see above). Number of the requests to process per one worker process. Defaults to 1000. +Note that "requests" actually means "connections served by a worker". +In presence of Keep-alive a worker process can actually serve more +requests; this can only be limited with the +C<--max-keepalive-requests> option. + +=item --max-keepalive-requests + +Maximum number of Keep-alive requests served for a connection. By +default there's no limit. + +Note: multiple consecutive pipelined requests still count as one request. + =item --preload-app This option lets Starman preload the specified PSGI application in the