[svn:modperl-modules] rev 200 - in Apache-Watchdog-RunAway/trunk: . t/conf
[email protected] 21 Mar 2005 20:00:08 -0000
| Newsgroups | perl.modperl.modules.svn |
|---|---|
| Message-ID | <[email protected]> |
Author: stas
Date: Mon Mar 21 12:00:08 2005
New Revision: 200
Modified:
Apache-Watchdog-RunAway/trunk/Changes
Apache-Watchdog-RunAway/trunk/MANIFEST
Apache-Watchdog-RunAway/trunk/README
Apache-Watchdog-RunAway/trunk/RunAway.pm
Apache-Watchdog-RunAway/trunk/t/conf/modperl_extra.pl
Log:
mp2 port
Modified: Apache-Watchdog-RunAway/trunk/Changes
==============================================================================
--- Apache-Watchdog-RunAway/trunk/Changes (original)
+++ Apache-Watchdog-RunAway/trunk/Changes Mon Mar 21 12:00:08 2005
@@ -2,7 +2,14 @@
=over
-=item 0.4 - dev
+=item 1.00 - Mon Mar 21 13:49:25 EST 2005
+
+ported to mod_perl2
+
+open the safehang.log file only when it's used for the first time, so
+if someone loads the module before setting
+$Apache::Watchdog::RunAway::LOG_FILE the user value will take an
+effect
added a basic test suite
Modified: Apache-Watchdog-RunAway/trunk/MANIFEST
==============================================================================
--- Apache-Watchdog-RunAway/trunk/MANIFEST (original)
+++ Apache-Watchdog-RunAway/trunk/MANIFEST Mon Mar 21 12:00:08 2005
@@ -1,8 +1,13 @@
Changes
+MANIFEST
Makefile.PL
-RunAway.pm
-bin/amprapmon
README
-MANIFEST
+RunAway.pm
TODO
+bin/amprapmon
+t/TEST.PL
+t/conf/extra.conf.in
+t/conf/modperl_extra.pl
+t/runaway/basic.t
+META.yml Module meta-data (added by MakeMaker)
Modified: Apache-Watchdog-RunAway/trunk/README
==============================================================================
--- Apache-Watchdog-RunAway/trunk/README (original)
+++ Apache-Watchdog-RunAway/trunk/README Mon Mar 21 12:00:08 2005
@@ -24,6 +24,9 @@
*** mod_perl 2.0 ***
+You can't use this module with threaded mpms. Since when a process is
+killed all threads in it will be killed.
+
% perl Makefile.PL MOD_PERL=2 -httpd /path/to/apache2/bin/httpd
% make
% make test
Modified: Apache-Watchdog-RunAway/trunk/RunAway.pm
==============================================================================
--- Apache-Watchdog-RunAway/trunk/RunAway.pm (original)
+++ Apache-Watchdog-RunAway/trunk/RunAway.pm Mon Mar 21 12:00:08 2005
@@ -1,12 +1,26 @@
package Apache::Watchdog::RunAway;
-$Apache::VMonitor::VERSION = 0.3;
+$Apache::VMonitor::VERSION = '1.00';
use strict;
+
+BEGIN {
+ use constant MP2 => eval { require mod_perl; $mod_perl::VERSION > 1.99 };
+ die "mod_perl is required to run this module: $@" if $@;
+
+ if (MP2) {
+ require APR::Pool;
+ } else {
+ # nada
+ }
+}
+
use Apache::Scoreboard ();
-use Apache::Constants ();
use Symbol ();
-use Apache ();
+
+if (MP2 && require Apache::MPM && Apache::MPM->is_threaded()) {
+ die __PACKAGE__ . " is suitable to be used only under prefork MPM";
+}
use subs qw(debug log_error);
@@ -122,6 +136,8 @@
defined (my $watchdog_pid = fork) or die "Cannot fork: $!\n";
if ($watchdog_pid) {
+ warn "detached monitor pid $watchdog_pid started\n"
+ if $Apache::Watchdog::RunAway::DEBUG;
return $watchdog_pid;
}
else {
@@ -159,12 +175,23 @@
}
+my $pool;
# the real code that does all the accounting and killings
############
sub monitor {
- my $image = Apache::Scoreboard->fetch($Apache::Watchdog::RunAway::SCOREBOARD_URL);
+ die "\$Apache::Watchdog::RunAway::SCOREBOARD_URL is not set"
+ unless $Apache::Watchdog::RunAway::SCOREBOARD_URL;
+
+ my @args = ($Apache::Watchdog::RunAway::SCOREBOARD_URL);
+ if (MP2) {
+ # mp's Apache::Scoreboard::fetch needs a pool arg
+ $pool = APR::Pool->new;
+ unshift @args, $pool;
+ }
+
+ my $image = Apache::Scoreboard->fetch(@args);
unless ($image){
# reset the counters and timers
%req_proc_time = ();
@@ -174,17 +201,19 @@
return;
}
- for (my $i = 0; $i<Apache::Constants::HARD_SERVER_LIMIT; $i++) {
- my $pid = $image->parent($i)->pid;
+ for (my $i = 0; $i < $image->server_limit; $i++) {
+ my $parent_score = MP2 ? $image->parent_score($i) : $image->servers($i);
+ next unless $parent_score;
+
+ my $pid = MP2 ? $parent_score->pid : $image->parent($i)->pid;
last unless $pid;
- my $process = $image->servers($i);
+ my $worker_score = MP2 ? $parent_score->worker_score : $parent_score;
# we care only about processes that in 'W' status
- # processing. this is very not clean coding style: (W means
- # 'writing to a client' and it's equal to 4 in status field
- next unless $process->status == 4;
+ # processing. (W means 'writing to a client')
+ next unless $worker_score->status eq 'W';
# init if it's uninitialized (to non existant -1 count)
# can't use ||= construct as a value can be 0...
@@ -194,9 +223,9 @@
# make sure the proc time is initialized
$req_proc_time{$pid} ||= 0;
- my $count = $process->my_access_count;
+ my $count = $worker_score->my_access_count;
debug "OK: $i $pid ",
- $process->status, " $count ",
+ $worker_score->status, " $count ",
$req_proc_time{$pid}, " ",
$req_number{$pid};
@@ -210,8 +239,8 @@
which is longer than $Apache::Watchdog::RunAway::TIMEOUT secs limit.
EOT
if ($Apache::Watchdog::RunAway::VERBOSE) {
- $error .= 'It was handling [' . $process->request() .
- '] for [' . $process->client() . "]\n";
+ $error .= 'It was handling [' . $worker_score->request() .
+ '] for [' . $worker_score->client() . "]\n";
}
log_error $error;
Modified: Apache-Watchdog-RunAway/trunk/t/conf/modperl_extra.pl
==============================================================================
--- Apache-Watchdog-RunAway/trunk/t/conf/modperl_extra.pl (original)
+++ Apache-Watchdog-RunAway/trunk/t/conf/modperl_extra.pl Mon Mar 21 12:00:08 2005
@@ -16,12 +16,17 @@
$Apache::Watchdog::RunAway::SCOREBOARD_URL = $retrieve_url;
$Apache::Watchdog::RunAway::VERBOSE = 0;
+warn "The monitor will use URL: $retrieve_url\n";
+
# cleanup any remainder from the last test
Apache::Watchdog::RunAway::stop_monitor();
# forks a monitor
Apache::Watchdog::RunAway::start_detached_monitor();
+# comment out the following line and watch t/log/safehang.log for
+# what's monitor is doing
+
# kills a monitor
Apache::Watchdog::RunAway::stop_monitor();