-
Notifications
You must be signed in to change notification settings - Fork 3
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: improved stat5minClientRequests() naming #275
Changes from 1 commit
9145a8f
90aa746
b50d546
f936f71
e2478f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1684,11 +1684,15 @@ snmpStatGet(int minutes) | |||||||||||
return &CountHist[minutes]; | ||||||||||||
} | ||||||||||||
|
||||||||||||
int | ||||||||||||
stat5minClientRequests(void) | ||||||||||||
bool | ||||||||||||
statSawRecentRequests() | ||||||||||||
{ | ||||||||||||
assert(N_COUNT_HIST > 5); | ||||||||||||
return statCounter.client_http.requests - CountHist[5].client_http.requests; | ||||||||||||
static const int recentMinutes = 5; | ||||||||||||
assert(N_COUNT_HIST > recentMinutes); | ||||||||||||
|
||||||||||||
if (NCountHist > recentMinutes) | ||||||||||||
rousskov marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's document why this math is not precise:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||||||||
return statCounter.client_http.requests - CountHist[recentMinutes].client_http.requests; | ||||||||||||
return 0; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of recent requests within the first few minutes of Squid process live is not always zero, right?
Suggested change
Alternatively, we can use this pattern (that reduces statCounter duplication): const auto oldRequests = (NCountHist > recentMinutes) ? CountHist[recentMinutes].client_http.requests : 0;
return statCounter.client_http.requests - oldRequests; Your call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right, but I thought that since this function cannot produce a meaningful result within these initial few minutes, it should not confuse the caller (which will proceed refreshing DNS). Theoretically, this function could return an 'optional', and the caller would wait in 'zero' and 'undefined' outcomes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I disagree with that assertion. Both true and false statSawRecentRequests() outcomes during the first few minutes seem perfectly meaningful to me (regardless of how an existing or future caller may use those outcomes).
Refreshing code that triggers a refresh just because statSawRecentRequests() returned true is confused for other reasons. No reasonable caller will refresh just because statSawRecentRequests() returned true! Refreshing code that avoids a refresh just because statSawRecentRequests() returned false is reasonable and will not malfunction (or, to be more precise, any malfunction is outside this discussion scope). In both cases, this function will not cause or create confusion where none existed.
That would be a good strategy for a function designed to classify cases where there were no requests for the first X minutes as "cannot tell; have to wait for X minutes to pass". Such a function should be named something like statSawRequestsDuringLastXminutes() so that the caller can correctly handle its dependency on X. I see no reason to complicate our function right now. The vagueness of "recent" allows it to produce correct boolean result at any time. The caller is not dependent on any specific X value -- the caller should work correctly after sleeping for any reasonable (for that caller!) time between calls as long as that caller is OK with vague "recent" definition (e.g., because the caller sleeps for periods that ought to exceed statistics collection periods by a lot). And changing statistics collection interval to any reasonable value will not affect any such caller. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||||||||||||
} | ||||||||||||
|
||||||||||||
static double | ||||||||||||
|
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.
AAA if possible:
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.
Done.