Skip to content

Instantly share code, notes, and snippets.

@brandur
Last active June 3, 2023 02:31
Show Gist options
  • Save brandur/90698498bd543598d00df46e32be3268 to your computer and use it in GitHub Desktop.
Save brandur/90698498bd543598d00df46e32be3268 to your computer and use it in GitHub Desktop.
redis-cell Informal Benchmarks

redis-cell Informal Benchmarks

I got these results when comparing CL.THROTTLE to SET on my early 2015 13" 3.1 GHz i7 MacBook Pro (not connected to a power source at the time):

$ ruby bench.rb
SET
Took total of: 5.975439 s
Per iteration: 5.975439e-05 s (0.05975439 ms)

CL.THROTTLE
Took total of: 10.621449 s
Per iteration: 0.00010621449 s (0.10621449000000001 ms)

Which suggests that CL.THROTTLE a little under twice as slow as a basic Redis SET command at roughly 0.11 milliseconds per execution.

Notes on methodology:

  • Timing is measured from a client outside Redis itself to represent a slightly more realistic situation.
  • Timing is measured relative to SET in an attempt to abstract away any advantages of specific hardware.

Script

require "redis"

ITERATIONS = 100000

RedisConn = Redis.new

def bench_command(*args, &block)
  start = Time.now

  ITERATIONS.times do
    resp = RedisConn.send(*args)
    block.yield(resp)
  end

  puts args[0]

  duration = Time.now - start
  puts "Took total of: #{duration} s"

  per_iteration = duration / ITERATIONS
  per_iteration_ms = per_iteration * 1000
  puts "Per iteration: #{per_iteration} s (#{per_iteration_ms} ms)"

  puts ""
end

bench_command(:"SET", "hello", 123) do |resp|
  if resp != "OK"
    raise "Unexpected response. You probably have a bug."
  end
end

bench_command(:"CL.THROTTLE", "user123", 15, 30, 60, 1) do |resp|
  if !resp.is_a?(Array) || (resp[0] != 0 && resp[0] != 1)
    raise "Unexpected response. You probably have a bug."
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment