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:

Thursday, June 14, 2007

Documenting code