From: Marcelo Date: 2008-03-27T11:55:10+09:00 Subject: Re: "loop do IO.select([io], nil, nil)" eats 95% of CPU, any other way? On Wed, Mar 26, 2008 at 10:34 AM, IƱaki Baz Castillo wrote: > -------------- > class MyServer < GServer > def serve(io) > loop do > if IO.select([io], nil, nil) > .... > -------------- > > A "top" says to me that Ruby is eating more than 90% of CPU and there > is no connections yet... :( > Any other suggestion? I don't know what GServer is, but I guess that serve is called when there's a connection. As John points out, if io.eof? is true, select will return immediately. For example: #!/usr/bin/env ruby loop do open("fifo") do |f| puts "Opened fifo" loop do ready, = select([f], nil, nil, nil).first break if ready.nil? p ready.read(1000) break if ready.eof? end end puts "Closed fifo" end You'll see that it opens the fifo, blocks on it, once you write to it select returns, and once you reach EOF the inner loop breaks and the fifo is closed. You can do something like: $ ruby -e 'puts "x"*2000' > fifo and you'll see the inner loop consuming all the input. If you remove: break if ready.eof? you'll see the behaviour you describe. Short answer: are you sure serve is called only if there's a connection? Marcelo