From 2bc6e7a3c4e972ee3227d931e79bc4057ba278ca Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 24 Nov 2009 22:52:35 -0800 Subject: Rev*: safer client accounting Due to the addition of keepalive_timeouts, it's safer to pay a performance penalty and use a hash here instead. --- lib/rainbows/rev.rb | 3 +++ lib/rainbows/rev/client.rb | 4 ++-- lib/rainbows/rev/core.rb | 2 +- lib/rainbows/rev/heartbeat.rb | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/rainbows/rev.rb b/lib/rainbows/rev.rb index eed14f5..197d138 100644 --- a/lib/rainbows/rev.rb +++ b/lib/rainbows/rev.rb @@ -28,6 +28,9 @@ module Rainbows # keep-alive timeout scoreboard KATO = {} + # all connected clients + CONN = {} + include Core end end diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb index f7a9750..af56889 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/rev/client.rb @@ -8,7 +8,7 @@ module Rainbows G = Rainbows::G def initialize(io) - G.cur += 1 + CONN[self] = false super(io) post_init @deferred_bodies = [] # for (fast) regular files only @@ -71,7 +71,7 @@ module Rainbows end def on_close - G.cur -= 1 + CONN.delete(self) end end # module Client diff --git a/lib/rainbows/rev/core.rb b/lib/rainbows/rev/core.rb index 0460137..472182a 100644 --- a/lib/rainbows/rev/core.rb +++ b/lib/rainbows/rev/core.rb @@ -11,7 +11,7 @@ module Rainbows # CL and MAX will be defined in the corresponding worker loop def on_readable - return if G.cur >= MAX + return if CONN.size >= MAX begin CL.new(@_io.accept_nonblock).attach(LOOP) rescue Errno::EAGAIN, Errno::ECONNABORTED diff --git a/lib/rainbows/rev/heartbeat.rb b/lib/rainbows/rev/heartbeat.rb index ee9d1b5..54cc056 100644 --- a/lib/rainbows/rev/heartbeat.rb +++ b/lib/rainbows/rev/heartbeat.rb @@ -14,7 +14,7 @@ module Rainbows ot = Time.now - ot KATO.delete_if { |client, time| time < ot and client.timeout? } end - exit if (! G.tick && G.cur <= 0) + exit if (! G.tick && CONN.size <= 0) end end -- cgit v1.2.3-24-ge0c7