Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
19853db8
Commit
19853db8
authored
Jul 07, 2014
by
antirez
Browse files
Latency: low level time series analysis implemented.
parent
b2604dc5
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/latency.c
View file @
19853db8
...
...
@@ -122,6 +122,56 @@ int latencyResetEvent(char *event_to_reset) {
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 -------------------- */
/* latencyCommand() helper to produce a time-delay reply for all the samples
...
...
src/latency.h
View file @
19853db8
...
...
@@ -50,6 +50,16 @@ struct latencyTimeSeries {
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
latencyAddSample
(
char
*
event
,
mstime_t
latency
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment