shortcutting DNS?
am 14.03.2005 19:01:28 von matthew_berk
Silly question.
In using LWP to gather pages, is there a way to shortcut the DNS lookup
to eliminate the overhead? I assume LWP leaves this to the OS, in which
case, my question is better asked elsewhere, yes?
Thanks,
Matthew
Re: shortcutting DNS?
am 15.03.2005 11:55:05 von gisle
Matthew Berk writes:
> In using LWP to gather pages, is there a way to shortcut the DNS
> lookup to eliminate the overhead? I assume LWP leaves this to the OS,
> in which case, my question is better asked elsewhere, yes?
LWP will let IO::Socket::INET module do the host lookup. This module
will call the $self->_get_addr() method which by default will call
gethostbyname() to get the information from the OS.
You can provide your own implementation of _get_addr if you want it to
do something else. You might for instance provide one that does more
agressive caching or even one that does proper timeout handling. The
following trivial program demonstrate how you can trap these calls.
Regards,
Gisle
#!/usr/bin/perl -w
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
print $ua->get("http://www.example.com/")->status_line, "\n";
print $ua->get("http://www.perl.org/")->status_line, "\n";
BEGIN {
package Net::HTTP;
use Socket qw(inet_ntoa);
# demonstrate how we can trap host name lookups
sub _get_addr {
my $self = shift;
my @addr = $self->SUPER::_get_addr(@_);
print "_get_addr @_ => ", join(" ", map inet_ntoa($_), @addr), "\n";
return @addr;
}
}
Re: shortcutting DNS?
am 15.03.2005 13:52:27 von ville.skytta
On Tue, 2005-03-15 at 02:55 -0800, Gisle Aas wrote:
> Matthew Berk writes:
>
> > In using LWP to gather pages, is there a way to shortcut the DNS
> > lookup to eliminate the overhead? I assume LWP leaves this to the OS,
> > in which case, my question is better asked elsewhere, yes?
>
> LWP will let IO::Socket::INET module do the host lookup. This module
> will call the $self->_get_addr() method which by default will call
> gethostbyname() to get the information from the OS.
If you're running Linux, nscd(8) could help. It's part of glibc, IIRC.