Permalink
Browse files

support for slow restart (but yet without tests or docs)

  • Loading branch information...
1 parent 31a7862 commit 89b50d20854b2d76cc10f537a893d88b67bdc002 @kazuho committed Jan 21, 2011
Showing with 30 additions and 13 deletions.
  1. +10 −2 lib/Plack/Handler/Starlet.pm
  2. +20 −11 lib/Starlet/Server.pm
@@ -47,13 +47,21 @@ sub run {
$self->setup_listener();
if ($self->{max_workers} != 0) {
# use Parallel::Prefork
- my $pm = Parallel::Prefork->new({
+ my %pm_args = (
max_workers => $self->{max_workers},
trap_signals => {
TERM => 'TERM',
HUP => 'TERM',
},
- });
+ );
+ if (defined $self->{spawn_interval}) {
+ $pm_args{trap_signals}{HUP} = [ 'TERM', $self->{spawn_interval} ];
+ $pm_args{spawn_interval} = $self->{spawn_interval};
+ }
+ if (defined $self->{err_respawn_interval}) {
+ $pm_args{err_respawn_interval} = $self->{err_respawn_interval};
+ }
+ my $pm = Parallel::Prefork->new(\%pm_args);
while ($pm->signal_received ne 'TERM') {
$pm->start and next;
$self->accept_loop($app, $self->_calc_reqs_per_child());
View
@@ -26,20 +26,29 @@ sub new {
my($class, %args) = @_;
my $self = bless {
- host => $args{host} || 0,
- port => $args{port} || 8080,
- timeout => $args{timeout} || 300,
- keepalive_timeout => $args{keepalive_timeout} || 2,
- max_keepalive_reqs => $args{max_keepalive_reqs} || 1,
- server_software => $args{server_software} || $class,
- server_ready => $args{server_ready} || sub {},
- min_reqs_per_child =>
+ host => $args{host} || 0,
+ port => $args{port} || 8080,
+ timeout => $args{timeout} || 300,
+ keepalive_timeout => $args{keepalive_timeout} || 2,
+ max_keepalive_reqs => $args{max_keepalive_reqs} || 1,
+ server_software => $args{server_software} || $class,
+ server_ready => $args{server_ready} || sub {},
+ min_reqs_per_child => (
defined $args{min_reqs_per_child}
? $args{min_reqs_per_child} : undef,
- max_reqs_per_child =>
+ ),
+ max_reqs_per_child => (
$args{max_reqs_per_child} || $args{max_requests} || 100,
- is_multiprocess => Plack::Util::FALSE,
- _using_defer_accept => undef,
+ ),
+ spawn_interval => (
+ defined $args{spawn_interval} ? $args{spawn_interval} : undef,
+ ),
+ err_respawn_interval => (
+ defined $args{err_respawn_interval}
+ ? $args{err_respawn_interval} : undef,
+ ),
+ is_multiprocess => Plack::Util::FALSE,
+ _using_defer_accept => undef,
}, $class;
if ($args{max_workers} && $args{max_workers} > 1) {

0 comments on commit 89b50d2

Please sign in to comment.