Project

General

Profile

Bug #11482 » client.rb

s_p_oneil (Sean O'Neil), 08/24/2015 03:21 PM

 
require 'socket'

_success, _fail = 0, 0

URLS = [
"/stats",
"/404.html",
"/login/index"
]

threads = []
100.times {|i|
threads << Thread.new {
loop {
begin
s = TCPSocket.new('127.0.0.1', 8000 + i%10)
s.puts("GET #{URLS[(_success+_fail)%URLS.size]} HTTP/1.0\r\n\r\n")
s.close
_success += 1
rescue Exception
#puts($!.to_s)
_fail += 1
end
puts("#{_success} successes, #{_fail} failures") if (_success+_fail) % 100 == 0
}
}
}

threads.each {|t| t.join }

(1-1/3)