diff options
| author | Stefan Boberg <[email protected]> | 2026-03-23 12:54:14 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-23 12:54:14 +0100 |
| commit | 8e2c307bdb501db0ab0ce2d51bc61b552855ee11 (patch) | |
| tree | 8f9be7e926bc555318a68794ee75ad5ad0dd979f /src/zenhttp/httpserver.cpp | |
| parent | Logger simplification (#883) (diff) | |
| download | zen-8e2c307bdb501db0ab0ce2d51bc61b552855ee11.tar.xz zen-8e2c307bdb501db0ab0ce2d51bc61b552855ee11.zip | |
Unique session/client tracking using HyperLogLog (#884)
## Summary
Adds probabilistic cardinality estimation for tracking unique HTTP clients and sessions using a HyperLogLog implementation.
- Add a `HyperLogLog<Precision>` template in `zentelemetry` with thread-safe lock-free register updates, merge support, and XXH3 hashing
- Feed client IP addresses (via raw bytes) and session IDs (via `Oid` bytes) into their respective HyperLogLog estimators from both the ASIO and http.sys server backends
- Emit `distinct_clients` and `distinct_sessions` cardinality estimates in HTTP `CollectStats()`
- Add tests covering empty, single, duplicates, accuracy, merge, and clear scenarios
## Why HyperLogLog
Tracking exact unique counts would require storing every observed IP or session ID. HyperLogLog provides a memory-bounded probabilistic estimate (~1–2% error) using only a few KB of memory regardless of traffic volume.
Diffstat (limited to 'src/zenhttp/httpserver.cpp')
| -rw-r--r-- | src/zenhttp/httpserver.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index e5cfbcbae..a46c5b851 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -988,6 +988,9 @@ HttpServer::CollectStats() } Cbo.EndObject(); + Cbo << "distinct_clients" << m_ClientAddresses.Count(); + Cbo << "distinct_sessions" << m_ClientSessions.Count(); + Cbo.BeginObject("websockets"); { Cbo << "active_connections" << GetActiveWebSocketConnectionCount(); |