Created
December 7, 2009 23:54
-
-
Save tenderlove/251244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Net::HTTP::BufferedIO < Net::BufferedIO | |
@@patch = false | |
def self.patch= v; @@patch = v; end | |
def rbuf_fill | |
return super unless @@patch | |
begin | |
@rbuf << @io.read_nonblock(BUFSIZE) | |
rescue Errno::EWOULDBLOCK, Errno::EAGAIN | |
retry unless @read_timeout | |
if IO.select([@io], nil, nil, @read_timeout) | |
retry | |
else | |
raise Timeout::Error, 'IO timeout' | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'benchmark' | |
require 'io_select_http' | |
S = '/~apatterson/small.html' # => 150B | |
M = '/~apatterson/medium.html' # => 71K | |
L = '/~apatterson/large.html' # => 82M | |
GC.disable | |
n = 5000 | |
m = 500 | |
Benchmark.bm(14) do |x| | |
small_uri = URI.parse("http://localhost/#{S}") | |
medium_uri = URI.parse("http://localhost/#{M}") | |
large_uri = URI.parse("http://localhost/#{L}") | |
#x.report('small') do | |
# n.times do | |
# Net::HTTP.get(small_uri) | |
# end | |
#end | |
#x.report('small patched') do | |
# Net::HTTP::BufferedIO.patch = true | |
# n.times do | |
# Net::HTTP.get(small_uri) | |
# end | |
# Net::HTTP::BufferedIO.patch = false | |
#end | |
x.report('medium') do | |
m.times do | |
Net::HTTP.get(medium_uri) | |
end | |
end | |
x.report('medium patched') do | |
Net::HTTP::BufferedIO.patch = true | |
m.times do | |
Net::HTTP.get(medium_uri) | |
end | |
Net::HTTP::BufferedIO.patch = false | |
end | |
#x.report('large') do | |
# Net::HTTP.get(large_uri) | |
#end | |
#x.report('large patched') do | |
# Net::HTTP::BufferedIO.patch = true | |
# Net::HTTP.get(large_uri) | |
# Net::HTTP::BufferedIO.patch = false | |
#end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment