about summary refs log tree commit homepage
path: root/lib/rainbows
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-18 00:08:52 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-18 00:08:52 -0800
commit77f930cb64d32b3fac942b462cf4c7a04af730e3 (patch)
tree6612d92c7d3681f0701969db5060afd6c65c62e0 /lib/rainbows
parent02245b9ea8a407ac67a9633119140fa2fd2c561e (diff)
downloadrainbows-77f930cb64d32b3fac942b462cf4c7a04af730e3.tar.gz
And change the default to 2 seconds, most clients can
render the page and load all URLs within 2 seconds.
Diffstat (limited to 'lib/rainbows')
-rw-r--r--lib/rainbows/base.rb2
-rw-r--r--lib/rainbows/event_machine.rb2
-rw-r--r--lib/rainbows/http_server.rb5
-rw-r--r--lib/rainbows/rev/heartbeat.rb6
-rw-r--r--lib/rainbows/revactor.rb3
5 files changed, 13 insertions, 5 deletions
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