Skip to content
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

Merged
merged 6 commits into from Oct 10, 2017

Conversation

rpv-tomsk
Copy link
Contributor

@rpv-tomsk rpv-tomsk commented Jul 30, 2017

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.

hitratio

The value of hitratio is calculated as get_hits / cmd_get , unlike the rest, incr_hitratio and decr_hitratio, which are calculated like incr_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 new get_* stats was added in memcached: the get_expired in memcached-1.4.26 , and get_flushed in memcached-1.4.28, so that unification cannot be applied.

@rpv-tomsk rpv-tomsk changed the title memcached: Fix hitratio reporting, report connections rate memcached: Fix hitratio reporting, add connections rate report Jul 30, 2017
@rpv-tomsk
Copy link
Contributor Author

Ping.

Copy link
Member

@octo octo left a 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,
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to ..._ratio_percent.

Copy link
Contributor Author

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,
Copy link
Member

@octo octo Sep 26, 2017

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?

Copy link
Contributor Author

@rpv-tomsk rpv-tomsk Sep 26, 2017

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?

Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, SGTM

@octo octo added the Bug A genuine bug label Sep 26, 2017
@octo
Copy link
Member

octo commented Sep 26, 2017

FYI, I've cherry-picked 7590014 as 66ac89c.

@octo octo added this to the 5.8 milestone Oct 6, 2017
Pavel Rochnyack added 3 commits October 9, 2017 17:23
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.
@rpv-tomsk
Copy link
Contributor Author

rpv-tomsk commented Oct 9, 2017

Hi, Florian!

I updated this. All suggestions are accepted except proposal of value_to_rate() usage (see inline comment).

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)) {
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, SGTM

Copy link
Member

@octo octo left a 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!

Pavel Rochnyack added 2 commits October 10, 2017 01:37
If there is no requests, NAN is reported as hitratio.
If there is no hits - zero is reported.
Copy link
Member

@octo octo left a 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!

@octo octo merged commit 60bc9b5 into collectd:master Oct 10, 2017
@rpv-tomsk rpv-tomsk deleted the fix-memcached branch October 31, 2018 17:21
@octo octo added Fix A pull request fixing a bug and removed Bug A genuine bug labels Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix A pull request fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants