Friday, June 22, 2007

Increasing Ruby's Net::BufferedIO buffer size

Reading bytes from Net::HTTP seems really slow, around 1Mb/s for a close host. Not many people seem to have complained about this, but I found some insight from Headius and monkey-patched Net::BufferedIO::rbuf_fill. Changing the read buffer size from 1k to 32k brought the throughput up to 24Mb/s.


module Net
class BufferedIO
def rbuf_fill
timeout(@read_timeout) { @rbuf << @io.sysread(32768) }
end
end
end

Labels:

1 Comments:

Blogger demi said...

This is awesome. Just what I needed. Thanks!

3:39 PM  

Post a Comment

Links to this post:

Create a Link

<< Home