Skip to content

Commit

Permalink
Small refactor, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
athomason committed Mar 4, 2011
1 parent 6574a18 commit 6062993
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Perlbal/Plugin/Throttle.pm
Expand Up @@ -297,12 +297,12 @@ sub register {

my $start_handler = sub {
my $retval = eval {
my $request_start = Time::HiRes::time;

VERBOSE and Perlbal::log(info => "In Throttle (%s)",
defined $DELAYED ? sprintf 'back after %.2fs', $DELAYED : 'initial'
);

my $request_start = Time::HiRes::time;

my Perlbal::ClientProxy $cp = shift;
unless ($cp) {
VERBOSE and Perlbal::log(error => "Missing ClientProxy");
Expand Down Expand Up @@ -384,18 +384,22 @@ sub register {
return HANDLE_REQUEST;
}

# now entering throttle path...

# check if we've seen this IP lately.
my $key = $cfg->{instance_name} . $ip;
$store->get(key => $key, timeout => $cfg->{initial_delay}, callback => sub {
my ($last_request_time, $violations) = @_;
$violations ||= 0;

# do an early set to update the last_request_time and
# expiration in case of early exit
$store->set(
key => $key,
exptime => $cfg->{throttle_threshold_seconds},
timeout => $cfg->{initial_delay},
start => $request_start,
count => $violations,
exptime => $cfg->{throttle_threshold_seconds},
timeout => $cfg->{initial_delay},
);

my $time_since_last_request;
Expand Down

0 comments on commit 6062993

Please sign in to comment.