Created
May 2, 2011 09:24
-
-
Save catwell/951352 to your computer and use it in GitHub Desktop.
Redis scripting MHSET 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 "redis" | |
def time(x) | |
t0 = Time.now | |
yield | |
puts "#{x} - #{1000 * (Time.now - t0)}" | |
end | |
L = 1.upto(10000.to_i).to_a | |
R = Redis.new(path: "/tmp/redis.sock",thread_safe: false) | |
LUA_MHSET_SRC = <<-EOS | |
n = #KEYS | |
f = ARGV[n+1] | |
for i,k in ipairs(KEYS) do | |
redis("hset",k,f,ARGV[i]) | |
end | |
return n | |
EOS | |
def lua_mhset(field,keys,values) | |
R.eval(LUA_MHSET_SRC,keys,values+[field]) | |
end | |
R.flushall; sleep 2 | |
time("naive"){ L.each{|i| R.hset(i,1,i)} } | |
R.flushall; sleep 2 | |
time("pipeline"){ R.multi{L.each{|i| R.hset(i,1,i)}} } | |
R.flushall; sleep 2 | |
time("lua"){ lua_mhset(1,L,L) } | |
# RESULTS: | |
# naive - 646.516 | |
# pipeline - 226.891 | |
# lua - 81.239 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: "eval" here does not use method_missing, I rewrote it as: