]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env tclsh8.5 | |
2 | # Copyright (C) 2011 Salvatore Sanfilippo | |
3 | # Released under the BSD license like Redis itself | |
4 | ||
5 | source ../tests/support/redis.tcl | |
6 | set ::port 12123 | |
7 | set ::tests {PING,SET,GET,INCR,LPUSH,LPOP,SADD,SPOP,LRANGE_100,LRANGE_600,MSET} | |
8 | set ::datasize 16 | |
9 | set ::requests 100000 | |
10 | ||
11 | proc 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]" | |
31 | set pids [exec echo "port $::port\nloglevel warning\n" | ./redis-server - > /dev/null 2> /dev/null &] | |
32 | puts " pids: $pids" | |
33 | after 1000 | |
34 | puts " running the benchmark" | |
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 | ||
41 | set output [exec /tmp/redis-benchmark -n $::requests -t $::tests -d $::datasize --csv -p $::port] | |
42 | lappend runs $b $output | |
43 | puts " killing server..." | |
44 | catch {exec kill -9 [lindex $pids 0]} | |
45 | catch {exec kill -9 [lindex $pids 1]} | |
46 | incr branch_id | |
47 | } | |
48 | return $runs | |
49 | } | |
50 | ||
51 | proc 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 | ||
63 | proc 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 | |
69 | } | |
70 | return $names | |
71 | } | |
72 | ||
73 | proc combine-results {results} { | |
74 | set tests [get-test-names [lindex $results 1]] | |
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 | ||
85 | proc 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] | |
92 | puts "\n" | |
93 | puts "# Test results: datasize=$::datasize requests=$::requests" | |
94 | puts [combine-results $results] | |
95 | } | |
96 | ||
97 | # Force the user to run the script from the 'utils' directory. | |
98 | if {![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 | } | |
103 | ||
104 | # Make sure there is not already a server runnign on port 12123 | |
105 | set is_not_running [catch {set r [redis 127.0.0.1 $::port]}] | |
106 | if {!$is_not_running} { | |
107 | puts "Sorry, you have a running server on port $::port" | |
108 | exit 1 | |
109 | } | |
110 | ||
111 | # parse arguments | |
112 | for {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 | ||
130 | main |