[Catalyst] Slowness on test server caused by reverse DNS lookups

Marcello Romani mromani at ottotecnica.com
Tue May 30 08:58:21 CEST 2006


Eric K. Olson ha scritto:
> Hi Folks!
> 
> In writing my first Catalyst Application (and may I say THANK YOU for 
> creating this framework!),
> I noticed a long delay on every request, which I traced to the reverse 
> DNS lookups of the server
> and client IP addresses in Catalyst::Engine::HTTP::_socket_info.  I 
> patched it to have '-nodns'
> and '-noremotedns' to turn off the server and client reverse DNS 
> lookups, respectively.  That patch
> appears below, including a patch to the Helper that generates the 
> myapp_server.pl code.
> 
> I realize that the test server is just for getting people up and running 
> quickly, but I think it
> is important that it have good response time, even in the face of badly 
> configured (or impossible
> to properly configure) reverse DNS records.  I initially attributed the 
> delay to actual processing,
> which made Catalyst look REALLY slow.  It was 100% DNS timeouts-- even 
> with the test server my
> App (using TT and DBIC::Schema) is REALLY fast.
> 
> Questions:
> 
> 1. Is it appropriate to post this patch here, or should I be contacting 
> the maintainer of that
> package directly?
> 
> 2. I created an instance variable _options to hold the options hash, 
> rather than passing it down
> into _handler() and then into _socket_data().  I was surprised it wasn't 
> already an instance variable.
> Is this an OK thing to do?  Is there a coding style standard somewhere?
> 
> 3. I also created an accessor method options() in 
> Catalyst::Engine::HTTP, but not a setter method.  I
> was surprised that C:E:HTTP didn't inherit from a superclass providing 
> generic accessor/setters for
> all the instance variables.  Was this an OK thing to do?
> 
> Basically, if I want my patches to be rolled into the official Catalyst, 
> I need to know if I'm doing
> things appropriately.  Any constructive input is welcome.
> 
> Once again, thank you folks SO much for making web development fun and 
> interesting again!
> 
> Cheers,
> 
> -Eric
> 
> 
> ------------------------------------------------------------------------
> 
> diff -r -U 2 old/Catalyst/Engine/HTTP.pm new/Catalyst/Engine/HTTP.pm
> --- old/Catalyst/Engine/HTTP.pm	2006-05-29 14:06:48.632044096 -1000
> +++ new/Catalyst/Engine/HTTP.pm	2006-05-29 14:25:43.283550848 -1000
> @@ -117,4 +117,6 @@
>      $options ||= {};
>  
> +    $self->{_options} = $options;
> +
>      my $restart = 0;
>      local $SIG{CHLD} = 'IGNORE';
> @@ -308,9 +310,12 @@
>      my ( undef, $localiaddr ) = sockaddr_in($local_sockaddr);
>  
> +    my $peeraddr_str = inet_ntoa($iaddr) || "127.0.0.1";
> +    my $localaddr_str = inet_ntoa($localiaddr) || "127.0.0.1";
> +
>      my $data = {
> -        peername => gethostbyaddr( $iaddr, AF_INET ) || "localhost",
> -        peeraddr => inet_ntoa($iaddr) || "127.0.0.1",
> -        localname => gethostbyaddr( $localiaddr, AF_INET ) || "localhost",
> -        localaddr => inet_ntoa($localiaddr) || "127.0.0.1",
> +        peername => ($self->options->{'nodns'} ? $peeraddr_str : (gethostbyaddr( $iaddr, AF_INET ) || "localhost")),
> +        peeraddr => $peeraddr_str,
> +        localname => ($self->options->{'noremotedns'} ? $localaddr_str : (gethostbyaddr( $localiaddr, AF_INET ) || "localhost")),
> +        localaddr => $localaddr_str,
>      };
>  
> @@ -333,4 +338,10 @@
>  }
>  
> +sub options {
> +    my ($self) = @_;
> +
> +    return $self->{_options};
> +}
> +
>  sub _inet_addr { unpack "N*", inet_aton( $_[0] ) }
>  
> diff -r -U 2 old/Catalyst/Helper.pm new/Catalyst/Helper.pm
> --- old/Catalyst/Helper.pm	2006-05-29 14:15:17.998608608 -1000
> +++ new/Catalyst/Helper.pm	2006-05-29 14:26:21.004816344 -1000
> @@ -854,4 +854,6 @@
>  my $restart_delay = 1;
>  my $restart_regex = '\.yml$|\.yaml$|\.pm$';
> +my $nodns         = 0;
> +my $noremotedns   = 0;
>  
>  my @argv = @ARGV;
> @@ -866,5 +868,7 @@
>      'restart|r'         => \$restart,
>      'restartdelay|rd=s' => \$restart_delay,
> -    'restartregex|rr=s' => \$restart_regex
> +    'restartregex|rr=s' => \$restart_regex,
> +    'nodns'             => \$nodns,
> +    'noremotedns'       => \$noremotedns,
>  );
>  
> @@ -888,5 +892,7 @@
>      restart       => $restart,
>      restart_delay => $restart_delay,
> -    restart_regex => qr/$restart_regex/
> +    restart_regex => qr/$restart_regex/,
> +    nodns         => $nodns,
> +    noremotedns   => $noremotedns,
>  } );
>  
> @@ -915,4 +921,8 @@
>                        a restart when modified
>                        (defaults to '\.yml$|\.yaml$|\.pm$')
> +       -nodns         do not use reverse DNS to look up the
> +                      server's IP address
> +       -noremotedns   do not use reverse DNS to look up the
> +                      client's IP address
>  
>   See also:
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst

I had a problem that is possibly related to this: when trying to access 
the local test server, the browser requests seemed to reach it only 
after a rather lengthy delay (5 seconds or so), but if I disabled the 
LAN interface everything was instantaneous.

WinXP Pro SP2, Cat 5.6x (don't have that machine anymore, unfortunately).


-- 
Marcello Romani
Responsabile IT
Ottotecnica s.r.l.
http://www.ottotecnica.com



More information about the Catalyst mailing list