Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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

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 studying the Monastery: (8)
As of 2016-10-01 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (6 votes). Check out past polls.