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
f35abe2f
Commit
f35abe2f
authored
Jul 01, 2014
by
antirez
Browse files
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.
parent
83beaa88
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/latency.c
View file @
f35abe2f
...
@@ -69,6 +69,8 @@ void latencyMonitorInit(void) {
...
@@ -69,6 +69,8 @@ void latencyMonitorInit(void) {
* server.latency_monitor_threshold. */
* server.latency_monitor_threshold. */
void
latencyAddSample
(
char
*
event
,
mstime_t
latency
)
{
void
latencyAddSample
(
char
*
event
,
mstime_t
latency
)
{
struct
latencyTimeSeries
*
ts
=
dictFetchValue
(
server
.
latency_events
,
event
);
struct
latencyTimeSeries
*
ts
=
dictFetchValue
(
server
.
latency_events
,
event
);
time_t
now
=
time
(
NULL
);
int
prev
;
/* Create the time series if it does not exist. */
/* Create the time series if it does not exist. */
if
(
ts
==
NULL
)
{
if
(
ts
==
NULL
)
{
...
@@ -79,6 +81,15 @@ void latencyAddSample(char *event, mstime_t latency) {
...
@@ -79,6 +81,15 @@ void latencyAddSample(char *event, mstime_t latency) {
dictAdd
(
server
.
latency_events
,
zstrdup
(
event
),
ts
);
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
].
time
=
time
(
NULL
);
ts
->
samples
[
ts
->
idx
].
latency
=
latency
;
ts
->
samples
[
ts
->
idx
].
latency
=
latency
;
if
(
latency
>
ts
->
max
)
ts
->
max
=
latency
;
if
(
latency
>
ts
->
max
)
ts
->
max
=
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