Log-Shuffling Stress Test Script
The following script takes existing access logs from Axiom and fires off a random sequence of concurrent requests from those recorded within. It's pretty useful for stress-testing an application, though it does rely on preexisting access data.
Usage: ruby script.rb num-threads domain list-of-log-files
Example: ruby script.rb 7 test.siteworx.com log/*access*.log
require 'open-uri'
num_threads = ARGV[0].to_i
domain = ARGV[1]
uris = ARGV[2..ARGV.length-1].map do |log|
File.open(log).read.scan(/get:(\S+)/)
end
uris.flatten!
threads = []
(1..num_threads).each do
threads << Thread.new(uris) do |url_list|
url_list.sort_by{rand}.each do |uri|
puts "fetching - http://#{domain}/#{uri}"
begin
open("http://#{domain}/#{uri}") do |data|
puts "#{data.base_uri} - #{data.status[0]}"
end
rescue Exception => e
puts "no dice - #{e} "
end
end
end
end
threads.each {|thread| thread.join}
