Unverified Commit 5dd15443 authored by filipe oliveira's avatar filipe oliveira Committed by GitHub
Browse files

Added INFO LATENCYSTATS section: latency by percentile distribution/latency by...


Added INFO LATENCYSTATS section: latency by percentile distribution/latency by cumulative distribution of latencies (#9462)

# Short description

The Redis extended latency stats track per command latencies and enables:
- exporting the per-command percentile distribution via the `INFO LATENCYSTATS` command.
  **( percentile distribution is not mergeable between cluster nodes ).**
- exporting the per-command cumulative latency distributions via the `LATENCY HISTOGRAM` command.
  Using the cumulative distribution of latencies we can merge several stats from different cluster nodes
  to calculate aggregate metrics .

By default, the extended latency monitoring is enabled since the overhead of keeping track of the
command latency is very small.
 
If you don't want to track extended latency metrics, you can easily disable it at runtime using the command:
 - `CONFIG SET latency-tracking no`

By default, the exported latency percentiles are the p50, p99, and p999.
You can alter them at runtime using the command:
- `CONFIG SET latency-tracking-info-percentiles "0.0 50.0 100.0"`


## Some details:
- The total size per histogram should sit around 40 KiB. We only allocate those 40KiB when a command
  was called for the first time.
- With regards to the WRITE overhead As seen below, there is no measurable overhead on the achievable
  ops/sec or full latency spectrum on the client. Including also the measured redis-benchmark for unstable
  vs this branch. 
- We track from 1 nanosecond to 1 second ( everything above 1 second is considered +Inf )

## `INFO LATENCYSTATS` exposition format

   - Format: `latency_percentiles_usec_<CMDNAME>:p0=XX,p50....` 

## `LATENCY HISTOGRAM [command ...]` exposition format

Return a cumulative distribution of latencies in the format of a histogram for the specified command names.

The histogram is composed of a map of time buckets:
- Each representing a latency range, between 1 nanosecond and roughly 1 second.
- Each bucket covers twice the previous bucket's range.
- Empty buckets are not printed.
- Everything above 1 sec is considered +Inf.
- At max there will be log2(1000000000)=30 buckets

We reply a map for each command in the format:
`<command name> : { `calls`: <total command calls> , `histogram` : { <bucket 1> : latency , < bucket 2> : latency, ...  } }`
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
parent 4d3c4cfa
proc latency_histogram {cmd} {
return [lindex [r latency histogram $cmd] 1]
}
start_server {tags {"latency-monitor needs:latency"}} { start_server {tags {"latency-monitor needs:latency"}} {
# Set a threshold high enough to avoid spurious latency events. # Set a threshold high enough to avoid spurious latency events.
r config set latency-monitor-threshold 200 r config set latency-monitor-threshold 200
r latency reset r latency reset
test {LATENCY HISTOGRAM with empty histogram} {
r config resetstat
assert_match {} [latency_histogram set]
assert {[llength [r latency histogram]] == 0}
}
test {LATENCY HISTOGRAM all commands} {
r config resetstat
r set a b
r set c d
assert_match {calls 2 histogram_usec *} [latency_histogram set]
}
test {LATENCY HISTOGRAM with a subset of commands} {
r config resetstat
r set a b
r set c d
r get a
r hset f k v
r hgetall f
assert_match {calls 2 histogram_usec *} [latency_histogram set]
assert_match {calls 1 histogram_usec *} [latency_histogram hset]
assert_match {calls 1 histogram_usec *} [latency_histogram hgetall]
assert_match {calls 1 histogram_usec *} [latency_histogram get]
assert {[llength [r latency histogram]] == 8}
assert {[llength [r latency histogram set get]] == 4}
}
test {LATENCY HISTOGRAM command} {
r config resetstat
r set a b
r get a
assert {[llength [r latency histogram]] == 4}
assert {[llength [r latency histogram set get]] == 4}
}
test {LATENCY HISTOGRAM with wrong command name skips the invalid one} {
r config resetstat
assert {[llength [r latency histogram blabla]] == 0}
assert {[llength [r latency histogram blabla blabla2 set get]] == 0}
r set a b
r get a
assert_match {calls 1 histogram_usec *} [lindex [r latency histogram blabla blabla2 set get] 1]
assert_match {calls 1 histogram_usec *} [lindex [r latency histogram blabla blabla2 set get] 3]
assert {[string length [r latency histogram blabla set get]] > 0}
}
test {Test latency events logging} { test {Test latency events logging} {
r debug sleep 0.3 r debug sleep 0.3
after 1100 after 1100
......
...@@ -326,6 +326,10 @@ proc test_slave_buffers {test_name cmd_count payload_len limit_memory pipeline} ...@@ -326,6 +326,10 @@ proc test_slave_buffers {test_name cmd_count payload_len limit_memory pipeline}
$master config set client-output-buffer-limit "replica 100000000 100000000 300" $master config set client-output-buffer-limit "replica 100000000 100000000 300"
$master config set repl-backlog-size [expr {10*1024}] $master config set repl-backlog-size [expr {10*1024}]
# disable latency tracking
$master config set latency-tracking no
$slave config set latency-tracking no
$slave slaveof $master_host $master_port $slave slaveof $master_host $master_port
wait_for_condition 50 100 { wait_for_condition 50 100 {
[s 0 master_link_status] eq {up} [s 0 master_link_status] eq {up}
...@@ -412,6 +416,7 @@ test_slave_buffers "replica buffer don't induce eviction" 100000 100 1 0 ...@@ -412,6 +416,7 @@ test_slave_buffers "replica buffer don't induce eviction" 100000 100 1 0
start_server {tags {"maxmemory external:skip"}} { start_server {tags {"maxmemory external:skip"}} {
test {Don't rehash if used memory exceeds maxmemory after rehash} { test {Don't rehash if used memory exceeds maxmemory after rehash} {
r config set latency-tracking no
r config set maxmemory 0 r config set maxmemory 0
r config set maxmemory-policy allkeys-random r config set maxmemory-policy allkeys-random
...@@ -432,6 +437,7 @@ start_server {tags {"maxmemory external:skip"}} { ...@@ -432,6 +437,7 @@ start_server {tags {"maxmemory external:skip"}} {
start_server {tags {"maxmemory external:skip"}} { start_server {tags {"maxmemory external:skip"}} {
test {client tracking don't cause eviction feedback loop} { test {client tracking don't cause eviction feedback loop} {
r config set latency-tracking no
r config set maxmemory 0 r config set maxmemory 0
r config set maxmemory-policy allkeys-lru r config set maxmemory-policy allkeys-lru
r config set maxmemory-eviction-tenacity 100 r config set maxmemory-eviction-tenacity 100
......
...@@ -2,6 +2,10 @@ set testmodule [file normalize tests/modules/blockonbackground.so] ...@@ -2,6 +2,10 @@ set testmodule [file normalize tests/modules/blockonbackground.so]
source tests/support/util.tcl source tests/support/util.tcl
proc latency_percentiles_usec {cmd} {
return [latencyrstat_percentiles $cmd r]
}
start_server {tags {"modules"}} { start_server {tags {"modules"}} {
r module load $testmodule r module load $testmodule
...@@ -16,16 +20,21 @@ start_server {tags {"modules"}} { ...@@ -16,16 +20,21 @@ start_server {tags {"modules"}} {
assert_equal [r slowlog len] 0 assert_equal [r slowlog len] 0
} }
r config resetstat r config resetstat
r config set latency-tracking yes
r config set latency-tracking-info-percentiles "50.0"
r block.debug 200 10000 r block.debug 200 10000
if {!$::no_latency} { if {!$::no_latency} {
assert_equal [r slowlog len] 1 assert_equal [r slowlog len] 1
} }
set cmdstatline [cmdrstat block.debug r] set cmdstatline [cmdrstat block.debug r]
set latencystatline_debug [latency_percentiles_usec block.debug]
regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline -> usec usec_per_call
regexp "p50.000000=(.+\..+)" $latencystatline_debug -> p50
assert {$usec >= 100000} assert {$usec >= 100000}
assert {$usec_per_call >= 100000} assert {$usec_per_call >= 100000}
assert {$p50 >= 100000}
} }
test { blocked clients time tracking - check blocked command that uses RedisModule_BlockedClientMeasureTimeStart() is tracking background time even in timeout } { test { blocked clients time tracking - check blocked command that uses RedisModule_BlockedClientMeasureTimeStart() is tracking background time even in timeout } {
......
...@@ -115,6 +115,7 @@ start_server {tags {"obuf-limits external:skip"}} { ...@@ -115,6 +115,7 @@ start_server {tags {"obuf-limits external:skip"}} {
} }
test {No response for single command if client output buffer hard limit is enforced} { test {No response for single command if client output buffer hard limit is enforced} {
r config set latency-tracking no
r config set client-output-buffer-limit {normal 100000 0 0} r config set client-output-buffer-limit {normal 100000 0 0}
# Total size of all items must be more than 100k # Total size of all items must be more than 100k
set item [string repeat "x" 1000] set item [string repeat "x" 1000]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment