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

[varnishstat] reset running averages #4274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gquintard
Copy link
Member

I've been running benchmark tests these last few days, and I've been wishing to be able to reset the average calculations without having to restart varnishncsa, so here we go.

I've been running benchmark tests these last few days, and I've been
wishing to be able to reset the average calculations without having to
restart `varnishncsa`, so here we go.
@dridi dridi changed the title [varnishncsa] reset running averages [varnishstat] reset running averages Feb 14, 2025
@dridi dridi changed the title [varnishstat] reset running averages [varnishncsa] reset running averages Feb 14, 2025
@dridi
Copy link
Member

dridi commented Feb 14, 2025

Please remove all mentions to varnishncsa, this is varnishstat.

@gquintard
Copy link
Member Author

Ah yes, of course

@dridi
Copy link
Member

dridi commented Feb 14, 2025

Please also make it two commits, it's easier to back-port to any branch without the guaranteed conflict in the changelog.

@dridi
Copy link
Member

dridi commented Feb 14, 2025

I accidentally submitted the previous comment, I meant to also ask for basic test coverage.

Comment on lines -319 to +332
sample_points();
sample_hitrate();
sample_points(reset_averages);
sample_hitrate(reset_averages);
reset_averages = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why pass reset_averages to the sample_*() functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

this was a quick 10 minutes job, and I assumed the key presses could come at any given time and wanted to avoid different counters from being handled differently, but I see the wgetch() call now, I can indeed use the global variable

Copy link
Member

Choose a reason for hiding this comment

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

It's single-threaded, you are fine with globals :)

Comment on lines +314 to 321
if (reset) {
hitrate.hr_10.n = 0;
hitrate.hr_100.n = 0;
hitrate.hr_1000.n = 0;
}
update_ma(&hitrate.hr_10, ratio);
update_ma(&hitrate.hr_100, ratio);
update_ma(&hitrate.hr_1000, ratio);
Copy link
Member

Choose a reason for hiding this comment

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

Here you could use reset_averages directly.

Comment on lines -265 to 273
if (pt->t_last)
if (reset) {
pt->chg = 0;
pt->ma_10.n = 0;
pt->ma_100.n = 0;
pt->ma_1000.n = 0;
} else if (pt->t_last)
pt->chg = ((int64_t)pt->cur - (int64_t)pt->last) /
(pt->t_cur - pt->t_last);
Copy link
Member

Choose a reason for hiding this comment

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

To be consistent with the block of code from my previous comment, shouldn't it look like this?

if (reset) { // or better: if (reset_averages)
	pt->chg = 0;
	pt->ma_10.n = 0;
	pt->ma_100.n = 0;
	pt->ma_1000.n = 0;
}

if (pt->t_last) {
	pt->chg = ((int64_t)pt->cur - (int64_t)pt->last) /
	    (pt->t_cur - pt->t_last);
}

For the hit ratio you reset the 10/100/1000 averages and let them be updated in the same iteration. So for consistency you should give the counters a chance to be updated too.

@bsdphk bsdphk changed the title [varnishncsa] reset running averages [varnishstat] reset running averages Feb 17, 2025
@nigoroll
Copy link
Member

I like phk's idea to use the 0 key to reset the averages.
Other than that, bugwash is +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants