From: Francis Cianfrocca Date: 2006-10-26T21:58:32+09:00 Subject: Re: threads ------=_Part_26262_17084025.1161867510266 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/24/06, Brad Tilley wrote: > > I'm rewriting some old Python scripts in Ruby. Just to learn a bit more. > I want to thread this code to check websites concurrently. Could somone > offer advice? What are reasonable limits on threads in Ruby? > > ips.each do |ip| > begin > Timeout::timeout(5) do > Net::HTTP.start(ip) do |site| > data = site.get( '/' ).body.downcase > if data.include?(minolta) and > data.include?(pagescope) > puts printer + "\t" + ip > elsif data.include?(xerox) and > data.include?(printer) > puts printer + "\t" + ip > else > puts "website\t" + ip > end > end > end > # Don't really care about exceptions just time outs mostly. > rescue Timeout::Error > puts "Timeout\t" + ip > rescue Exception > puts "General Exception\t" + ip > end > end > > -- > Posted via http://www.ruby-forum.com/. > > Looks like you're trying to perform a network client operation simultaneously across a lot of different servers. For a non-threaded approach, look at the EventMachine library. Sync to the latest source and look at EventMachine::Deferrable. That should give you considerably more scalability and performance than trying to solve this with threads. The Deferrable pattern works like Python's Twisted. If it doesn't make sense to you, let me know and I can send you some sample code. ------=_Part_26262_17084025.1161867510266--