1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/tools/trickletest.rb
zedshaw a6d80703cb Refactor reaping dead threads. Slight change to license header to make it clearer.
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@255 19e92222-5c0b-0410-8929-a290d50e31e9
2006-06-23 13:22:47 +00:00

45 lines
912 B
Ruby

require 'socket'
require 'stringio'
def do_test(st, chunk)
s = TCPSocket.new('127.0.0.1',ARGV[0].to_i);
req = StringIO.new(st)
nout = 0
randstop = rand(st.length / 10)
STDERR.puts "stopping after: #{randstop}"
begin
while data = req.read(chunk)
nout += s.write(data)
s.flush
sleep 0.1
if nout > randstop
STDERR.puts "BANG! after #{nout} bytes."
break
end
end
rescue Object
STDERR.puts "ERROR: #$!"
ensure
s.close
end
end
content = "-" * (1024 * 240)
st = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\nContent-Length: #{content.length}\r\n\r\n#{content}"
puts "length: #{content.length}"
threads = []
ARGV[1].to_i.times do
t = Thread.new do
size = 100
puts ">>>> #{size} sized chunks"
do_test(st, size)
end
t.abort_on_exception = true
threads << t
end
threads.each {|t| t.join}