2
0

latency-monitor.tcl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. start_server {tags {"latency-monitor"}} {
  2. # Set a threshold high enough to avoid spurious latency events.
  3. r config set latency-monitor-threshold 200
  4. r latency reset
  5. test {Test latency events logging} {
  6. r debug sleep 0.3
  7. after 1100
  8. r debug sleep 0.4
  9. after 1100
  10. r debug sleep 0.5
  11. assert {[r latency history command] >= 3}
  12. }
  13. test {LATENCY HISTORY output is ok} {
  14. set min 250
  15. set max 450
  16. foreach event [r latency history command] {
  17. lassign $event time latency
  18. assert {$latency >= $min && $latency <= $max}
  19. incr min 100
  20. incr max 100
  21. set last_time $time ; # Used in the next test
  22. }
  23. }
  24. test {LATENCY LATEST output is ok} {
  25. foreach event [r latency latest] {
  26. lassign $event eventname time latency max
  27. assert {$eventname eq "command"}
  28. assert {$max >= 450 & $max <= 650}
  29. assert {$time == $last_time}
  30. break
  31. }
  32. }
  33. test {LATENCY HISTORY / RESET with wrong event name is fine} {
  34. assert {[llength [r latency history blabla]] == 0}
  35. assert {[r latency reset blabla] == 0}
  36. }
  37. test {LATENCY DOCTOR produces some output} {
  38. assert {[string length [r latency doctor]] > 0}
  39. }
  40. test {LATENCY RESET is able to reset events} {
  41. assert {[r latency reset] > 0}
  42. assert {[r latency latest] eq {}}
  43. }
  44. test {LATENCY of expire events are correctly collected} {
  45. r config set latency-monitor-threshold 20
  46. r eval {
  47. local i = 0
  48. while (i < 1000000) do
  49. redis.call('sadd','mybigkey',i)
  50. i = i+1
  51. end
  52. } 0
  53. r pexpire mybigkey 1
  54. after 500
  55. assert_match {*expire-cycle*} [r latency latest]
  56. }
  57. }