diff --git a/src/neighbors.cc b/src/neighbors.cc index b8d23db2e09..4f704ae8360 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -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; diff --git a/src/stat.cc b/src/stat.cc index a49efeeada5..476b1e8cb3a 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -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 diff --git a/src/stat.h b/src/stat.h index b8008cf64ae..f83261c7597 100644 --- a/src/stat.h +++ b/src/stat.h @@ -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);