forked from nahi/httpclient
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bm_common.rb
49 lines (45 loc) · 1.16 KB
/
bm_common.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'benchmark'
require 'uri'
require 'fileutils'
def try_require(target)
begin
require target
rescue LoadError
warn("#{target} not loaded")
end
end
try_require 'httpclient'
require 'net/http'
# following Net code block is not copirighed by me.
# see: http://7fff.com/2008/12/20/faster-nethttp-for-ruby-186
module Net
class BufferedIO
alias rbuf_fill_replaced_by_bm rbuf_fill
BUFSIZE = 1024 * 16
def rbuf_fill
# 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 [email protected]_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
end
require 'open-uri'
try_require 'rfuzz/session'
try_require 'eventmachine'
try_require 'curb'
try_require 'httparty'