redis-benchmark.tcl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. source tests/support/benchmark.tcl
  2. proc cmdstat {cmd} {
  3. return [cmdrstat $cmd r]
  4. }
  5. # common code to reset stats, flush the db and run redis-benchmark
  6. proc common_bench_setup {cmd} {
  7. r config resetstat
  8. r flushall
  9. if {[catch { exec {*}$cmd } error]} {
  10. set first_line [lindex [split $error "\n"] 0]
  11. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  12. fail "redis-benchmark non zero code. first line: $first_line"
  13. }
  14. }
  15. # we use this extra asserts on a simple set,get test for features like uri parsing
  16. # and other simple flag related tests
  17. proc default_set_get_checks {} {
  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. start_server {tags {"benchmark network external:skip"}} {
  24. start_server {} {
  25. set master_host [srv 0 host]
  26. set master_port [srv 0 port]
  27. test {benchmark: set,get} {
  28. set cmd [redisbenchmark $master_host $master_port "-c 5 -n 10 -t set,get"]
  29. common_bench_setup $cmd
  30. default_set_get_checks
  31. }
  32. test {benchmark: connecting using URI set,get} {
  33. set cmd [redisbenchmarkuri $master_host $master_port "-c 5 -n 10 -t set,get"]
  34. common_bench_setup $cmd
  35. default_set_get_checks
  36. }
  37. test {benchmark: connecting using URI with authentication set,get} {
  38. r config set masterauth pass
  39. set cmd [redisbenchmarkuriuserpass $master_host $master_port "default" pass "-c 5 -n 10 -t set,get"]
  40. common_bench_setup $cmd
  41. default_set_get_checks
  42. }
  43. test {benchmark: full test suite} {
  44. set cmd [redisbenchmark $master_host $master_port "-c 10 -n 100"]
  45. common_bench_setup $cmd
  46. # ping total calls are 2*issued commands per test due to PING_INLINE and PING_MBULK
  47. assert_match {*calls=200,*} [cmdstat ping]
  48. assert_match {*calls=100,*} [cmdstat set]
  49. assert_match {*calls=100,*} [cmdstat get]
  50. assert_match {*calls=100,*} [cmdstat incr]
  51. # lpush total calls are 2*issued commands per test due to the lrange tests
  52. assert_match {*calls=200,*} [cmdstat lpush]
  53. assert_match {*calls=100,*} [cmdstat rpush]
  54. assert_match {*calls=100,*} [cmdstat lpop]
  55. assert_match {*calls=100,*} [cmdstat rpop]
  56. assert_match {*calls=100,*} [cmdstat sadd]
  57. assert_match {*calls=100,*} [cmdstat hset]
  58. assert_match {*calls=100,*} [cmdstat spop]
  59. assert_match {*calls=100,*} [cmdstat zadd]
  60. assert_match {*calls=100,*} [cmdstat zpopmin]
  61. assert_match {*calls=400,*} [cmdstat lrange]
  62. assert_match {*calls=100,*} [cmdstat mset]
  63. # assert one of the non benchmarked commands is not present
  64. assert_match {} [cmdstat rpoplpush]
  65. }
  66. test {benchmark: multi-thread set,get} {
  67. set cmd [redisbenchmark $master_host $master_port "--threads 10 -c 5 -n 10 -t set,get"]
  68. common_bench_setup $cmd
  69. default_set_get_checks
  70. # ensure only one key was populated
  71. assert_match {1} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
  72. }
  73. test {benchmark: pipelined full set,get} {
  74. set cmd [redisbenchmark $master_host $master_port "-P 5 -c 10 -n 10010 -t set,get"]
  75. common_bench_setup $cmd
  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. set cmd [redisbenchmark $master_host $master_port "-c 5 -n 150 INCRBYFLOAT mykey 10.0"]
  85. common_bench_setup $cmd
  86. assert_match {*calls=150,*} [cmdstat incrbyfloat]
  87. # assert one of the non benchmarked commands is not present
  88. assert_match {} [cmdstat get]
  89. # ensure only one key was populated
  90. assert_match {1} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
  91. }
  92. test {benchmark: keyspace length} {
  93. set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000"]
  94. common_bench_setup $cmd
  95. assert_match {*calls=1000,*} [cmdstat set]
  96. # assert one of the non benchmarked commands is not present
  97. assert_match {} [cmdstat get]
  98. # ensure the keyspace has the desired size
  99. assert_match {50} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
  100. }
  101. # tls specific tests
  102. if {$::tls} {
  103. test {benchmark: specific tls-ciphers} {
  104. set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000 --tls-ciphers \"DEFAULT:-AES128-SHA256\""]
  105. common_bench_setup $cmd
  106. assert_match {*calls=1000,*} [cmdstat set]
  107. # assert one of the non benchmarked commands is not present
  108. assert_match {} [cmdstat get]
  109. }
  110. test {benchmark: tls connecting using URI with authentication set,get} {
  111. r config set masterauth pass
  112. set cmd [redisbenchmarkuriuserpass $master_host $master_port "default" pass "-c 5 -n 10 -t set,get"]
  113. common_bench_setup $cmd
  114. default_set_get_checks
  115. }
  116. test {benchmark: specific tls-ciphersuites} {
  117. r flushall
  118. r config resetstat
  119. set ciphersuites_supported 1
  120. set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000 --tls-ciphersuites \"TLS_AES_128_GCM_SHA256\""]
  121. if {[catch { exec {*}$cmd } error]} {
  122. set first_line [lindex [split $error "\n"] 0]
  123. if {[string match "*Invalid option*" $first_line]} {
  124. set ciphersuites_supported 0
  125. if {$::verbose} {
  126. puts "Skipping test, TLSv1.3 not supported."
  127. }
  128. } else {
  129. puts [colorstr red "redis-benchmark non zero code. first line: $first_line"]
  130. fail "redis-benchmark non zero code. first line: $first_line"
  131. }
  132. }
  133. if {$ciphersuites_supported} {
  134. assert_match {*calls=1000,*} [cmdstat set]
  135. # assert one of the non benchmarked commands is not present
  136. assert_match {} [cmdstat get]
  137. }
  138. }
  139. }
  140. }
  141. }