In article <44B9A127.3020801 / nixe.ping.de>,
  "Florian Frank" <flori / nixe.ping.de> writes:

> I think you're right. In the GET case (for both open-uri and net/http) I 
> have found a possibility to speed up the download. The method 
> BufferedIO#rbuf_fill in net/protocol.rb uses a fixed buffer size of 
> 1024. I changed this to 8192:
>
>     def rbuf_fill
>       timeout(@read_timeout) {
>         @rbuf << @io.sysread(8192)
>       }
>     end

I guess the timeout() is slow.

Try:

    def rbuf_fill
      @rbuf << @io.sysread(1024)
    end

However, the above is not acceptable in general since
timeout is a feature.

It is possible to implement timeout without timeout() as:

    def rbuf_fill
      begin
        @rbuf << @io.read_nonblock(4096)
      rescue Errno::EWOULDBLOCK
        if IO.select([@io], nil, nil, @read_timeout)
          @rbuf << @io.read_nonblock(4096)
        else
          raise Timeout::TimeoutError
        end
      end
    end
-- 
Tanaka Akira