about summary refs log tree commit homepage
path: root/lib/rainbows/event_machine
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2011-01-17 03:42:33 +0000
committerEric Wong <normalperson@yhbt.net>2011-01-17 08:42:56 +0000
commit810701d939114a5fcdacc55ec383de112c5e3fa4 (patch)
treeb2e44c0cde116366b2aee309b791f4d270b69637 /lib/rainbows/event_machine
parentc7f4ade8edcfa7422d41c4272250b292b141b427 (diff)
downloadrainbows-810701d939114a5fcdacc55ec383de112c5e3fa4.tar.gz
Single-threaded concurrency models can reuse a single
buffer to avoid thrashing memory and causing unnecessary
GC activity.
Diffstat (limited to 'lib/rainbows/event_machine')
-rw-r--r--lib/rainbows/event_machine/response_chunk_pipe.rb2
-rw-r--r--lib/rainbows/event_machine/response_pipe.rb4
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/rainbows/event_machine/response_chunk_pipe.rb b/lib/rainbows/event_machine/response_chunk_pipe.rb
index 5caf250..af9393a 100644
--- a/lib/rainbows/event_machine/response_chunk_pipe.rb
+++ b/lib/rainbows/event_machine/response_chunk_pipe.rb
@@ -10,7 +10,7 @@ module Rainbows::EventMachine::ResponseChunkPipe
 
   def notify_readable
     begin
-      data = @io.read_nonblock(16384, BUF)
+      data = @io.read_nonblock(16384, RBUF)
       @client.write("#{data.size.to_s(16)}\r\n")
       @client.write(data)
       @client.write("\r\n")
diff --git a/lib/rainbows/event_machine/response_pipe.rb b/lib/rainbows/event_machine/response_pipe.rb
index 3b584c7..0ea1eae 100644
--- a/lib/rainbows/event_machine/response_pipe.rb
+++ b/lib/rainbows/event_machine/response_pipe.rb
@@ -3,7 +3,7 @@
 module Rainbows::EventMachine::ResponsePipe
   # garbage avoidance, EM always uses this in a single thread,
   # so a single buffer for all clients will work safely
-  BUF = ''
+  RBUF = Rainbows::EvCore::RBUF
 
   def initialize(client)
     @client = client
@@ -11,7 +11,7 @@ module Rainbows::EventMachine::ResponsePipe
 
   def notify_readable
     begin
-      @client.write(@io.read_nonblock(16384, BUF))
+      @client.write(@io.read_nonblock(16384, RBUF))
     rescue Errno::EINTR
     rescue Errno::EAGAIN
       return