From: Eduard Bagdasaryan Date: Sun, 1 Dec 2024 01:48:10 +0000 (+0000) Subject: Maintenance: improved stat5minClientRequests() naming (#1951) X-Git-Tag: SQUID_7_0_1~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=72f2eff87f041556bdc9e141bfb594d3afda9d4f;p=thirdparty%2Fsquid.git Maintenance: improved stat5minClientRequests() naming (#1951) 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(). --- diff --git a/src/neighbors.cc b/src/neighbors.cc index b8d23db2e0..4f704ae836 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 a49efeeada..476b1e8cb3 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 b8008cf64a..f83261c759 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);