Apache-Throttle
view release on metacpan or search on metacpan
Throttle/Log.pm view on Meta::CPAN
my ($r) = shift;
my $id = get_id($r);
my $sum = 0;
my $i = 0;
foreach my $v (@{ $speeds->{$id} }) {
$sum += $v;
$i++;
}
$i ? int ($sum / $i) : undef;
}
1;
__END__
=head1 NAME
Apache::Throttle::Log - Apache/Perl module to determine average speed
=head1 SYNOPSIS
<Location /images>
PerlSetVar MaxUsers 100
PerlSetVar MinSize 100000
PerlSetVar MinDuration 0.1
PerlSetVar IDSub Website::Session::session_id
PerlTypeHandler Apache::Throttle::Log
</Location>
=head1 DESCRIPTION
Apache::Throttle::Log measures the speed that requests are transmitted
at and can calculate the average transmittion speed for a connection.
It isn't particularly accurate yet, but seems to be close enough for
most applications. If you know of a better way to measure the speed
feel free to send me suggestions, patches, etc.
=head1 OPTIONS
These options can be set with the PerlSetVar operative in one of your
Apache configuration files.
=over 4
=item ThrottleDebug
Prints extra debugging information to the error log.
=item MaxUsers
Clear the speed hash when it reaches the specified number of users.
I'm still looking for a better way of doing this. If anyone has any
suggestions, feel free to tell me. This option is strongly recommended.
=item LogTypes
Only log requests with a MIME-type that matches this regular expression.
This is useful for only logging "^image/" if you plan to serve images and
the speeds for other large, compressable files are throwing off your
averages. It's probably much more efficient to keep all your images under
one directory and just put a <Location> container around the handler
definition though.
=item MinSize
The minimum size in bytes that a request has to be for it to be logged.
=item MinDuration
The minimum time in seconds that a request has to take for it to be logged.
=item StoreSpeeds
The number of speeds to store for each connection. These are averaged
together to predict the speed of the next request.
=item ContinueChecking
If this is set to a true value, Apache::Throttle::Log will continue
logging requests from a user forever. If unspecified or set false,
however, it will only log as many requests as StoreSpeeds is set to,
and then DECLINED requests from the same user. This should be used
when speeds are fairly constant and Apache::Throttle is putting a
strain on your webserver.
=item IDSub
This specifies the subroutine that Apache::Throttle::Log will get the
hash key from. The subroutine will be called with one argument:
the Apache request object, and will be expected to return a scalar.
This scalar will be used as the hash key to store the connection
information. Defaults to the remote IP address for the request.
=back
=head1 AUTHOR
Don Schwarz <dons@xnet.com>
=head1 SEE ALSO
L<Apache::Throttle>, L<mod_perl>
=head1 COPYRIGHT
Copyright (c) 1998 Don Schwarz. All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms
as Perl itself.
=cut
( run in 1.827 second using v1.01-cache-2.11-cpan-39bf76dae61 )