Reduce peak client recalculation overhead
This commit is contained in:
parent
f49b679ce2
commit
5e760d52dd
2 changed files with 40 additions and 2 deletions
|
|
@ -167,9 +167,12 @@ func (c *Collector) RecordQueryFrom(domain string, clientID string, resolverIP n
|
|||
|
||||
now := c.now()
|
||||
client, exists := tunnel.clients[clientID]
|
||||
updatePeak := !exists
|
||||
if !exists {
|
||||
client = &clientState{firstSeen: now, firstKey: key}
|
||||
tunnel.clients[clientID] = client
|
||||
} else if now.Sub(client.lastSeen) >= ClientTimeout || client.lastKey != key {
|
||||
updatePeak = true
|
||||
}
|
||||
client.lastSeen = now
|
||||
client.lastKey = key
|
||||
|
|
@ -178,7 +181,9 @@ func (c *Collector) RecordQueryFrom(domain string, clientID string, resolverIP n
|
|||
client.bytesIn += uint64(size)
|
||||
}
|
||||
|
||||
updatePeaks(tunnel, now)
|
||||
if updatePeak {
|
||||
updatePeaks(tunnel, now)
|
||||
}
|
||||
}
|
||||
|
||||
// RecordResponse records an observed DNSTT DNS response.
|
||||
|
|
@ -211,7 +216,6 @@ func (c *Collector) Snapshot() Snapshot {
|
|||
snapshot := Snapshot{Tunnels: make(map[string]TunnelSnapshot, len(c.tunnels))}
|
||||
for _, domain := range c.domains {
|
||||
tunnel := c.tunnels[domain]
|
||||
updatePeaks(tunnel, now)
|
||||
series := c.seriesSnapshotsLocked(domain, tunnel, now)
|
||||
|
||||
tunnelSnapshot := TunnelSnapshot{Domain: domain, Series: series}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue