From b3278b45bd5e31d97ce7b8625585692091ff4755 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 19 Jul 2010 10:09:54 +0000 Subject: event_machine: garbage avoidance for pipe responses Since the EM loop runs entirely in one thread, we can get away with using a single buffer across all pipe/socket responses. --- lib/rainbows/event_machine.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 4d5156e..3837e1f 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -158,13 +158,17 @@ module Rainbows end module ResponsePipe # :nodoc: all + # garbage avoidance, EM always uses this in a single thread, + # so a single buffer for all clients will work safely + BUF = '' + def initialize(client) @client = client end def notify_readable begin - @client.write(@io.read_nonblock(16384)) + @client.write(@io.read_nonblock(16384, BUF)) rescue Errno::EINTR retry rescue Errno::EAGAIN @@ -192,7 +196,7 @@ module Rainbows def notify_readable begin data = begin - @io.read_nonblock(16384) + @io.read_nonblock(16384, BUF) rescue Errno::EINTR retry rescue Errno::EAGAIN -- cgit v1.2.3-24-ge0c7