Skip to content

Instantly share code, notes, and snippets.

@nyku
Created November 24, 2019 10:37
Show Gist options
  • Save nyku/3cdd456c4089b8a79e7b8054aaa1ec5c to your computer and use it in GitHub Desktop.
Save nyku/3cdd456c4089b8a79e7b8054aaa1ec5c to your computer and use it in GitHub Desktop.
EZmetrics benchmark
require 'ezmetrics'
require 'benchmark'
require 'active_support/time'
def write_metrics(start, redis, seconds)
redis.flushdb
seconds.times do |i|
second = start - i
payload = {
"duration_sum" => rand(10000),
"duration_max" => rand(10000),
"views_sum" => rand(1000),
"views_max" => rand(1000),
"db_sum" => rand(8000),
"db_max" => rand(8000),
"queries_sum" => rand(100),
"queries_max" => rand(100),
"statuses" => {
"2xx" => rand(10),
"3xx" => rand(10),
"4xx" => rand(10),
"5xx" => rand(10),
"all" => rand(40)
}
}
redis.setex("ez-metrics:#{second}", seconds, JSON.generate(payload))
end
nil
end
def measure_aggregation_time(seconds)
start = Time.now.to_i
redis = Redis.new
durations = []
itterations = 3
write_metrics(start, redis, seconds)
itterations.times do
durations << Benchmark.measure { EZmetrics.new(seconds).show }.real
end
redis.flushdb
{ seconds => "#{(durations.sum.to_f / itterations).round(2)} seconds" }
end
p measure_aggregation_time(1.minute)
p measure_aggregation_time(1.hour)
p measure_aggregation_time(12.hours)
p measure_aggregation_time(24.hours)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment