Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 44 lines (38 sloc) 1.09 KB
#!/usr/bin/env ruby
begin
require 'benchmark'
require 'rubygems'
require 'activesupport'
require 'socket'
require 'optparse'
require 'ostruct'
end
begin
$options = {
:concurrency => 1,
:count => 100,
:host => "0.0.0.0"
}
OptionParser.new do |opts|
opts.on('-n', "--number COUNT", Integer) { |count| $options[:count] = count }
opts.on('-c', "--concurrency CONCURRENCY", Integer) { |concurrency| $options[:concurrency] = concurrency }
opts.on('-p', "--port PORT", Integer) { |port| $options[:port] = port }
end.parse!
end
count_per_worker = $options[:count] / $options[:concurrency]
requests = (1..10).to_a
benchmark = Benchmark.measure do
threads = []
$options[:concurrency].times do
threads << Thread.new do
socket = TCPSocket.new($options[:host], $options[:port])
count_per_worker.times do
socket.print("#{requests.rand}\n")
socket.readline
end
end
end
threads.each(&:join)
end
mean = $options[:count] / benchmark.real
puts "Requests per second (throughput):\t%2f [#/sec] (mean)" % mean