summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-07-01 17:12:09 +0200
committerantirez <antirez@gmail.com>2014-07-18 12:20:55 +0200
commit372484ab8e52d764356855f7f462c5d5365d541d (patch)
tree654fc3cf59dcfaced9fd5f0bba441e857afc12f5
parent5e5659019880be65e3fbea537b78ba21c4a28eb3 (diff)
downloadredis-372484ab8e52d764356855f7f462c5d5365d541d.tar.gz
Latency monitor: don't add new samples in the same second.
Instead we update the old sample with the new latency if it is greater.
-rw-r--r--src/latency.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/latency.c b/src/latency.c
index 198036df3..649381efc 100644
--- a/src/latency.c
+++ b/src/latency.c
@@ -69,6 +69,8 @@ void latencyMonitorInit(void) {
* server.latency_monitor_threshold. */
void latencyAddSample(char *event, mstime_t latency) {
struct latencyTimeSeries *ts = dictFetchValue(server.latency_events,event);
+ time_t now = time(NULL);
+ int prev;
/* Create the time series if it does not exist. */
if (ts == NULL) {
@@ -79,6 +81,15 @@ void latencyAddSample(char *event, mstime_t latency) {
dictAdd(server.latency_events,zstrdup(event),ts);
}
+ /* If the previous sample is in the same second, we update our old sample
+ * if this latency is > of the old one, or just return. */
+ prev = (ts->idx + LATENCY_TS_LEN - 1) % LATENCY_TS_LEN;
+ if (ts->samples[prev].time == now) {
+ if (latency > ts->samples[prev].latency)
+ ts->samples[prev].latency = latency;
+ return;
+ }
+
ts->samples[ts->idx].time = time(NULL);
ts->samples[ts->idx].latency = latency;
if (latency > ts->max) ts->max = latency;