ruby-changes:39153
From: nobu <ko1@a...>
Date: Tue, 14 Jul 2015 11:21:59 +0900 (JST)
Subject: [ruby-changes:39153] nobu:r51234 (trunk): webrick/utils.rb: adaptive sleep
nobu 2015-07-14 11:21:53 +0900 (Tue, 14 Jul 2015) New Revision: 51234 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51234 Log: webrick/utils.rb: adaptive sleep * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#initialize): make sleep intervals adaptive than fixed period intervals. Modified files: trunk/ChangeLog trunk/lib/webrick/utils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 51233) +++ ChangeLog (revision 51234) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Tue Jul 14 11:20:13 2015 Nobuyoshi Nakada <nobu@r...> +Tue Jul 14 11:21:31 2015 Nobuyoshi Nakada <nobu@r...> + + * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#initialize): + make sleep intervals adaptive than fixed period intervals. * lib/webrick/server.rb (WEBrick::GenericServer#start): flush shutdown pipe. Index: lib/webrick/utils.rb =================================================================== --- lib/webrick/utils.rb (revision 51233) +++ lib/webrick/utils.rb (revision 51234) @@ -156,15 +156,23 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L156 Thread.start{ while true now = Time.now - @timeout_info.keys.each{|thread| - ary = @timeout_info[thread] + wakeup = nil + @timeout_info.each {|thread, ary| next unless ary ary.dup.each{|info| time, exception = *info - interrupt(thread, info.object_id, exception) if time < now + if time < now + interrupt(thread, info.object_id, exception) + elsif !wakeup || time < wakeup + wakeup = time + end } } - sleep 0.5 + if !wakeup + sleep + elsif (wakeup -= now) > 0 + sleep(wakeup) + end end } end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/