From: Tomas Doran Date: Sun, 28 Mar 2010 16:54:36 +0000 (+0000) Subject: Cache the IP address => hostname lookups which could be performed multiple times... X-Git-Tag: 5.80022~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=13e46699880fb7b5a880a1b5aad48162f3f11e0e Cache the IP address => hostname lookups which could be performed multiple times to mitigate slow DNS servers. Poor man's replacement for 13063 --- diff --git a/Changes b/Changes index e05dd8b..be7627f 100644 --- a/Changes +++ b/Changes @@ -11,8 +11,11 @@ in parameter filtering (for example). - $c->model/view/controller have become a lot faster for non-regexp names by using direct hash lookup instead of looping. + - IP address => hostname mapping for the server is only done once and cached + by Catalyst::Engine::HTTP to somewhat mitigate the problem of people + developing on machines pointed at slow DNS servers. - Bug fixed: + Bugs fixed: - DispatchType::Index's uri_for_action only returns for actions registered with it (prevents 'index :Path' or similar resolving to the wrong URI) - Make sure to construct Upload objects properly, even if there are diff --git a/lib/Catalyst/Engine/HTTP.pm b/lib/Catalyst/Engine/HTTP.pm index 7f01795..30ddbc4 100644 --- a/lib/Catalyst/Engine/HTTP.pm +++ b/lib/Catalyst/Engine/HTTP.pm @@ -534,13 +534,21 @@ sub _socket_data { peeraddr => $iaddr ? ( inet_ntoa($iaddr) || '127.0.0.1' ) : '127.0.0.1', - localname => gethostbyaddr( $localiaddr, AF_INET ) || 'localhost', + localname => _gethostbyaddr( $localiaddr ), localaddr => inet_ntoa($localiaddr) || '127.0.0.1', }; return $data; } +{ # If you have a crappy DNS server then these can be slow, so cache 'em + my %hostname_cache; + sub _gethostbyaddr { + my $ip = shift; + $hostname_cache{$ip} ||= gethostbyaddr( $ip, AF_INET ) || 'localhost'; + } +} + sub _inet_addr { unpack "N*", inet_aton( $_[0] ) } =head2 options