Faster Net::HTTP for Ruby 1.8.6 by jgn on Saturday, December 20, 2008 in Rails and Ruby

We've been a bit frustrated at work with Net::HTTP performance ( as have so many others) so here's a monkeypatch for 1.8.6 that combines the buffer size increase in 1.8.7 with Aaron Patterson's recent tweak to use non-blocking IO (unfortunately, the non-blocking IO patch doesn't work with HTTPS, which is why we use the buffer size tweak when the @io variable suggests that HTTPS is happening. No guarantee implied, etc.

[source language='ruby'] class Net::BufferedIO #:nodoc:

alias :old_rbuf_fill :rbuf_fill

def rbuf_fill

BUFSIZE = 1024 * 16

# HTTPS can't use the non-blocking strategy below in 1.8.6; so at least # increase buffer size over 1.8.6 default of 1024 if !@io.respond_to? :read_nonblock timeout(@read_timeout) { @rbuf

comments powered by Disqus