Created
September 22, 2023 14:20
-
-
Save ArturT/5d9bcd7213806f731cfb812363ae5b82 to your computer and use it in GitHub Desktop.
Measure Redis latency from inside of Heroku Dyno
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# repalce REDIS_CONNECTION with your Redis instance | |
# | |
# run this script in Rails console. | |
# For example start Heroku Dyno with Rails console to measure the Redis latency from inside of the Heroku Dyno | |
# | |
# Do you like it? Check what we do: https://knapsackpro.com | |
rtts = [] | |
100.times do | |
a = b = 0; a = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond); REDIS_CONNECTION.ping; b = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond); rtt = b - a; | |
puts "#{rtt} microseconds" | |
rtts << rtt | |
sleep 0.1 | |
end | |
puts "Average: #{rtts.sum / rtts.size.to_f}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment