Roger,
Using write_nonblock is an absolutely great suggestion; the only real
issue with write_nonblock is that it doesn't work in all environments.
While Ruby is supposed to fall back on blocking IO when async is
unavailable in the underlying system the reality is sketchy at best.
Through in Ruby implementations like Ruby and you end up with code
that seemingly arbitrarily breaks. I'm all for write_nonblock however
if this route is pursued then there has to be a whole chain of
capability and environment detection around this chunk not a simple
rescue (yes I have done this before).
So, +1 from me as long as we modify as I suggested.
~Wayne
On Sep 1, 2008, at 13:08 , Roger Pack wrote:
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
difference.
Thanks!
-=R
* 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
patch:
Index: lib/mongrel/http_response.rb
===================================================================
--- lib/mongrel/http_response.rb (revision 1036)
+++ lib/mongrel/http_response.rb (working copy)
@@ -137,7 +137,15 @@
end
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, [EMAIL PROTECTED], nil, nil
+ end
+ end
rescue => details
socket_error(details)
end
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Mongrel-users mailing list
Mongrel-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-users
_______________________________________________
Mongrel-users mailing list
Mongrel-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-users