Skip to content
This repository was archived by the owner on Aug 30, 2019. It is now read-only.

Commit 4875242

Browse files
committed
cmd/trace-agent: reduce histogram calls in concentrator
Reduce UDP hits and flooding by calling Histogram only once per flush.
1 parent 9738c9e commit 4875242

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cmd/trace-agent/concentrator.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ func (c *Concentrator) Flush() []model.StatsBucket {
142142

143143
func (c *Concentrator) flushNow(now int64) []model.StatsBucket {
144144
var sb []model.StatsBucket
145+
var (
146+
lenDistributions int
147+
lenErrDistributions int
148+
)
145149

146150
c.mu.Lock()
147151
for ts, srb := range c.buckets {
@@ -156,15 +160,18 @@ func (c *Concentrator) flushNow(now int64) []model.StatsBucket {
156160

157161
log.Debugf("flushing bucket %d", ts)
158162
for _, d := range bucket.Distributions {
159-
statsd.Client.Histogram("datadog.trace_agent.distribution.len", float64(d.Summary.N), nil, 1)
163+
lenDistributions += d.Summary.N
160164
}
161165
for _, d := range bucket.ErrDistributions {
162-
statsd.Client.Histogram("datadog.trace_agent.err_distribution.len", float64(d.Summary.N), nil, 1)
166+
lenErrDistributions += d.Summary.N
163167
}
164168
sb = append(sb, bucket)
165169
delete(c.buckets, ts)
166170
}
167171

172+
statsd.Client.Histogram("datadog.trace_agent.distribution.len", float64(lenDistributions), nil, 1)
173+
statsd.Client.Histogram("datadog.trace_agent.err_distribution.len", float64(lenErrDistributions), nil, 1)
174+
168175
// After flushing, update the oldest timestamp allowed to prevent having stats for
169176
// an already-flushed bucket.
170177
newOldestTs := alignTs(now, c.bsize) - int64(c.bufferLen-1)*c.bsize

0 commit comments

Comments
 (0)