-
-
Save kragen/166199 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
sub maybe_add_worker { | |
if ( @threads < $daemon->options->{maxthreads} ) { | |
print "Creating new thread\n"; | |
push @threads, threads->new(\&do_work); | |
} | |
} | |
sub remove_worker { | |
if ( @threads > $daemon->options->{minthreads} ) { | |
print "Removing thread\n"; | |
unshift(@threads)->detach; | |
} | |
} | |
maybe_add_worker for 1..$daemon->options->{minthreads}; | |
for (;;) { | |
if ( $apache_load > 100 ) { | |
remove_worker; | |
} elsif ( $queue_size > 10000 ) { | |
maybe_add_worker; | |
} | |
sleep 5; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment