tee_input: make interface more usable outside of Unicorn
[unicorn.git] / test / benchmark / big_request.rb
bloba250c624d98fac568c8b108ffb347f65fcaca43e
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))
29 unless request.respond_to?(:reset)
30   def request.reset
31     # no-op
32   end
33 end
35 Benchmark.bmbm do |x|
36   x.report("big") do
37     for i in 1..nr
38       request.read(big)
39       request.reset
40       big.sysseek(0)
41     end
42   end
43 end