1 # frozen_string_literal: false
2 # This app is intended to test large HTTP responses with or without
3 # a fully-buffering reverse proxy such as nginx. Without a fully-buffering
4 # reverse proxy, unicorn will be unresponsive when client count exceeds
7 # To demonstrate how bad unicorn is at slowly reading clients:
9 # # in one terminal, start unicorn with one worker:
10 # unicorn -E none -l 127.0.0.1:8080 test/benchmark/ddstream.ru
12 # # in a different terminal, start more slow curl processes than
13 # # unicorn workers and watch time outputs
14 # curl --limit-rate 8K --trace-time -vsN http://127.0.0.1:8080/ >/dev/null &
15 # curl --limit-rate 8K --trace-time -vsN http://127.0.0.1:8080/ >/dev/null &
18 # The last client won't see a response until the first one is done reading
20 # nginx note: do not change the default "proxy_buffering" behavior.
21 # Setting "proxy_buffering off" prevents nginx from protecting unicorn.
23 # totally standalone rack app to stream a giant response
25 def initialize(bs, count)
26 @buf = "#{bs.to_s(16)}\r\n#{' ' * bs}\r\n"
29 { 'Transfer-Encoding' => -'chunked', 'Content-Type' => 'text/plain' },
34 # rack response body iterator
36 (1..@count).each { yield @buf }
40 # rack app entry endpoint
46 # default to a giant (128M) response because kernel socket buffers
47 # can be ridiculously large on some systems
48 bs = ENV['bs'] ? ENV['bs'].to_i : 65536
49 count = ENV['count'] ? ENV['count'].to_i : 2048
50 warn "serving response with bs=#{bs} count=#{count} (#{bs*count} bytes)"
51 run BigResponse.new(bs, count)