benchmark/*: updates for newer versions of Unicorn
[unicorn.git] / test / benchmark / big_request.rb
blobee42d412f2e31521f7ad7f5ded5eff32dabc3b1a
1 require 'benchmark'
2 require 'tempfile'
3 require 'unicorn'
4 nr = ENV['nr'] ? ENV['nr'].to_i : 100
5 bs = ENV['bs'] ? ENV['bs'].to_i : (1024 * 1024)
6 count = ENV['count'] ? ENV['count'].to_i : 4
7 length = bs * count
8 slice = (' ' * bs).freeze
10 big = Tempfile.new('')
12 def big.unicorn_peeraddr # old versions of Unicorn used this
13   '127.0.0.1'
14 end
16 big.syswrite(
17 "PUT /hello/world/puturl?abcd=efg&hi#anchor HTTP/1.0\r\n" \
18 "Host: localhost\r\n" \
19 "Accept: */*\r\n" \
20 "Content-Length: #{length}\r\n" \
21 "User-Agent: test-user-agent 0.1.0 (Mozilla compatible) 5.0 asdfadfasda\r\n" \
22 "\r\n")
23 count.times { big.syswrite(slice) }
24 big.sysseek(0)
25 big.fsync
27 include Unicorn
28 request = HttpRequest.new(Logger.new($stderr))
30 Benchmark.bmbm do |x|
31   x.report("big") do
32     for i in 1..nr
33       request.read(big)
34       request.reset
35       big.sysseek(0)
36     end
37   end
38 end