]> git.saurik.com Git - redis.git/blame - utils/speed-regression.tcl
Fix compilation on Linux kernels or glibc versions lacking sync_file_range().
[redis.git] / utils / speed-regression.tcl
CommitLineData
9f080a01 1#!/usr/bin/env tclsh8.5
2# Copyright (C) 2011 Salvatore Sanfilippo
3# Released under the BSD license like Redis itself
4
85bc9b06 5source ../tests/support/redis.tcl
6set ::port 12123
55758a5f 7set ::tests {PING,SET,GET,INCR,LPUSH,LPOP,SADD,SPOP,LRANGE_100,LRANGE_600,MSET}
8set ::datasize 16
9set ::requests 100000
85bc9b06 10
9f080a01 11proc run-tests branches {
12 set runs {}
13 set branch_id 0
14 foreach b $branches {
15 cd ../src
16 puts "Benchmarking $b"
17 exec -ignorestderr git checkout $b 2> /dev/null
18 exec -ignorestderr make clean 2> /dev/null
19 puts " compiling..."
20 exec -ignorestderr make 2> /dev/null
21
22 if {$branch_id == 0} {
23 puts " copy redis-benchmark from unstable to /tmp..."
24 exec -ignorestderr cp ./redis-benchmark /tmp
25 incr branch_id
26 continue
27 }
28
29 # Start the Redis server
30 puts " starting the server... [exec ./redis-server -v]"
85bc9b06 31 set pids [exec echo "port $::port\nloglevel warning\n" | ./redis-server - > /dev/null 2> /dev/null &]
32 puts " pids: $pids"
9f080a01 33 after 1000
34 puts " running the benchmark"
85bc9b06 35
36 set r [redis 127.0.0.1 $::port]
37 set i [$r info]
38 puts " redis INFO shows version: [lindex [split $i] 0]"
39 $r close
40
55758a5f 41 set output [exec /tmp/redis-benchmark -n $::requests -t $::tests -d $::datasize --csv -p $::port]
9f080a01 42 lappend runs $b $output
43 puts " killing server..."
85bc9b06 44 catch {exec kill -9 [lindex $pids 0]}
45 catch {exec kill -9 [lindex $pids 1]}
9f080a01 46 incr branch_id
47 }
48 return $runs
49}
50
51proc get-result-with-name {output name} {
52 foreach line [split $output "\n"] {
53 lassign [split $line ","] key value
54 set key [string tolower [string range $key 1 end-1]]
55 set value [string range $value 1 end-1]
56 if {$key eq [string tolower $name]} {
57 return $value
58 }
59 }
60 return "n/a"
61}
62
84c6bdfc 63proc get-test-names output {
64 set names {}
65 foreach line [split $output "\n"] {
66 lassign [split $line ","] key value
67 set key [string tolower [string range $key 1 end-1]]
68 lappend names $key
9f080a01 69 }
84c6bdfc 70 return $names
71}
72
73proc combine-results {results} {
74 set tests [get-test-names [lindex $results 1]]
9f080a01 75 foreach test $tests {
76 puts $test
77 foreach {branch output} $results {
78 puts [format "%-20s %s" \
79 $branch [get-result-with-name $output $test]]
80 }
81 puts {}
82 }
83}
84
85proc main {} {
86 # Note: the first branch is only used in order to get the redis-benchmark
87 # executable. Tests are performed starting from the second branch.
88 set branches {
89 slowset 2.2.0 2.4.0 unstable slowset
90 }
91 set results [run-tests $branches]
55758a5f 92 puts "\n"
93 puts "# Test results: datasize=$::datasize requests=$::requests"
9f080a01 94 puts [combine-results $results]
95}
96
97# Force the user to run the script from the 'utils' directory.
98if {![file exists speed-regression.tcl]} {
99 puts "Please make sure to run speed-regression.tcl while inside /utils."
100 puts "Example: cd utils; ./speed-regression.tcl"
101 exit 1
102}
85bc9b06 103
104# Make sure there is not already a server runnign on port 12123
105set is_not_running [catch {set r [redis 127.0.0.1 $::port]}]
106if {!$is_not_running} {
107 puts "Sorry, you have a running server on port $::port"
108 exit 1
109}
110
d5a80182 111# parse arguments
112for {set j 0} {$j < [llength $argv]} {incr j} {
113 set opt [lindex $argv $j]
114 set arg [lindex $argv [expr $j+1]]
115 if {$opt eq {--tests}} {
116 set ::tests $arg
117 incr j
118 } elseif {$opt eq {--datasize}} {
119 set ::datasize $arg
120 incr j
121 } elseif {$opt eq {--requests}} {
122 set ::requests $arg
123 incr j
124 } else {
125 puts "Wrong argument: $opt"
126 exit 1
127 }
128}
129
9f080a01 130main