Created
May 1, 2015 18:44
-
-
Save dmcclory/1b9203d56659b1ab86ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# some real quick code for running requests in parallel | |
# usage: | |
# $ ruby parallel_req.rb http://url_place/ post 5 data.json | |
# doesn't work with get requests (yet)! | |
require 'http' | |
url = ARGV[0] | |
method = ARGV[1] | |
thread_count = ARGV[2].to_i | |
data = File.read(ARGV[3]) | |
results = {} | |
threads = thread_count.times.map do |n| | |
Thread.new do |t| | |
start_time = Time.now | |
HTTP.send(method, url, :json => data) | |
end_time = Time.now | |
duration = end_time - start_time | |
results[n] = duration | |
end | |
end | |
threads.each do |t| | |
t.join | |
end | |
results.each do |id, duration| | |
puts "thread[#{id}]: #{duration}" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment