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.
class Net::BufferedIO #:nodoc: aliasld_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 << @io.sysread(BUFSIZE) } return end # non-blocking begin @rbuf << @io.read_nonblock(BUFSIZE) rescue Errno::EWOULDBLOCK if IO.select([@io], nil, nil, @read_timeout) @rbuf << @io.read_nonblock(BUFSIZE) else raise Timeout::TimeoutError end end end end
