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

Maintenance: update FadingCounter API #1782

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

yadij
Copy link
Contributor

@yadij yadij commented Apr 16, 2024

No description provided.

This value is never changed, so it does not need
to be a modifiable member.

Also, update type to size_t to avoid casting.
This value is only ever used for whole integers of seconds.
It does not need the millisecond resolution.

Hide fully behind accessor methods that preserve the -1/0/+N
semantics of the existing API.
src/FadingCounter.cc Outdated Show resolved Hide resolved
src/FadingCounter.cc Outdated Show resolved Hide resolved
src/FadingCounter.cc Outdated Show resolved Hide resolved
src/FadingCounter.cc Outdated Show resolved Hide resolved
src/FadingCounter.cc Outdated Show resolved Hide resolved
src/FadingCounter.cc Outdated Show resolved Hide resolved
Co-authored-by: Francesco Chemolli <5175948+kinkie@users.noreply.github.com>
@rousskov rousskov self-requested a review April 16, 2024 12:10
Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

AFAICT, this PR introduces runtime bugs, but I am focusing this review on primary API changes: If my horizon type recommendations are followed, those bugs may go away automagically.

Please test FadingCounter configurations with -1, 0, and 1 second horizon parameters before requesting additional reviews.

src/FadingCounter.h Outdated Show resolved Hide resolved
src/FadingCounter.h Outdated Show resolved Hide resolved
FadingCounter();

/// 0=remember nothing; -1=forget nothing; new value triggers clear()
void configure(double horizonSeconds);
void configure(const time_t horizonSeconds);
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are going to change FadingCounter::horizon type, then we should use an std::chrono::duration type.

N.B. I am aware of "This value is only ever used for whole integers of seconds." fact and "It does not need the millisecond resolution." assertion in PR commit e4847b5 message, but neither convince me that limiting future configure() callers to integer numbers is a desirable change because I can imagine callers that would be inconvenienced by it (e.g., callers that have to compute horizon value by dividing some configuration parameters). I do not plan to block this PR because of this added restriction, but I recommend keeping support for fractional seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One step at a time. Using a std::chrono here requires squid.conf parser logic and modifications to the internal logic of FadingCounter. They are explicitly being left to followup PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Using a std::chrono here requires squid.conf parser logic

I seriously doubt that using std::chrono for FadingCounter::horizon requires any squid.conf parser changes, but, if it really does, then FadingCounter::horizon type and similar changes are not compatible with an "Update FadingCounter API" PR (because they require too many out-of-scope changes).

and modifications to the internal logic of FadingCounter.

I do not think so, but our definitions of "internal logic" may differ.

They are explicitly being left to followup PR.

In summary, it is totally fine to postpone conversion of FadingCounter internals to std::chrono beyond this PR as long as this PR does not change FadingCounter::horizon type (or contains other similar internal FadingCounter changes that are difficult to do correctly, especially without std::chrono help).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FadingCounter::horizon is set by several configuration options. Currently they use parse_time(). I do not want to extend scope of this specific PR outside of FadingCounter.

Copy link
Contributor

Choose a reason for hiding this comment

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

FadingCounter::horizon is set by several configuration options. Currently they use parse_time(). I do not want to extend scope of this specific PR outside of FadingCounter.

No such scope extension is requested, required, or implied by this change request. FadingCounter::horizon is configured by FadingCounter::configure(double). One can keep that configuration API intact while converting FadingCounter::horizon to std::chrono::duration. That std::chrono conversion itself is only required if this PR changes FadingCounter::horizon type.

src/FadingCounter.h Outdated Show resolved Hide resolved
@yadij
Copy link
Contributor Author

yadij commented Apr 18, 2024

Please test FadingCounter configurations with -1, 0, and 1 second horizon parameters before requesting additional reviews.

Please add the missing unit-tests for FadingCounter. I have ensured these changes are bug-compatible with existing code.

@rousskov
Copy link
Contributor

rousskov commented Apr 18, 2024

Please test FadingCounter configurations with -1, 0, and 1 second horizon parameters before requesting additional reviews.

Please add the missing unit-tests for FadingCounter. I have ensured these changes are bug-compatible with existing code.

Personally, I do not plan on adding unit-tests for FadingCounter (and I am not sure I agree that they are "missing").

I have ensured these changes are bug-compatible with existing code.

This request is not about existing official code. I strongly suspect that the current PR introduces new bugs in FadingCounter implementation. If my suspicions are correct, then I hope that the requested tests expose those bugs (and prevent them from re-occurring as we refactor PR code to address change requests). I am not asking for anything complex or permanent like official unit tests. I do not even need to see your test code.

{
for (int i = 0; i < precision; ++i)
counters[i] = 0;
std::fill(counters.begin(), counters.end(), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please simplify this code, similar to code this PR already uses to initialize counters during object construction:

Suggested change
std::fill(counters.begin(), counters.end(), 0);
counters = {};

total -= counters[idx];
counters[idx] = 0;
Must(total >= 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This assertion can be preserved if it is moved before total is decremented and adjusted to look like Assure(total >= counters[idx]).

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 removed this and the one below because they seem to exist purely for paranoia reasons and do not appear to be necessary any longer.

@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-for-author author action is expected (and usually required)
Projects
None yet
3 participants