summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorfilipe oliveira <filipecosta.90@gmail.com>2022-01-05 12:01:05 +0000
committerGitHub <noreply@github.com>2022-01-05 14:01:05 +0200
commit5dd15443ac755d9ad2a22aa8c341b25d3de82eb4 (patch)
tree96123aeae3e692d6401b8e0138a81b65a206b19f /src/config.c
parent4d3c4cfac70557a28a62266543951d46d0cae584 (diff)
downloadredis-5dd15443ac755d9ad2a22aa8c341b25d3de82eb4.tar.gz
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: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index 1a7337883..6dd4cc844 100644
--- a/src/config.c
+++ b/src/config.c
@@ -2660,6 +2660,71 @@ int allowProtectedAction(int config, client *c) {
(config == PROTECTED_ACTION_ALLOWED_LOCAL && islocalClient(c));
}
+
+static int setConfigLatencyTrackingInfoPercentilesOutputOption(typeData data, sds *argv, int argc, const char **err) {
+ UNUSED(data);
+ zfree(server.latency_tracking_info_percentiles);
+ server.latency_tracking_info_percentiles = NULL;
+ server.latency_tracking_info_percentiles_len = argc;
+
+ /* Special case: treat single arg "" as zero args indicating empty percentile configuration */
+ if (argc == 1 && sdslen(argv[0]) == 0)
+ server.latency_tracking_info_percentiles_len = 0;
+ else
+ server.latency_tracking_info_percentiles = zmalloc(sizeof(double)*argc);
+
+ for (int j = 0; j < server.latency_tracking_info_percentiles_len; j++) {
+ double percentile;
+ if (!string2d(argv[j], sdslen(argv[j]), &percentile)) {
+ *err = "Invalid latency-tracking-info-percentiles parameters";
+ goto configerr;
+ }
+ if (percentile > 100.0 || percentile < 0.0) {
+ *err = "latency-tracking-info-percentiles parameters should sit between [0.0,100.0]";
+ goto configerr;
+ }
+ server.latency_tracking_info_percentiles[j] = percentile;
+ }
+
+ return 1;
+configerr:
+ zfree(server.latency_tracking_info_percentiles);
+ server.latency_tracking_info_percentiles = NULL;
+ server.latency_tracking_info_percentiles_len = 0;
+ return 0;
+}
+
+static sds getConfigLatencyTrackingInfoPercentilesOutputOption(typeData data) {
+ UNUSED(data);
+ sds buf = sdsempty();
+ for (int j = 0; j < server.latency_tracking_info_percentiles_len; j++) {
+ buf = sdscatprintf(buf,"%f",
+ server.latency_tracking_info_percentiles[j]);
+ if (j != server.latency_tracking_info_percentiles_len-1)
+ buf = sdscatlen(buf," ",1);
+ }
+ return buf;
+}
+
+/* Rewrite the latency-tracking-info-percentiles option. */
+void rewriteConfigLatencyTrackingInfoPercentilesOutputOption(typeData data, const char *name, struct rewriteConfigState *state) {
+ UNUSED(data);
+ sds line = sdsnew(name);
+ /* Rewrite latency-tracking-info-percentiles parameters,
+ * or an empty 'latency-tracking-info-percentiles ""' line to avoid the
+ * defaults from being used.
+ */
+ if (!server.latency_tracking_info_percentiles_len) {
+ line = sdscat(line," \"\"");
+ } else {
+ for (int j = 0; j < server.latency_tracking_info_percentiles_len; j++) {
+ line = sdscatprintf(line," %f",
+ server.latency_tracking_info_percentiles[j]);
+ }
+ }
+ rewriteConfigRewriteLine(state,name,line,1);
+}
+
standardConfig configs[] = {
/* Bool configs */
createBoolConfig("rdbchecksum", NULL, IMMUTABLE_CONFIG, server.rdb_checksum, 1, NULL, NULL),
@@ -2705,6 +2770,7 @@ standardConfig configs[] = {
createBoolConfig("disable-thp", NULL, MODIFIABLE_CONFIG, server.disable_thp, 1, NULL, NULL),
createBoolConfig("cluster-allow-replica-migration", NULL, MODIFIABLE_CONFIG, server.cluster_allow_replica_migration, 1, NULL, NULL),
createBoolConfig("replica-announced", NULL, MODIFIABLE_CONFIG, server.replica_announced, 1, NULL, NULL),
+ createBoolConfig("latency-tracking", NULL, MODIFIABLE_CONFIG, server.latency_tracking_enabled, 1, NULL, NULL),
createBoolConfig("aof-disable-auto-gc", NULL, MODIFIABLE_CONFIG, server.aof_disable_auto_gc, 0, NULL, updateAofAutoGCEnabled),
/* String Configs */
@@ -2857,6 +2923,7 @@ standardConfig configs[] = {
createSpecialConfig("notify-keyspace-events", NULL, MODIFIABLE_CONFIG, setConfigNotifyKeyspaceEventsOption, getConfigNotifyKeyspaceEventsOption, rewriteConfigNotifyKeyspaceEventsOption, NULL),
createSpecialConfig("bind", NULL, MODIFIABLE_CONFIG | MULTI_ARG_CONFIG, setConfigBindOption, getConfigBindOption, rewriteConfigBindOption, applyBind),
createSpecialConfig("replicaof", "slaveof", IMMUTABLE_CONFIG | MULTI_ARG_CONFIG, setConfigReplicaOfOption, getConfigReplicaOfOption, rewriteConfigReplicaOfOption, NULL),
+ createSpecialConfig("latency-tracking-info-percentiles", NULL, MODIFIABLE_CONFIG | MULTI_ARG_CONFIG, setConfigLatencyTrackingInfoPercentilesOutputOption, getConfigLatencyTrackingInfoPercentilesOutputOption, rewriteConfigLatencyTrackingInfoPercentilesOutputOption, NULL),
/* NULL Terminator */
{NULL}