ruby-amqp / bunny

Bunny is a popular, easy to use, mature Ruby client for RabbitMQ
Other
1.39k stars 305 forks source link

High CPU load after 600 seconds #163

Closed bernd closed 11 years ago

bernd commented 11 years ago

Running the following code with Bunny 1.0.0.rc3, JRuby 1.7.6 and RabbitMQ 3.2.0 on Ubuntu 12.04 shows a high CPU usage after 600 seconds.

require 'bunny'

START = Time.now

conn = Bunny.new
conn.start

ch = conn.create_channel
ex = ch.fanout('amq.fanout', durable: true)

def uptime
  Time.now.to_i - START.to_i
end

def utime
  File.read("/proc/#{$$}/stat").split[13] rescue '-'
end

loop do
  puts "pid #{$$} | uptime #{uptime}s | utime #{utime}"
  sleep 5
end

See also: https://gist.github.com/bernd/97e2f32ecd2f7c127e07

The program just connects to the RabbitMQ broker, opens a channel and declares an exchange. After around 600 seconds the top shows a CPU usage of 100%.

VisualVM shows that the Ruby thread ../lib/bunny/reader_loop.rb:21 eats the CPU.

I guess this has something to do with the default heartbeat of 600?

michaelklishin commented 11 years ago

Duplicate of #127 and #114. This needs to be fixed in JRuby. Use March Hare if you want to use JRuby.

michaelklishin commented 11 years ago

It has nothing to do with heartbeats. IO.select in a loop on JRuby uses an abnormally high amount of CPU.

bernd commented 11 years ago

Yikes, sorry for the noise. :(