Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: optimise code EV Event AnyEvent POE

by Corion (Pope)
on Jun 26, 2012 at 07:18 UTC ( #978345=note: print w/ replies, xml ) Need Help??


in reply to optimise code EV Event AnyEvent POE

Using AnyEvent::DNS, you could parallelize your DNS requests to the various blacklists instead of waiting for the results sequentially.

#!perl -w use strict; use AnyEvent; use AnyEvent::DNS; my %results; my $outstanding = AnyEvent->condvar; for my $domain (<DATA>) { $domain =~ s!\s+$!!; # Fire off a query for this hostname warn "Querying ip(s) for '$domain'"; $outstanding->begin(); AnyEvent::DNS::resolver->resolve ( $domain, "a", sub { $outstanding->end; if( @_ ) { for (@_) { my ($name, $type, $in, $ttl, $ip) = @$_; $results{ $name } ||= []; warn "Response for $name"; push @{$results{ $name }}, $ip; }; } else { warn "No response for $domain"; }; }); }; # Wait for all requests to finish $outstanding->recv; use Data::Dumper; warn Dumper \%results; __DATA__ google.de google.com example.com doesnotexist.local perlmonks.org


Comment on Re: optimise code EV Event AnyEvent POE
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978345]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2015-07-07 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls