From fb24ca8f30edbf5086dbe288d4dd4fa213684236 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 21 Jan 2011 15:11:16 -0800 Subject: epoll: reduce expiration calls and Time objects We'll lower our precision for keepalive timeouts a little and and reduce our Time object allocation rate. --- lib/rainbows/epoll/client.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb index ba9d576..f4e49dc 100644 --- a/lib/rainbows/epoll/client.rb +++ b/lib/rainbows/epoll/client.rb @@ -13,12 +13,15 @@ module Rainbows::Epoll::Client KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity) KEEPALIVE_TIMEOUT = Rainbows.keepalive_timeout EP = Rainbows::Epoll::EP + @@last_expire = Time.now def self.expire + return if ((now = Time.now) - @@last_expire) < 1.0 if (ot = KEEPALIVE_TIMEOUT) >= 0 - ot = Time.now - ot + ot = now - ot KATO.delete_if { |client, time| time < ot and client.timeout! } end + @@last_expire = now end # only call this once @@ -36,7 +39,7 @@ module Rainbows::Epoll::Client on_read(rv) return if @wr_queue[0] || closed? when :wait_readable - KATO[self] = Time.now if :headers == @state + KATO[self] = @@last_expire if :headers == @state return EP.set(self, IN) else break -- cgit v1.2.3-24-ge0c7