Skip to content

Instantly share code, notes, and snippets.

@asterite
Last active September 2, 2015 15:56
Show Gist options
  • Save asterite/d4b53b1c6c3f1e7ad06c to your computer and use it in GitHub Desktop.
Save asterite/d4b53b1c6c3f1e7ad06c to your computer and use it in GitHub Desktop.
require "./cryload/*"
require "http"
module Cryload
class LoadGenerator
def initialize(@host, @number)
@stats = Stats.new @number
ch = generate_request_channel
loop do
check_log
ch.receive
@stats.increase_total_request_count
end
end
def generate_request_channel()
channel = Channel(Int32).new
uri = URI.parse @host
full_path = uri.full_path
client = HTTP::Client.new uri.host.not_nil!, port: uri.port
spawn do
loop do
start_time = Time.now
client.get full_path
end_time = Time.now
time_taken_in_ms = (end_time - start_time).to_f * 1000.0
@stats.add_to_request_times time_taken_in_ms
channel.send 0
end
end
channel
end
def check_log
Logger.new @stats
end
end
end
if ARGV.empty?
p "You need to set a host!"
exit
else
host = ARGV.shift
request_count = unless ARGV.empty?
ARGV.shift
else
1000
end
p "Preparing to make it CRY for #{request_count} requests!"
Cryload::LoadGenerator.new host, request_count.to_i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment