2006-05-19 22:56:30 -04:00
|
|
|
require 'socket'
|
|
|
|
require 'stringio'
|
|
|
|
|
|
|
|
def do_test(st, chunk)
|
|
|
|
s = TCPSocket.new('127.0.0.1',ARGV[0].to_i);
|
|
|
|
req = StringIO.new(st)
|
2006-06-23 09:22:47 -04:00
|
|
|
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
|
2007-10-20 22:54:53 -04:00
|
|
|
rescue Object => e
|
|
|
|
STDERR.puts "ERROR: #{e}"
|
2006-06-23 09:22:47 -04:00
|
|
|
ensure
|
|
|
|
s.close
|
2006-05-19 22:56:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-06-23 09:22:47 -04:00
|
|
|
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}"
|
2006-05-19 22:56:30 -04:00
|
|
|
|
2006-06-23 09:22:47 -04:00
|
|
|
puts "length: #{content.length}"
|
2006-05-19 22:56:30 -04:00
|
|
|
|
|
|
|
threads = []
|
2017-06-04 16:21:05 -04:00
|
|
|
ARGV[1].to_i.times do
|
2006-06-23 09:22:47 -04:00
|
|
|
t = Thread.new do
|
|
|
|
size = 100
|
|
|
|
puts ">>>> #{size} sized chunks"
|
|
|
|
do_test(st, size)
|
2006-05-19 22:56:30 -04:00
|
|
|
end
|
|
|
|
|
2006-06-23 09:22:47 -04:00
|
|
|
threads << t
|
2006-05-19 22:56:30 -04:00
|
|
|
end
|
|
|
|
|
2006-06-23 09:22:47 -04:00
|
|
|
threads.each {|t| t.join}
|