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
| | require 'benchmark'
require 'tempfile'
require 'unicorn'
nr = ENV['nr'] ? ENV['nr'].to_i : 100
bs = ENV['bs'] ? ENV['bs'].to_i : (1024 * 1024)
count = ENV['count'] ? ENV['count'].to_i : 4
length = bs * count
slice = (' ' * bs).freeze
big = Tempfile.new('')
def big.unicorn_peeraddr # old versions of Unicorn used this
'127.0.0.1'
end
big.syswrite(
"PUT /hello/world/puturl?abcd=efg&hi#anchor HTTP/1.0\r\n" \
"Host: localhost\r\n" \
"Accept: */*\r\n" \
"Content-Length: #{length}\r\n" \
"User-Agent: test-user-agent 0.1.0 (Mozilla compatible) 5.0 asdfadfasda\r\n" \
"\r\n")
count.times { big.syswrite(slice) }
big.sysseek(0)
big.fsync
include Unicorn
request = HttpRequest.new(Logger.new($stderr))
unless request.respond_to?(:reset)
def request.reset
# no-op
end
end
Benchmark.bmbm do |x|
x.report("big") do
for i in 1..nr
request.read(big)
request.reset
big.sysseek(0)
end
end
end
|