From 07e5a1d7e8624e57d640af1d641c7ca51a948ecd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 7 Nov 2013 08:40:22 +0000 Subject: fdmap: simplify IO expiry interface The first argument of the old __expire_for method was completely unused in all but one invocation of it, so it is not worth it. This also simplifies the code a bit too. --- lib/yahns/acceptor.rb | 2 +- lib/yahns/fdmap.rb | 16 +++++++--------- lib/yahns/server.rb | 2 +- lib/yahns/stream_file.rb | 2 +- lib/yahns/tmpio.rb | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/yahns/acceptor.rb b/lib/yahns/acceptor.rb index c61975a..cd9e055 100644 --- a/lib/yahns/acceptor.rb +++ b/lib/yahns/acceptor.rb @@ -56,7 +56,7 @@ module Yahns::Acceptor # :nodoc: end rescue Errno::EMFILE, Errno::ENFILE => e logger.error("#{e.message}, consider raising open file limits") - queue.fdmap.desperate_expire_for(nil, 5) + queue.fdmap.desperate_expire(5) sleep 1 # let other threads do some work rescue => e Yahns::Log.exception(logger, "accept loop", e) diff --git a/lib/yahns/fdmap.rb b/lib/yahns/fdmap.rb index 97e9f44..a9125e7 100644 --- a/lib/yahns/fdmap.rb +++ b/lib/yahns/fdmap.rb @@ -31,11 +31,11 @@ class Yahns::Fdmap # :nodoc: # Yes, we call IO#close inside the lock(!) # - # We don't want to race with __expire_for. Theoretically, a Ruby + # We don't want to race with __expire. Theoretically, a Ruby # implementation w/o GVL may end up issuing shutdown(2) on the same fd # as one which got accept-ed (a brand new IO object) so we must prevent # IO#close in worker threads from racing with any threads which may run - # __expire_for + # __expire def sync_close(io) @fdmap_mtx.synchronize do @count -= 1 @@ -48,17 +48,16 @@ class Yahns::Fdmap # :nodoc: fd = io.fileno @fdmap_mtx.synchronize do if (@count += 1) > @client_expire_threshold - __expire_for(io) - else - @fdmap_ary[fd] = io + __expire(nil) end + @fdmap_ary[fd] = io end end # this is only called in Errno::EMFILE/Errno::ENFILE situations # and graceful shutdown - def desperate_expire_for(io, timeout) - @fdmap_mtx.synchronize { __expire_for(io, timeout) } + def desperate_expire(timeout) + @fdmap_mtx.synchronize { __expire(timeout) } end # only called on hijack @@ -74,7 +73,7 @@ class Yahns::Fdmap # :nodoc: # expire a bunch of idle clients and register the current one # We should not be calling this too frequently, it is expensive # This is called while @fdmap_mtx is held - def __expire_for(io, timeout = nil) + def __expire(timeout) nr = 0 now = Time.now.to_f (now - @last_expire) >= 1.0 or return # don't expire too frequently @@ -88,7 +87,6 @@ class Yahns::Fdmap # :nodoc: nr += c.yahns_expire(tout) end - @fdmap_ary[io.fileno] = io if io @last_expire = Time.now.to_f msg = timeout ? "timeout=#{timeout}" : "client_timeout" @logger.info("dropping #{nr} of #@count clients for #{msg}") diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb index e2d03e2..f956d50 100644 --- a/lib/yahns/server.rb +++ b/lib/yahns/server.rb @@ -459,7 +459,7 @@ class Yahns::Server # :nodoc: def dropping(fdmap) if drop_acceptors[0] || fdmap.size > 0 timeout = @shutdown_expire < Time.now ? -1 : @shutdown_timeout - fdmap.desperate_expire_for(nil, timeout) + fdmap.desperate_expire(timeout) true else false diff --git a/lib/yahns/stream_file.rb b/lib/yahns/stream_file.rb index 03dab45..bcca0d6 100644 --- a/lib/yahns/stream_file.rb +++ b/lib/yahns/stream_file.rb @@ -24,7 +24,7 @@ class Yahns::StreamFile # :nodoc: rescue Errno::EMFILE, Errno::ENFILE raise if retried retried = true - Thread.current[:yahns_fdmap].desperate_expire_for(nil, 5) + Thread.current[:yahns_fdmap].desperate_expire(5) sleep(1) retry end diff --git a/lib/yahns/tmpio.rb b/lib/yahns/tmpio.rb index bcf6b8a..19da658 100644 --- a/lib/yahns/tmpio.rb +++ b/lib/yahns/tmpio.rb @@ -20,7 +20,7 @@ class Yahns::TmpIO < File # :nodoc: rescue Errno::EMFILE, Errno::ENFILE raise if retried retried = true - Thread.current[:yahns_fdmap].desperate_expire_for(nil, 5) + Thread.current[:yahns_fdmap].desperate_expire(5) sleep(1) retry end -- cgit v1.2.3-24-ge0c7