On 2007-08-02 17:54:01 -0400, Guy Hulbert wrote:
> On Thu, 2007-08-02 at 23:04 +0200, Peter J. Holzer wrote:
> > * The return value should probably be cached. Doing a DNS lookup every
> >   time is wasteful. A connection note is probably the cleanest way to
> >   do this.
> 
> Why does everyone (i've seen this on other projects) want to write code
> to do DNS lookups ?

I don't want to write code to do DNS looks. gethostbyaddr does a DNS
lookup (unless it gets the info from /etc/hosts, or NIS, or whatever),
and I want to avoid to call it more often than necessary.

Therefore instead of 

    my $local_name = gethostbyaddr(inet_aton($local_ip), AF_INET);

that code should be something like 

    my $local_name = $self->connection->notes('local_name');
    unless ($local_name) {
        $local_name = $self->connection->notes('local_name');
        $self->connection->notes('local_name', $local_name);
    }

> Won't a local daemon (bind or djbdns) + libresolv do the caching for
> you ?

It's still a UDP query to an external process. It's not a problem for
me, we have only about 30 - 50 k connections per day, and another 100 k
dns queries won't kill the server. (I know that for a fact,
because I have been running that code for a year or so now). But if I'm
cleaning up the plugin this is something I can easily fix.

(Although I have to admit that I misremembered: while the plugin is
called quite often, most calls are with different parameters than "me"
(in which case the plugin of course returns DECLINED immediately).
config("me") is on average called only 2.5 times per connection, so
maybe caching the result isn't worthwhile even though it is cheap.

        hp

-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | [EMAIL PROTECTED]         |
__/   | http://www.hjp.at/ |    -- Sam in "Freefall"

Attachment: signature.asc
Description: Digital signature

Reply via email to