[Mongrel] speed curiosity

Roger Pack lists at ruby-forum.com
Mon Sep 1 13:08:20 EDT 2008

>>        out.write("hello!\n"*10_000)
> AFAIK that's not the fastest of operations.

String creation itself turns out to not take too long:
>> Benchmark.measure { "hello!\n"*10_000}
=> #<Benchmark... @real=0.000353097915649414, @utime=0.0, @cstime=0.0>

So it's not a huge bottleneck.  Replacing it with a static string yields 
approx. the same results, which I did thanks to your suggestion.

>> latency to http_response.rb line 137
>> yielded ~938 req/s [AFAICT]
> Thin and ebb both write more like this.

Here's some results [ruby 1.8.6p287 OS X] running ab -n 300

7B response: old: 1595 req/s new: 1690 req/s (thin: 1901)
7K response: old: 1168 req/s new: 1559 req/s  (thin: 1849)
70K response: old: 366 req/s new: 1140 req/s (thin: 1160)
700K response: old: 46 req/s new: 286 [or 48] req/s (thin: 295)*

So overall better results, but most noticeable at the 70K level.  It 
seems roughly on par with thin.
IO#write is [I think] ruby thread friendly, so I'm not sure why the 


* or 48: With some mongrel tests it would have a single long, out of 
300, that would take 4s while the others all took 20ms.  Not sure why. 
Excluding that, it ran at the 286

Index: lib/mongrel/http_response.rb
--- lib/mongrel/http_response.rb  (revision 1036)
+++ lib/mongrel/http_response.rb  (working copy)
@@ -137,7 +137,15 @@

     def write(data)
-      @socket.write(data)
+      while data and data.length > 0
+  begin
+    amount_wrote = @socket.write_nonblock(data)
+          data = data[amount_wrote..-1]
+  rescue Errno::EAGAIN
+    # wait for it to become writable again
+    select nil, [@socket], nil, nil
+  end
+      end
     rescue => details
Posted via http://www.ruby-forum.com/.

More information about the Mongrel-users mailing list