Skip to content

Instantly share code, notes, and snippets.

/restart.pl Secret

Created July 4, 2017 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7db38f2441d6cd59962134c738b9dcda to your computer and use it in GitHub Desktop.
Save anonymous/7db38f2441d6cd59962134c738b9dcda to your computer and use it in GitHub Desktop.
# Stop prefork workers gracefully once they reach a certain size
my $parent = $$;
Mojo::IOLoop->next_tick(
sub {
Mojo::IOLoop->recurring(
5 => sub {
my $rss = (getrusage())[2];
my $max = $config->{max_worker_rss};
return unless $rss > $max;
$app->log->warn(
qq{Worker exceeded RSS limit "$rss > $max", restarting});
Mojo::IOLoop->stop_gracefully;
}
) if $parent ne $$;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment