Created
December 5, 2012 13:07
-
-
Save timbuchwaldt/4215376 to your computer and use it in GitHub Desktop.
Redis Performance Benchmark
This file contains 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
require 'rubygems' | |
require 'hiredis' | |
require 'redis' | |
require 'json' | |
require 'msgpack' | |
script = <<EOF | |
redis.call('get', 'a') | |
redis.call('get', 'b') | |
redis.call('get', 'c') | |
redis.call('get', 'd') | |
redis.call('get', 'e') | |
redis.call('get', 'f') | |
redis.call('get', 'g') | |
redis.call('get', 'h') | |
redis.call('get', 'i') | |
redis.call('get', 'j') | |
redis.call('get', 'k') | |
redis.call('get', 'l') | |
EOF | |
r = Redis.new(:driver => :hiredis) | |
sha = r.script(:load, script) | |
repeat = 10000 | |
t1 = Time.now | |
repeat.times do | |
r.get("a") | |
r.get("b") | |
r.get("c") | |
r.get("d") | |
r.get("e") | |
r.get("f") | |
r.get("g") | |
r.get("h") | |
r.get("i") | |
r.get("j") | |
r.get("k") | |
r.get("l") | |
end | |
puts "Simple: #{(1 / ( (Time.now - t1) / repeat)).round} req/s" | |
t1 = Time.now | |
repeat.times do | |
r.multi do | |
r.get("a") | |
r.get("b") | |
r.get("c") | |
r.get("d") | |
r.get("e") | |
r.get("f") | |
r.get("g") | |
r.get("h") | |
r.get("i") | |
r.get("j") | |
r.get("k") | |
r.get("l") | |
end | |
end | |
puts "Multi: #{(1 / ( (Time.now - t1) / repeat)).round} req/s" | |
t1 = Time.now | |
repeat.times do | |
r.evalsha(sha, [], []) | |
end | |
puts "Script: #{(1 / ( (Time.now - t1) / repeat)).round} req/s" |
This file contains 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
This script performs a simple redis benchmark, requesting 12 keys per simple 'get'. | |
The loop repeats 10k times for some meaningful measurements. | |
First run does simple sequential gets, second one doing a redis multi, third one using a redis script and evalsha for requesting. | |
Simple: 1041 req/s | |
Multi: 4045 req/s | |
Script: 8145 req/s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment