From 9145a8f3bb23ac964c2c0f0219fdf14478ee7232 Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Tue, 19 Nov 2024 17:28:18 +0300 Subject: [PATCH 1/4] Renamed stat5minClientRequests() to reflect its meaning --- src/neighbors.cc | 2 +- src/stat.cc | 12 ++++++++---- src/stat.h | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/neighbors.cc b/src/neighbors.cc index f9898f33ca4..f5469745320 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1153,7 +1153,7 @@ peerRefreshDNS(void *data) if (eventFind(peerRefreshDNS, nullptr)) eventDelete(peerRefreshDNS, nullptr); - if (!data && 0 == stat5minClientRequests()) { + if (!data && !statSawRecentRequests()) { /* no recent client traffic, wait a bit */ eventAddIsh("peerRefreshDNS", peerRefreshDNS, nullptr, 180.0, 1); return; diff --git a/src/stat.cc b/src/stat.cc index a49efeeada5..ccbd8a8f462 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -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) + return statCounter.client_http.requests - CountHist[recentMinutes].client_http.requests; + return 0; } 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); From 90aa746f7891cfd959c07de27855ce8738de0647 Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Wed, 20 Nov 2024 17:16:15 +0300 Subject: [PATCH 2/4] Polished and added a comment --- src/stat.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stat.cc b/src/stat.cc index ccbd8a8f462..b6bb41dcd52 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1687,9 +1687,12 @@ snmpStatGet(int minutes) bool statSawRecentRequests() { - static const int recentMinutes = 5; + static 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. if (NCountHist > recentMinutes) return statCounter.client_http.requests - CountHist[recentMinutes].client_http.requests; return 0; From b50d546af850f9014e01f58b594e5140878345a4 Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Thu, 21 Nov 2024 12:24:50 +0300 Subject: [PATCH 3/4] Let statSawRecentRequests() give requests number on startup --- src/stat.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/stat.cc b/src/stat.cc index b6bb41dcd52..818df93380b 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1693,9 +1693,8 @@ statSawRecentRequests() // 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. - if (NCountHist > recentMinutes) - return statCounter.client_http.requests - CountHist[recentMinutes].client_http.requests; - return 0; + const auto oldRequests = (NCountHist > recentMinutes) ? CountHist[recentMinutes].client_http.requests : 0; + return statCounter.client_http.requests - oldRequests; } static double From e2478f74e97d4658e10b5577f9708eb1162a2b9e Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Fri, 22 Nov 2024 01:10:29 +0300 Subject: [PATCH 4/4] No 'static' for an integer constant --- src/stat.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stat.cc b/src/stat.cc index 818df93380b..476b1e8cb3a 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1687,7 +1687,7 @@ snmpStatGet(int minutes) bool statSawRecentRequests() { - static const auto recentMinutes = 5; + const auto recentMinutes = 5; assert(N_COUNT_HIST > recentMinutes); // Math below computes the number of requests during the last 0-6 minutes.