mirror of
https://github.com/fluencelabs/redis
synced 2025-04-01 23:31:03 +00:00
Latency: low level time series analysis implemented.
This commit is contained in:
parent
b2604dc58c
commit
19853db892
@ -122,6 +122,56 @@ int latencyResetEvent(char *event_to_reset) {
|
|||||||
return resets;
|
return resets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------ Latency reporting (doctor) ---------------------- */
|
||||||
|
|
||||||
|
/* Analyze the samples avaialble for a given event and return a structure
|
||||||
|
* populate with different metrics, average, MAD, min, max, and so forth.
|
||||||
|
* Check latency.h definition of struct latenctStat for more info.
|
||||||
|
* If the specified event has no elements the structure is populate with
|
||||||
|
* zero values. */
|
||||||
|
void analyzeLatencyForEvent(char *event, struct latencyStats *ls) {
|
||||||
|
struct latencyTimeSeries *ts = dictFetchValue(server.latency_events,event);
|
||||||
|
int j;
|
||||||
|
uint64_t sum;
|
||||||
|
|
||||||
|
ls->all_time_high = ts ? ts->max : 0;
|
||||||
|
ls->avg = 0;
|
||||||
|
ls->min = 0;
|
||||||
|
ls->max = 0;
|
||||||
|
ls->mad = 0;
|
||||||
|
ls->samples = 0;
|
||||||
|
if (!ts) return;
|
||||||
|
|
||||||
|
/* First pass, populate everything but the MAD. */
|
||||||
|
sum = 0;
|
||||||
|
for (j = 0; j < LATENCY_TS_LEN; j++) {
|
||||||
|
if (ts->samples[j].time == 0) continue;
|
||||||
|
ls->samples++;
|
||||||
|
if (ls->samples == 1) {
|
||||||
|
ls->min = ls->max = ts->samples[j].latency;
|
||||||
|
} else {
|
||||||
|
if (ls->min > ts->samples[j].latency)
|
||||||
|
ls->min = ts->samples[j].latency;
|
||||||
|
if (ls->max < ts->samples[j].latency)
|
||||||
|
ls->max = ts->samples[j].latency;
|
||||||
|
}
|
||||||
|
sum += ts->samples[j].latency;
|
||||||
|
}
|
||||||
|
if (ls->samples) ls->avg = sum / ls->samples;
|
||||||
|
|
||||||
|
/* Second pass, compute MAD. */
|
||||||
|
sum = 0;
|
||||||
|
for (j = 0; j < LATENCY_TS_LEN; j++) {
|
||||||
|
int64_t delta;
|
||||||
|
|
||||||
|
if (ts->samples[j].time == 0) continue;
|
||||||
|
delta = ls->avg - ts->samples[j].latency;
|
||||||
|
if (delta < 0) delta = -delta;
|
||||||
|
sum += delta;
|
||||||
|
}
|
||||||
|
if (ls->samples) ls->mad = sum / ls->samples;
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------------------- Latency command implementation -------------------- */
|
/* ---------------------- Latency command implementation -------------------- */
|
||||||
|
|
||||||
/* latencyCommand() helper to produce a time-delay reply for all the samples
|
/* latencyCommand() helper to produce a time-delay reply for all the samples
|
||||||
|
@ -50,6 +50,16 @@ struct latencyTimeSeries {
|
|||||||
struct latencySample samples[LATENCY_TS_LEN]; /* Latest history. */
|
struct latencySample samples[LATENCY_TS_LEN]; /* Latest history. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Latency statistics structure. */
|
||||||
|
struct latencyStats {
|
||||||
|
uint32_t all_time_high; /* Absolute max observed since latest reset. */
|
||||||
|
uint32_t avg; /* Average of current samples. */
|
||||||
|
uint32_t min; /* Min of current samples. */
|
||||||
|
uint32_t max; /* Max of current samples. */
|
||||||
|
uint32_t mad; /* Mean absolute deviation. */
|
||||||
|
uint32_t samples; /* Number of non-zero samples. */
|
||||||
|
};
|
||||||
|
|
||||||
void latencyMonitorInit(void);
|
void latencyMonitorInit(void);
|
||||||
void latencyAddSample(char *event, mstime_t latency);
|
void latencyAddSample(char *event, mstime_t latency);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user