port test/unit/test_ccc.rb to Perl 5
[unicorn.git] / test / benchmark / readinput.ru
blob95c02261572a79e825a484ba867d4898adb192bb
1 # frozen_string_literal: false
2 # This app is intended to test large HTTP requests 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
5 # worker_processes.
7 DOC = <<DOC
8 To demonstrate how bad unicorn is at slowly uploading clients:
10   # in one terminal, start unicorn with one worker:
11   unicorn -E none -l 127.0.0.1:8080 test/benchmark/readinput.ru
13   # in a different terminal, upload 45M from multiple curl processes:
14   dd if=/dev/zero bs=45M count=1 | curl -T- -HExpect: --limit-rate 1M \
15      --trace-time -v http://127.0.0.1:8080/ &
16   dd if=/dev/zero bs=45M count=1 | curl -T- -HExpect: --limit-rate 1M \
17      --trace-time -v http://127.0.0.1:8080/ &
18   wait
20 # The last client won't see a response until the first one is done uploading
21 # You also won't be able to make GET requests to view this documentation
22 # while clients are uploading.  You can also view the stderr debug output
23 # of unicorn (see logging code in #{__FILE__}).
24 DOC
26 run(lambda do |env|
27   input = env['rack.input']
28   buf = ''.b
30   # default logger contains timestamps, rely on that so users can
31   # see what the server is doing
32   l = env['rack.logger']
34   l.debug('BEGIN reading input ...') if l
35   :nop while input.read(16384, buf)
36   l.debug('DONE reading input ...') if l
38   buf.clear
39   [ 200, [ %W(Content-Length #{DOC.size}), %w(Content-Type text/plain) ],
40     [ DOC ] ]
41 end)