Hi,
I've got a big list of hostnames, and I need to resolve them to
their IP#. Many times the authoritative nameserver hangs or
never answers, and the program waits ~30 seconds before timing out.
I thought if I created a bunch of threads that I could get around
the problem and would only hang when all threads (100) are hung.
But that doesn't seem to be the case. Do I have my threading
wrong?
require 'socket'
threads = []
100.times { |i|
threads << Thread.new(i) {
while name = gets # a list of hostnames from stdin
name.chomp!
begin
a = IPSocket.getaddress(name)
puts "#{name}\t#{a}"
rescue SocketError
$stderr.puts "+\t#{name}\t#{$!}" # timeout etc...
end
end
}
}
threads.each {|t| t.join }
Also, my google search for "async resolve ruby" turned up something
interesting (though unrelated):
http://freshmeat.net/projects/flex.rb/download/
flex.rb is a regexp matching and scanning library for the Ruby language. It
is more than 3 times faster than Ruby regexps, and supports matching text
arriving in multiple parts (via async, non-blocking I/O). flex.rb embeds the
GNU Flex 2.5.4 (fast lexical analyzer generator) as an engine, and all of
Flex's functionality is accessible from Ruby scripts.
anyone using it?
thanks,
-joe