Skip to content

Instantly share code, notes, and snippets.

@ssnickolay
Created September 28, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssnickolay/22e8ee2d6eb131de77a2b2b3a71bcb11 to your computer and use it in GitHub Desktop.
Save ssnickolay/22e8ee2d6eb131de77a2b2b3a71bcb11 to your computer and use it in GitHub Desktop.
Loop wrk
# Usage:
# ruby ./bench.rb "wrk -c20 -t20 -d3m http://localhost:9292/request" "c20t20-jvm.dat"
PARSE_RPS = proc do |out|
begin
out.match(/Requests\/sec: (?<value>.*)/)[:value].gsub!(" ", "").to_f
rescue
puts "Wrong RPS parsing"
0
end
end
puts "Let's start!"
command = ARGV.shift
plot = ARGV.shift
unless command.include?("wrk")
raise "Please, provide a wrk command"
end
i = 1
result = []
begin
loop do
out = `#{command}`
rps = PARSE_RPS.call(out)
puts "#{i}: #{rps} RPS"
result << [i, rps]
i += 1
break if rps == 0
sleep 10
end
rescue SystemExit, Interrupt
File.open(plot, "w") do |file|
file.puts("# Iteration RPS")
result.each do |(iteration, rps)|
file.puts("#{iteration} #{rps}")
end
end
end
puts "Done. See #{plot} file"
# An Example:
# gnuplot> set boxwidth 0.6 relative
# gnuplot> set style fill solid
# gnuplot> plot 'out.dat' with boxes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment