Skip to content

Instantly share code, notes, and snippets.

@rickhull
Created April 2, 2015 03:14
Show Gist options
  • Save rickhull/26c0a0523d87cf0b62df to your computer and use it in GitHub Desktop.
Save rickhull/26c0a0523d87cf0b62df to your computer and use it in GitHub Desktop.
num_threads.times {
threads << Thread.new {
while !queue.empty?
# pop the queue
verb, path, query, orig_rc, orig_latency = *queue.deq
# issue HTTP request
# get HTTP response
# categorize response into success, failure, timeout, questionable
begin
rc, body, latency = Timeout.timeout(timeout) {
perform_http(verb, host_str, path, query)
}
rescue Timeout::Error
results[:timeout] << [verb, path, nil, timeout * 1000]
end
if rc != orig_rc
results[:failure] << [verb, path, rc, latency, orig_rc]
elsif latency > latency_threshold
results[:questionable] << [verb, path, rc, latency, body]
else
results[:success] << [verb, path, rc, latency]
end
end
}
}
# wait for all threads to complete
threads.each { |thr| thr.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment