1
0

redis-benchmark.tcl 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. source tests/support/benchmark.tcl
  2. proc cmdstat {cmd} {
  3. return [cmdrstat $cmd r]
  4. }
  5. start_server {tags {"benchmark network external:skip"}} {
  6. start_server {} {
  7. set master_host [srv 0 host]
  8. set master_port [srv 0 port]
  9. test {benchmark: set,get} {
  10. r config resetstat
  11. r flushall
  12. set cmd [redisbenchmark $master_host $master_port "-c 5 -n 10 -t set,get"]
  13. if {[catch { exec {*}$cmd } error]} {
  14. set first_line [lindex [split $error "\n"] 0]
  15. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  16. fail "redis-benchmark non zero code. first line: $first_line"
  17. }
  18. assert_match {*calls=10,*} [cmdstat set]
  19. assert_match {*calls=10,*} [cmdstat get]
  20. # assert one of the non benchmarked commands is not present
  21. assert_match {} [cmdstat lrange]
  22. }
  23. test {benchmark: full test suite} {
  24. r config resetstat
  25. set cmd [redisbenchmark $master_host $master_port "-c 10 -n 100"]
  26. if {[catch { exec {*}$cmd } error]} {
  27. set first_line [lindex [split $error "\n"] 0]
  28. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  29. fail "redis-benchmark non zero code. first line: $first_line"
  30. }
  31. # ping total calls are 2*issued commands per test due to PING_INLINE and PING_MBULK
  32. assert_match {*calls=200,*} [cmdstat ping]
  33. assert_match {*calls=100,*} [cmdstat set]
  34. assert_match {*calls=100,*} [cmdstat get]
  35. assert_match {*calls=100,*} [cmdstat incr]
  36. # lpush total calls are 2*issued commands per test due to the lrange tests
  37. assert_match {*calls=200,*} [cmdstat lpush]
  38. assert_match {*calls=100,*} [cmdstat rpush]
  39. assert_match {*calls=100,*} [cmdstat lpop]
  40. assert_match {*calls=100,*} [cmdstat rpop]
  41. assert_match {*calls=100,*} [cmdstat sadd]
  42. assert_match {*calls=100,*} [cmdstat hset]
  43. assert_match {*calls=100,*} [cmdstat spop]
  44. assert_match {*calls=100,*} [cmdstat zadd]
  45. assert_match {*calls=100,*} [cmdstat zpopmin]
  46. assert_match {*calls=400,*} [cmdstat lrange]
  47. assert_match {*calls=100,*} [cmdstat mset]
  48. # assert one of the non benchmarked commands is not present
  49. assert_match {} [cmdstat rpoplpush]
  50. }
  51. test {benchmark: multi-thread set,get} {
  52. r config resetstat
  53. r flushall
  54. set cmd [redisbenchmark $master_host $master_port "--threads 10 -c 5 -n 10 -t set,get"]
  55. if {[catch { exec {*}$cmd } error]} {
  56. set first_line [lindex [split $error "\n"] 0]
  57. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  58. fail "redis-benchmark non zero code. first line: $first_line"
  59. }
  60. assert_match {*calls=10,*} [cmdstat set]
  61. assert_match {*calls=10,*} [cmdstat get]
  62. # assert one of the non benchmarked commands is not present
  63. assert_match {} [cmdstat lrange]
  64. # ensure only one key was populated
  65. assert_match {1} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
  66. }
  67. test {benchmark: pipelined full set,get} {
  68. r config resetstat
  69. r flushall
  70. set cmd [redisbenchmark $master_host $master_port "-P 5 -c 10 -n 10010 -t set,get"]
  71. if {[catch { exec {*}$cmd } error]} {
  72. set first_line [lindex [split $error "\n"] 0]
  73. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  74. fail "redis-benchmark non zero code. first line: $first_line"
  75. }
  76. assert_match {*calls=10010,*} [cmdstat set]
  77. assert_match {*calls=10010,*} [cmdstat get]
  78. # assert one of the non benchmarked commands is not present
  79. assert_match {} [cmdstat lrange]
  80. # ensure only one key was populated
  81. assert_match {1} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
  82. }
  83. test {benchmark: arbitrary command} {
  84. r config resetstat
  85. r flushall
  86. set cmd [redisbenchmark $master_host $master_port "-c 5 -n 150 INCRBYFLOAT mykey 10.0"]
  87. if {[catch { exec {*}$cmd } error]} {
  88. set first_line [lindex [split $error "\n"] 0]
  89. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  90. fail "redis-benchmark non zero code. first line: $first_line"
  91. }
  92. assert_match {*calls=150,*} [cmdstat incrbyfloat]
  93. # assert one of the non benchmarked commands is not present
  94. assert_match {} [cmdstat get]
  95. # ensure only one key was populated
  96. assert_match {1} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
  97. }
  98. test {benchmark: keyspace length} {
  99. r flushall
  100. r config resetstat
  101. set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000"]
  102. if {[catch { exec {*}$cmd } error]} {
  103. set first_line [lindex [split $error "\n"] 0]
  104. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  105. fail "redis-benchmark non zero code. first line: $first_line"
  106. }
  107. assert_match {*calls=1000,*} [cmdstat set]
  108. # assert one of the non benchmarked commands is not present
  109. assert_match {} [cmdstat get]
  110. # ensure the keyspace has the desired size
  111. assert_match {50} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
  112. }
  113. # tls specific tests
  114. if {$::tls} {
  115. test {benchmark: specific tls-ciphers} {
  116. r flushall
  117. r config resetstat
  118. set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000 --tls-ciphers \"DEFAULT:-AES128-SHA256\""]
  119. if {[catch { exec {*}$cmd } error]} {
  120. set first_line [lindex [split $error "\n"] 0]
  121. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  122. fail "redis-benchmark non zero code. first line: $first_line"
  123. }
  124. assert_match {*calls=1000,*} [cmdstat set]
  125. # assert one of the non benchmarked commands is not present
  126. assert_match {} [cmdstat get]
  127. }
  128. test {benchmark: specific tls-ciphersuites} {
  129. r flushall
  130. r config resetstat
  131. set ciphersuites_supported 1
  132. set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000 --tls-ciphersuites \"TLS_AES_128_GCM_SHA256\""]
  133. if {[catch { exec {*}$cmd } error]} {
  134. set first_line [lindex [split $error "\n"] 0]
  135. if {[string match "*Invalid option*" $first_line]} {
  136. set ciphersuites_supported 0
  137. if {$::verbose} {
  138. puts "Skipping test, TLSv1.3 not supported."
  139. }
  140. } else {
  141. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  142. fail "redis-benchmark non zero code. first line: $first_line"
  143. }
  144. }
  145. if {$ciphersuites_supported} {
  146. assert_match {*calls=1000,*} [cmdstat set]
  147. # assert one of the non benchmarked commands is not present
  148. assert_match {} [cmdstat get]
  149. }
  150. }
  151. }
  152. }
  153. }