Skip to content

Commit

Permalink
Maintenance: improved stat5minClientRequests() naming (#1951)
Browse files Browse the repository at this point in the history
stat5minClientRequests() was to meant to return the number of recent
client requests. However, the function did not provide implied 5 minute
precision. It returned, roughly speaking, the number of requests during
the last 0-6 minutes. The new, less strict function name and boolean
type avoid this false precision implication.

Also removed unused stat5minCPUUsage().
  • Loading branch information
eduard-bagdasaryan authored and squid-anubis committed Dec 1, 2024
1 parent c565067 commit 72f2eff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/neighbors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ peerScheduleDnsRefreshCheck(const double delayInSeconds)
static void
peerDnsRefreshCheck(void *)
{
if (!stat5minClientRequests()) {
if (!statSawRecentRequests()) {
/* no recent client traffic, wait a bit */
peerScheduleDnsRefreshCheck(180.0);
return;
Expand Down
14 changes: 10 additions & 4 deletions src/stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1684,11 +1684,17 @@ 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;
const auto recentMinutes = 5;
assert(N_COUNT_HIST > recentMinutes);

// Math below computes the number of requests during the last 0-6 minutes.
// CountHist is based on "minutes passed since Squid start" periods. It cannot
// deliver precise info for "last N minutes", but we do not need to be precise.
const auto oldRequests = (NCountHist > recentMinutes) ? CountHist[recentMinutes].client_http.requests : 0;
return statCounter.client_http.requests - oldRequests;
}

static double
Expand Down
5 changes: 3 additions & 2 deletions src/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
void statInit(void);
double median_svc_get(int, int);
void pconnHistCount(int, int);
int stat5minClientRequests(void);
double stat5minCPUUsage(void);
/// whether we processed any incoming requests in the last few minutes
/// \sa ClientHttpRequest::updateCounters()
bool statSawRecentRequests();
double statRequestHitRatio(int minutes);
double statRequestHitMemoryRatio(int minutes);
double statRequestHitDiskRatio(int minutes);
Expand Down

0 comments on commit 72f2eff

Please sign in to comment.