test-lru.rb: support for testing volatile-ttl policy.
This commit is contained in:
parent
6854c7b9ee
commit
9f1b7ab2ed
@ -2,11 +2,16 @@ require 'rubygems'
|
|||||||
require 'redis'
|
require 'redis'
|
||||||
|
|
||||||
$runs = []; # Remember the error rate of each run for average purposes.
|
$runs = []; # Remember the error rate of each run for average purposes.
|
||||||
|
$o = {}; # Options set parsing arguments
|
||||||
|
|
||||||
def testit(filename)
|
def testit(filename)
|
||||||
r = Redis.new
|
r = Redis.new
|
||||||
r.config("SET","maxmemory","2000000")
|
r.config("SET","maxmemory","2000000")
|
||||||
r.config("SET","maxmemory-policy","allkeys-lru")
|
if $o[:ttl]
|
||||||
|
r.config("SET","maxmemory-policy","volatile-ttl")
|
||||||
|
else
|
||||||
|
r.config("SET","maxmemory-policy","allkeys-lru")
|
||||||
|
end
|
||||||
r.config("SET","maxmemory-samples",5)
|
r.config("SET","maxmemory-samples",5)
|
||||||
r.config("RESETSTAT")
|
r.config("RESETSTAT")
|
||||||
r.flushall
|
r.flushall
|
||||||
@ -47,7 +52,11 @@ EOF
|
|||||||
id = 0
|
id = 0
|
||||||
while true
|
while true
|
||||||
id += 1
|
id += 1
|
||||||
r.set(id,"foo")
|
begin
|
||||||
|
r.set(id,"foo")
|
||||||
|
rescue
|
||||||
|
break
|
||||||
|
end
|
||||||
newsize = r.dbsize
|
newsize = r.dbsize
|
||||||
break if newsize == oldsize # A key was evicted? Stop.
|
break if newsize == oldsize # A key was evicted? Stop.
|
||||||
oldsize = newsize
|
oldsize = newsize
|
||||||
@ -60,12 +69,20 @@ EOF
|
|||||||
# Access keys sequentially, so that in theory the first part will be expired
|
# Access keys sequentially, so that in theory the first part will be expired
|
||||||
# and the latter part will not, according to perfect LRU.
|
# and the latter part will not, according to perfect LRU.
|
||||||
|
|
||||||
STDERR.puts "Access keys sequentially"
|
if $o[:ttl]
|
||||||
(1..first_set_max_id).each{|id|
|
STDERR.puts "Set increasing expire value"
|
||||||
r.get(id)
|
(1..first_set_max_id).each{|id|
|
||||||
sleep 0.001
|
r.expire(id,1000+id)
|
||||||
STDERR.print(".") if (id % 150) == 0
|
STDERR.print(".") if (id % 150) == 0
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
STDERR.puts "Access keys sequentially"
|
||||||
|
(1..first_set_max_id).each{|id|
|
||||||
|
r.get(id)
|
||||||
|
sleep 0.001
|
||||||
|
STDERR.print(".") if (id % 150) == 0
|
||||||
|
}
|
||||||
|
end
|
||||||
STDERR.puts
|
STDERR.puts
|
||||||
|
|
||||||
# Insert more 50% keys. We expect that the new keys will rarely be expired
|
# Insert more 50% keys. We expect that the new keys will rarely be expired
|
||||||
@ -173,16 +190,34 @@ def print_avg
|
|||||||
end
|
end
|
||||||
|
|
||||||
if ARGV.length < 1
|
if ARGV.length < 1
|
||||||
STDERR.puts "Usage: ruby test-lru.rb <html-output-filename> [num-runs]"
|
STDERR.puts "Usage: ruby test-lru.rb <html-output-filename> [--runs <count>] [--ttl]"
|
||||||
|
STDERR.puts "Options:"
|
||||||
|
STDERR.puts " --runs <count> Execute the test <count> times."
|
||||||
|
STDERR.puts " --ttl Set keys with increasing TTL values"
|
||||||
|
STDERR.puts " (starting from 1000 seconds) in order to"
|
||||||
|
STDERR.puts " test the volatile-lru policy."
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
filename = ARGV[0]
|
filename = ARGV[0]
|
||||||
numruns = 1
|
$o[:numruns] = 1
|
||||||
|
|
||||||
numruns = ARGV[1].to_i if ARGV.length == 2
|
# Options parsing
|
||||||
|
i = 1
|
||||||
|
while i < ARGV.length
|
||||||
|
if ARGV[i] == '--runs'
|
||||||
|
$o[:numruns] = ARGV[i+1].to_i
|
||||||
|
i+= 1
|
||||||
|
elsif ARGV[i] == '--ttl'
|
||||||
|
$o[:ttl] = true
|
||||||
|
else
|
||||||
|
STDERR.puts "Unknown option #{ARGV[i]}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
i+= 1
|
||||||
|
end
|
||||||
|
|
||||||
numruns.times {
|
$o[:numruns].times {
|
||||||
testit(filename)
|
testit(filename)
|
||||||
print_avg if numruns != 1
|
print_avg if $o[:numruns] != 1
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user