Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core speedups #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/Perlbal/ClientHTTPBase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -310,21 +310,22 @@ sub handle_request {
# re-enable reads.
$self->watch_read(0);

my $select = sub {
# now that we have headers, it's time to tell the selector
# plugin that it's time for it to select which real service to
# use
my $selector = $self->{'service'}->selector();
return $self->_simple_response(500, "No service selector configured.")
unless ref $selector eq "CODE";
$selector->($self);
};

# now that we have headers, it's time to tell the selector
# plugin that it's time for it to select which real service to
# use
my $svc = $self->{'service'};
if ($svc->{latency}) {
Danga::Socket->AddTimer($svc->{latency} / 1000, $select);
my $selector = $svc->selector();

return $self->_simple_response(500, "No service selector configured.")
unless ref $selector eq "CODE";

unless ($svc->{latency}) {
$selector->($self);
} else {
$select->();
my $select = sub {
$selector->($self);
};
Danga::Socket->AddTimer($svc->{latency} / 1000, $select);
}
}

Expand Down
14 changes: 4 additions & 10 deletions lib/Perlbal/ClientProxy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,12 @@ sub backend_response_received {
# a certain size and got back something different
my $code = $be->{res_headers}->response_code + 0;

my $bad_code = sub {
return 0 if $code >= 200 && $code <= 299;
return 0 if $code == 416;
return 1;
};
my $bad_code = ($code < 200 || $code >= 300) && $code != 416;

my $bad_size = sub {
return 0 unless defined $self->{reproxy_expected_size};
return $self->{reproxy_expected_size} != $be->{res_headers}->header('Content-length');
};
my $bad_size = (defined $self->{reproxy_expected_size} &&
$self->{reproxy_expected_size} != $be->{res_headers}->header('Content-length'));

if ($bad_code->() || $bad_size->()) {
if ($bad_code || $bad_size) {
# fall back to an alternate URL
$be->{client} = undef;
$be->close('non_200_reproxy');
Expand Down
26 changes: 12 additions & 14 deletions lib/Perlbal/Service.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1182,17 +1182,6 @@ sub mark_node_used {
sub get_client {
my Perlbal::Service $self = shift;

my $ret = sub {
my Perlbal::ClientProxy $cp = shift;
$self->{waiting_client_count}--;
delete $self->{waiting_client_map}{$cp->{fd}};

# before we return, start another round of connections
$self->spawn_backends;

return $cp;
};

# determine if we should jump straight to the high priority queue or
# act as pressure relief on the standard queue
my $hp_first = 1;
Expand All @@ -1211,24 +1200,33 @@ sub get_client {
my $backlog = scalar @{$self->{waiting_clients}};
print "Got from fast queue, in front of $backlog others\n";
}
return $ret->($cp);
goto RETURN_CP;
}

# regular clients:
while ($cp = shift @{$self->{waiting_clients}}) {
next if $cp->{closed};
print "Backend requesting client, got normal = $cp->{fd}.\n" if Perlbal::DEBUG >= 2;
return $ret->($cp);
goto RETURN_CP;
}

# low-priority (batch/idle) clients.
while ($cp = shift @{$self->{waiting_clients_lowpri}}) {
next if $cp->{closed};
print "Backend requesting client, got low priority = $cp->{fd}.\n" if Perlbal::DEBUG >= 2;
return $ret->($cp);
goto RETURN_CP;
}

return undef;

RETURN_CP:
$self->{waiting_client_count}--;
delete $self->{waiting_client_map}{$cp->{fd}};

# before we return, start another round of connections
$self->spawn_backends;

return $cp;
}

# given a backend, verify it's generation
Expand Down