From 77f930cb64d32b3fac942b462cf4c7a04af730e3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 18 Nov 2009 00:08:52 -0800 Subject: make keepalive_timeout configurable And change the default to 2 seconds, most clients can render the page and load all URLs within 2 seconds. --- lib/rainbows/base.rb | 2 +- lib/rainbows/event_machine.rb | 2 +- lib/rainbows/http_server.rb | 5 +++++ lib/rainbows/rev/heartbeat.rb | 6 ++++-- lib/rainbows/revactor.rb | 3 ++- 5 files changed, 13 insertions(+), 5 deletions(-) (limited to 'lib/rainbows') diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb index 62a7701..9a653ff 100644 --- a/lib/rainbows/base.rb +++ b/lib/rainbows/base.rb @@ -40,7 +40,7 @@ module Rainbows begin # loop while ! hp.headers(env, buf) - IO.select([client], nil, nil, 5) or return client.close + IO.select([client], nil, nil, G.kato) or return client.close buf << client.readpartial(CHUNK_SIZE) end diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 056bdd5..54c1bc0 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -74,7 +74,7 @@ module Rainbows @state = :headers # keepalive requests are always body-less, so @input is unchanged @hp.headers(@env, @buf) and next - set_comm_inactivity_timeout 5 + set_comm_inactivity_timeout G.kato end return end while true diff --git a/lib/rainbows/http_server.rb b/lib/rainbows/http_server.rb index c26285c..da97929 100644 --- a/lib/rainbows/http_server.rb +++ b/lib/rainbows/http_server.rb @@ -68,6 +68,11 @@ module Rainbows @worker_connections = nr end + def keepalive_timeout(nr) + (Integer === nr && nr >= 0) or + raise ArgumentError, "keepalive must be a non-negative Integer" + G.kato = nr + end end end diff --git a/lib/rainbows/rev/heartbeat.rb b/lib/rainbows/rev/heartbeat.rb index 5f76ed7..ee9d1b5 100644 --- a/lib/rainbows/rev/heartbeat.rb +++ b/lib/rainbows/rev/heartbeat.rb @@ -10,8 +10,10 @@ module Rainbows class Heartbeat < ::Rev::TimerWatcher def on_timer - ot = Time.now - 5 - KATO.delete_if { |client, time| time < ot and client.timeout? } + if (ot = G.kato) > 0 + ot = Time.now - ot + KATO.delete_if { |client, time| time < ot and client.timeout? } + end exit if (! G.tick && G.cur <= 0) end diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index 4cf6f11..489236c 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -23,7 +23,7 @@ module Rainbows module Revactor require 'rainbows/revactor/tee_input' - RD_ARGS = { :timeout => 5 } + RD_ARGS = {} include Base @@ -75,6 +75,7 @@ module Rainbows # given a INT, QUIT, or TERM signal) def worker_loop(worker) init_worker_process(worker) + RD_ARGS[:timeout] = G.kato if G.kato > 0 root = Actor.current root.trap_exit = true -- cgit v1.2.3-24-ge0c7