Skip to content

Instantly share code, notes, and snippets.

@mcrumm
Last active August 29, 2015 14:19
Show Gist options
  • Save mcrumm/e8c298b62c6787723cb5 to your computer and use it in GitHub Desktop.
Save mcrumm/e8c298b62c6787723cb5 to your computer and use it in GitHub Desktop.
sloth: gentle load testing

Sloth: Gentle load testing

Install

$ bundle install
$ chmod +x ./sloth.rb
$ ./sloth.rb <SIEGE_FILE> <AUTH_USER> <AUTH_PASS> <TRANSACTIONS_PER_SECOND> <RUNTIME_IN_SECONDS>
source 'https://rubygems.org'
gem 'httparty'
#!/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
# 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 } }
response = HTTParty.post(data[0], options)
puts Time.now.to_s << ' ' << response.code.to_s << ' ' << response.message
sleep(1.0/tps.to_f)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment