From 728496a31f34234b46d7025a23933aa06dd824f5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 27 Dec 2010 13:10:57 -0800 Subject: coolio_fiber_spawn: decrease CPU usage for keepalive Blindly resuming fibers every second is a waste of cycles, we can use the ZZ hash in regular FiberSpawn to resume expired fibers on an as-needed basis. While we're at it, merge the keepalive-timeout class into the heartbeat, there's no reason to have separate timers and classes here. --- lib/rainbows/fiber/rev/heartbeat.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/rainbows/fiber/rev/heartbeat.rb') diff --git a/lib/rainbows/fiber/rev/heartbeat.rb b/lib/rainbows/fiber/rev/heartbeat.rb index 9411b4a..f9ef573 100644 --- a/lib/rainbows/fiber/rev/heartbeat.rb +++ b/lib/rainbows/fiber/rev/heartbeat.rb @@ -2,7 +2,14 @@ # :enddoc: class Rainbows::Fiber::Rev::Heartbeat < Rev::TimerWatcher G = Rainbows::G + + # ZZ gets populated by read_expire in rainbows/fiber/io/methods + ZZ = Rainbows::Fiber::ZZ def on_timer exit if (! G.tick && G.cur <= 0) + now = Time.now + fibs = [] + ZZ.delete_if { |fib, time| now >= time ? fibs << fib : ! fib.alive? } + fibs.each { |fib| fib.resume if fib.alive? } end end -- cgit v1.2.3-24-ge0c7