-
-
Save toretore/ed941c6c54f2dbafcfa6 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'bundler/setup' | |
require 'httparty' | |
file = ARGV[0] # Siege File Path | |
user = ARGV[1] # HTTP Basic User | |
pass = ARGV[2] # HTTP Basic Pass | |
tps = ARGV[3].to_i # Transactions per second | |
runtime = ARGV[4].to_i # Runtime, in seconds. | |
lines = [] | |
# Add lines from siege files into lines array. | |
File.open(file) do |f| | |
f.each_line do |line| | |
lines.push line | |
end | |
end | |
now = Time.now | |
end_time = now + runtime | |
threads = [] | |
# Loop until we pass the end_time. | |
while Time.now < end_time do | |
# Get a random line from the siege file. | |
line = lines.sample | |
data = line.split(' ') | |
# Generate the POST data | |
options = { body: data[2], basic_auth: { username: user, password: pass } } | |
threads << Thread.new do | |
response = HTTParty.post(data[0], options) | |
puts Time.now.to_s << ' ' << response.code.to_s << ' ' << response.message | |
end | |
sleep(1.0/tps.to_f) | |
end | |
threads.each{|t| t.join } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment