Skip to content

Instantly share code, notes, and snippets.

@toretore
Forked from znorris/sloth.rb
Last active August 29, 2015 14:19
Show Gist options
  • Save toretore/ed941c6c54f2dbafcfa6 to your computer and use it in GitHub Desktop.
Save toretore/ed941c6c54f2dbafcfa6 to your computer and use it in GitHub Desktop.
#!/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