]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Maintenance: improved stat5minClientRequests() naming (#1951)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Sun, 1 Dec 2024 01:48:10 +0000 (01:48 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sun, 1 Dec 2024 10:16:50 +0000 (10:16 +0000)
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().

src/neighbors.cc
src/stat.cc
src/stat.h

index b8d23db2e095399e1cbd4e6d3181f69970b3a14a..4f704ae8360557b20c512712ed56e5d3c254a95b 100644 (file)
@@ -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;
index a49efeeada5d6a8722fa7cc2b12865933460fd5f..476b1e8cb3a86acb13b80dc587154b25526cfd88 100644 (file)
@@ -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
index b8008cf64ae00db9abf31fd872fc33d5e8f329c9..f83261c7597fe4f3d6e1dc7c580907e949a5dc2c 100644 (file)
@@ -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);