Back to home page

Redis cross reference

 
 

    


0001 #!/usr/bin/env tclsh8.5
0002 # Copyright (C) 2011 Salvatore Sanfilippo
0003 # Released under the BSD license like Redis itself
0004 
0005 source ../tests/support/redis.tcl
0006 set ::port 12123
0007 set ::tests {PING,SET,GET,INCR,LPUSH,LPOP,SADD,SPOP,LRANGE_100,LRANGE_600,MSET}
0008 set ::datasize 16
0009 set ::requests 100000
0010 
0011 proc run-tests branches {
0012     set runs {}
0013     set branch_id 0
0014     foreach b $branches {
0015         cd ../src
0016         puts "Benchmarking $b"
0017         exec -ignorestderr git checkout $b 2> /dev/null
0018         exec -ignorestderr make clean 2> /dev/null
0019         puts "  compiling..."
0020         exec -ignorestderr make 2> /dev/null
0021 
0022         if {$branch_id == 0} {
0023             puts "  copy redis-benchmark from unstable to /tmp..."
0024             exec -ignorestderr cp ./redis-benchmark /tmp
0025             incr branch_id
0026             continue
0027         }
0028 
0029         # Start the Redis server
0030         puts "  starting the server... [exec ./redis-server -v]"
0031         set pids [exec echo "port $::port\nloglevel warning\n" | ./redis-server - > /dev/null 2> /dev/null &]
0032         puts "  pids: $pids"
0033         after 1000
0034         puts "  running the benchmark"
0035 
0036         set r [redis 127.0.0.1 $::port]
0037         set i [$r info]
0038         puts "  redis INFO shows version: [lindex [split $i] 0]"
0039         $r close
0040 
0041         set output [exec /tmp/redis-benchmark -n $::requests -t $::tests -d $::datasize --csv -p $::port]
0042         lappend runs $b $output
0043         puts "  killing server..."
0044         catch {exec kill -9 [lindex $pids 0]}
0045         catch {exec kill -9 [lindex $pids 1]}
0046         incr branch_id
0047     }
0048     return $runs
0049 }
0050 
0051 proc get-result-with-name {output name} {
0052     foreach line [split $output "\n"] {
0053         lassign [split $line ","] key value
0054         set key [string tolower [string range $key 1 end-1]]
0055         set value [string range $value 1 end-1]
0056         if {$key eq [string tolower $name]} {
0057             return $value
0058         }
0059     }
0060     return "n/a"
0061 }
0062 
0063 proc get-test-names output {
0064     set names {}
0065     foreach line [split $output "\n"] {
0066         lassign [split $line ","] key value
0067         set key [string tolower [string range $key 1 end-1]]
0068         lappend names $key
0069     }
0070     return $names
0071 }
0072 
0073 proc combine-results {results} {
0074     set tests [get-test-names [lindex $results 1]]
0075     foreach test $tests {
0076         puts $test
0077         foreach {branch output} $results {
0078             puts [format "%-20s %s" \
0079                 $branch [get-result-with-name $output $test]]
0080         }
0081         puts {}
0082     }
0083 }
0084 
0085 proc main {} {
0086     # Note: the first branch is only used in order to get the redis-benchmark
0087     # executable. Tests are performed starting from the second branch.
0088     set branches {
0089         slowset 2.2.0 2.4.0 unstable slowset
0090     }
0091     set results [run-tests $branches]
0092     puts "\n"
0093     puts "# Test results: datasize=$::datasize requests=$::requests"
0094     puts [combine-results $results]
0095 }
0096 
0097 # Force the user to run the script from the 'utils' directory.
0098 if {![file exists speed-regression.tcl]} {
0099     puts "Please make sure to run speed-regression.tcl while inside /utils."
0100     puts "Example: cd utils; ./speed-regression.tcl"
0101     exit 1
0102 }
0103 
0104 # Make sure there is not already a server runnign on port 12123
0105 set is_not_running [catch {set r [redis 127.0.0.1 $::port]}]
0106 if {!$is_not_running} {
0107     puts "Sorry, you have a running server on port $::port"
0108     exit 1
0109 }
0110 
0111 # parse arguments
0112 for {set j 0} {$j < [llength $argv]} {incr j} {
0113     set opt [lindex $argv $j]
0114     set arg [lindex $argv [expr $j+1]]
0115     if {$opt eq {--tests}} {
0116         set ::tests $arg
0117         incr j
0118     } elseif {$opt eq {--datasize}} {
0119         set ::datasize $arg
0120         incr j
0121     } elseif {$opt eq {--requests}} {
0122         set ::requests $arg
0123         incr j
0124     } else {
0125         puts "Wrong argument: $opt"
0126         exit 1
0127     }
0128 }
0129 
0130 main