[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Fix periodic stats reporting.



commit 085f253757ecefd84aa0667eeb12e594e009e331
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Thu Oct 19 00:00:26 2017 -0700

    Fix periodic stats reporting.
    
    The time interval was being reset every time a new connection came in.
---
 server/stats.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/server/stats.go b/server/stats.go
index 1aeefb5..51b2f7e 100644
--- a/server/stats.go
+++ b/server/stats.go
@@ -22,6 +22,7 @@ var (
 func statsThread() {
 	var numClientIP, numConnections uint64
 	prevTime := time.Now()
+	deadline := time.After(statsInterval)
 	for {
 		select {
 		case v := <-statsChannel:
@@ -29,7 +30,7 @@ func statsThread() {
 				numClientIP += 1
 			}
 			numConnections += 1
-		case <-time.After(statsInterval):
+		case <-deadline:
 			now := time.Now()
 			log.Printf("in the past %.g s, %d/%d connections had client_ip",
 				(now.Sub(prevTime)).Seconds(),
@@ -37,6 +38,7 @@ func statsThread() {
 			numClientIP = 0
 			numConnections = 0
 			prevTime = now
+			deadline = time.After(statsInterval)
 		}
 	}
 }

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits