Skip to content

Commit

Permalink
implement --max-keepalive-requests (issue miyagawa#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
eserte committed Jul 11, 2017
1 parent 24febd7 commit 06cee30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Starman/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ sub process_request {
or die $!;
}

my $keepalive_requests = 0;

while ( $self->{client}->{keepalive} ) {
last if !$conn->connected;

Expand Down Expand Up @@ -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)/ ) {
Expand All @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions script/starman
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06cee30

Please sign in to comment.