New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memcached: Fix hitratio reporting, add connections rate report #2385
Conversation
Ping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rpv-tomsk, thanks for fixing this :)
src/memcached.c
Outdated
@@ -285,6 +297,47 @@ static void submit_gauge2(const char *type, const char *type_inst, | |||
plugin_dispatch_values(&vl); | |||
} | |||
|
|||
static gauge_t calculate_rate(gauge_t part, gauge_t total, gauge_t *prev_part, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize you copied this from the previous implementation, but "rate" is incorrect and confusing. What you're calculating here is a ratio.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed.
src/memcached.c
Outdated
if (num == 0 || denom == 0) | ||
return 0; | ||
|
||
return 100.0 * num / denom; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either rename this function to …_ratio
and return num / denom
here, or use …_ratio_percent
and return 100.0 * num / denom
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to ..._ratio_percent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to .._ratio_percent
.
src/memcached.c
Outdated
@@ -285,6 +297,47 @@ static void submit_gauge2(const char *type, const char *type_inst, | |||
plugin_dispatch_values(&vl); | |||
} | |||
|
|||
static gauge_t calculate_rate(gauge_t part, gauge_t total, gauge_t *prev_part, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it a bit unintuitive that you're effectively calculating the rate of gauge_t
. It looks like the raw metrics are integers, can you change these functions to take derive_t
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current code has following variable declarations:
gauge_t hits = NAN;
gauge_t gets = NAN;
gauge_t incr_hits = NAN;
e8fdf93#diff-e842cfa6e2070dbfa4c72d77b5b2fc71R351
These variables are passed to calculate_ratio()
and calculate_ratio2()
functions, so they take gauge_t
type as as argument. What to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert those variables to derive_t
, too. I'm fairly certain they were only gauge_t
so rate = 100.0 * hits / gets;
could be calculated without a cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, variables converted to derive_t
.
src/memcached.c
Outdated
*prev_total = total; | ||
|
||
if (num == 0 || denom == 0) | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there were no requests, the ratio should be NAN
, not zero. Otherwise this will skew e.g. averages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks!
src/memcached.c
Outdated
@@ -285,6 +297,47 @@ static void submit_gauge2(const char *type, const char *type_inst, | |||
plugin_dispatch_values(&vl); | |||
} | |||
|
|||
static gauge_t calculate_rate(gauge_t part, gauge_t total, gauge_t *prev_part, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using value_to_rate()
to convert both, "part" and "total" to a rate and then simply calculating the ratio as part_rate / total_rate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to leave this untouched. I think use of value_to_rate()
is excessive for this task.
That adds time calculations, which will be reducted later as the numerator and denominator will have a same value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, SGTM
When Collectd calculates 'hitratio', it divides two continiously-grown values of Memcached stats. As result, reported metric contains the average since Memcached start, which is incorrect.
7590014
to
c70e4fd
Compare
Hi, Florian! I updated this. All suggestions are accepted except proposal of Thanks for a review. |
src/memcached.c
Outdated
|
||
static gauge_t calculate_ratio_percent2(derive_t part1, derive_t part2, | ||
derive_t *prev1, derive_t *prev2) { | ||
if (isnan(*prev1) || isnan(*prev2) || (part1 < *prev1) || (part2 < *prev2)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/memcached.c: In function 'calculate_ratio_percent2':
src/memcached.c:417:3: error: non-floating-point argument in call to function '__builtin_isnan'
if (isnan(*prev1) || isnan(*prev2) || (part1 < *prev1) || (part2 < *prev2)) {
^
I think (*prev1 == 0) || (*prev2 == 0)
should do the trick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for a notice ;-)
src/memcached.c
Outdated
@@ -285,6 +297,47 @@ static void submit_gauge2(const char *type, const char *type_inst, | |||
plugin_dispatch_values(&vl); | |||
} | |||
|
|||
static gauge_t calculate_rate(gauge_t part, gauge_t total, gauge_t *prev_part, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, SGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI surfaced an issue. With that fixes this is good to do. Thanks @rpv-tomsk!
48af83e
to
cb48bb1
Compare
If there is no requests, NAN is reported as hitratio. If there is no hits - zero is reported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @rpv-tomsk!
When Collectd calculates 'hitratio', it divides two continiously-grown values.
So, reported metric contains the average since 'memcached' start, which is incorrect.
Collectd should report actual hitratio, not average for weeks-months-years.
The second commit adds connections rate reporting.
The value of
hitratio
is calculated asget_hits / cmd_get
, unlike the rest,incr_hitratio
anddecr_hitratio
, which are calculated likeincr_hits / (incr_hits + incr_misses)
.The
get_hits / (get_hits + get_misses)
formula may be used to unify the code, if use only these variables. But newget_*
stats was added in memcached: theget_expired
in memcached-1.4.26 , andget_flushed
in memcached-1.4.28, so that unification cannot be applied.