我正在使用Dashing-rails(使用Rufus-scheduler)向浏览器小部件发送更新。
在浏览器对页面发出5次单独请求后,网站崩溃的原因是:“ActiveRecord :: ConnectionTimeoutError”。
我的假设是每个浏览器请求触发创建一个rufus-scheduler线程。该线程发送更新,线程保持ActiveRecord连接而不让它继续,最终导致超时。
但是,我尝试确保计划释放与ActiveRecord池的连接无济于事。
Dashing.scheduler.every '10s', :allow_overlapping => false do
ActiveRecord::Base.connection_pool.with_connection do
Dashing.send_event('past_hour', { value: Device.sightings_past_hour })
d = Device.where("company != ''").last
company = d.company !="" ? d.company : "Device Manufacturer Not Found"
Dashing.send_event('last_MAC', { text: "#{company}",
moreinfo: "MAC Address: #{d.macaddress}"})
Dashing.send_event('macaddresses', { current: Device.total_Count })
top_manufacturers=Device.manufacturers_dashboard
Dashing.send_event('manufacturers', {items: top_manufacturers})
Dashing.send_event('past_day', { current: Device.sightings_past_day })
end
ActiveRecord::Base.connection_pool.release_connection
end
有没有办法查看每个线程上正在运行的进程/持有ActiveRecord连接的内容?或者如果这是问题,阻止Dashing-rails保持ActiveRecord连接?
答案 0 :(得分:2)
问题与Rails 4直播相关。 https://github.com/rails/rails/issues/10989
特别是Rails 4中的实时流线程没有关闭。