Skip to content

Commit

Permalink
httpfile: use Net::HTTP::NB, remove LWP::UserAgent
Browse files Browse the repository at this point in the history
This allows us to use the same HTTP connections between
digest and HTTP size checks, reducing the number of open
connections we need in the Fsck worker.
  • Loading branch information
Eric Wong committed Aug 10, 2013
1 parent 81433c2 commit d5cd4cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions lib/MogileFS/HTTPFile.pm
Expand Up @@ -7,9 +7,6 @@ use Digest;
use MogileFS::Server;
use MogileFS::Util qw(error undeferr wait_for_readability wait_for_writeability);

# (caching the connection used for HEAD requests)
my $user_agent;

my %sidechannel_nexterr; # host => next error log time

# create a new MogileFS::HTTPFile instance from a URL. not called
Expand Down Expand Up @@ -242,27 +239,27 @@ retry:
sub digest_http {
my ($self, $alg, $ping_cb) = @_;

# TODO: refactor
my $node_timeout = MogileFS->config("node_timeout");
# Hardcoded connection cache size of 20 :(
$user_agent ||= LWP::UserAgent->new(timeout => $node_timeout, keep_alive => 20);
my $digest = Digest->new($alg);

my %opts = (
port => $self->{port},
# default (4K) is tiny, use 1M like replicate
':read_size_hint' => 0x100000,
':content_cb' => sub {
read_size_hint => 0x100000,
content_cb => sub {
$digest->add($_[0]);
$ping_cb->();
}
},
);

my $path = $self->{url};
my $res = $user_agent->get($path, %opts);
my $res;
$self->host->http("GET", $self->{uri}, \%opts, sub { ($res) = @_ });

# TODO: async interface for workers already running Danga::Socket->EventLoop
Danga::Socket->SetPostLoopCallback(sub { !defined $res });
Danga::Socket->EventLoop;

return $digest->digest if $res->is_success;
return FILE_MISSING if $res->code == 404;
return undeferr("Failed $alg (GET) check for $path (" . $res->code . "): "
return undeferr("Failed $alg (GET) check for $self->{url} (" . $res->code . "): "
. $res->message);
}

Expand Down
1 change: 0 additions & 1 deletion lib/MogileFS/Server.pm
Expand Up @@ -25,7 +25,6 @@ use File::Path ();
use Sys::Syslog ();
use Time::HiRes ();
use Net::Netmask;
use LWP::UserAgent;
use List::Util;
use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);

Expand Down
1 change: 1 addition & 0 deletions lib/MogileFS/Test.pm
Expand Up @@ -7,6 +7,7 @@ use DBI;
use FindBin qw($Bin);
use IO::Socket::INET;
use MogileFS::Server;
use LWP::UserAgent;
use base 'Exporter';

our @EXPORT = qw(&find_mogclient_or_skip &temp_store &create_mogstored &create_temp_tracker &try_for &want);
Expand Down

0 comments on commit d5cd4cf

Please sign in to comment.