From 40c22b3f0a2ace6e4b51a39624ac5ed5ee3d0162 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 27 Dec 2010 03:56:30 +0000 Subject: fiber/*: more efficient keepalive_timeout expiry We can use the same interface as Rainbows::Fiber.sleep to avoid blindly waking up readers at ever scheduler invocation. --- lib/rainbows/fiber/base.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib/rainbows/fiber/base.rb') diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb index ccfda96..b693451 100644 --- a/lib/rainbows/fiber/base.rb +++ b/lib/rainbows/fiber/base.rb @@ -18,11 +18,10 @@ module Rainbows::Fiber::Base # for one second (returned by the schedule_sleepers method) which # will cause it. def schedule(&block) - ret = begin + begin G.tick - RD.compact.each { |c| c.f.resume } # attempt to time out idle clients t = schedule_sleepers - select(RD.compact.concat(LISTENERS), WR.compact, nil, t) or return + ret = select(RD.compact.concat(LISTENERS), WR.compact, nil, t) rescue Errno::EINTR retry rescue Errno::EBADF, TypeError @@ -30,15 +29,15 @@ module Rainbows::Fiber::Base raise end or return - # active writers first, then _all_ readers for keepalive timeout - ret[1].concat(RD.compact).each { |c| c.f.resume } + # active writers first, then readers + ret[1].concat(RD.compact & ret[0]).each { |c| c.f.resume } # accept is an expensive syscall, filter out listeners we don't want (ret[0] & LISTENERS).each(&block) end - # wakes up any sleepers that need to be woken and - # returns an interval to IO.select on + # wakes up any sleepers or keepalive-timeout violators that need to be + # woken and returns an interval to IO.select on def schedule_sleepers max = nil now = Time.now -- cgit v1.2.3-24-ge0c7