Skip to content

Commit

Permalink
ddtrace/tracer: remove meta maps pool
Browse files Browse the repository at this point in the history
Releasing the map after encoding the span for submission doesn't play well with our current codebase
  • Loading branch information
darccio committed Aug 7, 2024
1 parent d091651 commit 30d6cd8
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 46 deletions.
2 changes: 1 addition & 1 deletion ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func takeStacktrace(n, skip uint) string {
// setMeta sets a string tag. This method is not safe for concurrent use.
func (s *span) setMeta(key, v string) {
if s.Meta == nil {
s.Meta = mmp.Get()
s.Meta = defaultMetaMap()
}
delete(s.Metrics, key)
switch key {
Expand Down
37 changes: 0 additions & 37 deletions ddtrace/tracer/spantags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,3 @@
// Copyright 2024 Datadog, Inc.

package tracer

import "sync"

type metaMapPool struct {
*sync.Pool
}

var mmp = &metaMapPool{
Pool: &sync.Pool{
New: func() any {
return defaultMetaMap()
},
},
}

func (p *metaMapPool) Get() map[string]string {
return p.Pool.Get().(map[string]string)
}

func (p *metaMapPool) Put(m map[string]string) {
if m == nil {
return
}
clear(m)
p.Pool.Put(m)
}

func releaseSpanMaps(spans []*span) {
for i := range spans {
releaseSpanMap(spans[i])
}
}

func releaseSpanMap(s *span) {
mmp.Put(s.Meta)
s.Meta = nil
}
9 changes: 3 additions & 6 deletions ddtrace/tracer/spantags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func BenchmarkSpanLifecycle(b *testing.B) {
[]float64{8.75, 14.59, 22.8, 31.2, 39.1, 43.5, 54.3, 70.0},
)
b.Run("baseline/set tag", func(b *testing.B) {
span := &span{}
span.setMeta("key", "value")
span := newBasicSpan("benchmark")
if span.Meta == nil {
b.Fatal("expected span.Meta to be non-nil")
}
Expand All @@ -36,13 +35,12 @@ func BenchmarkSpanLifecycle(b *testing.B) {
// preallocate the spans
spans := make([]*span, b.N)
for i := 0; i < b.N; i++ {
spans[i] = &span{}
spans[i] = newBasicSpan("benchmark")
}
b.ResetTimer()
b.ReportMetric(1.0, "tags/op")
for i := 0; i < b.N; i++ {
spans[i].setMeta("key", "value")
releaseSpanMap(spans[i])
}
})
b.Run("with tags", func(b *testing.B) {
Expand All @@ -58,7 +56,7 @@ func BenchmarkSpanLifecycle(b *testing.B) {
}, b.N)
totalSpanTags := 0
for i := 0; i < b.N; i++ {
spans[i].span = &span{}
spans[i].span = newBasicSpan("benchmark")
spans[i].n = int(distribution.generate(r))
totalSpanTags += spans[i].n
}
Expand All @@ -69,7 +67,6 @@ func BenchmarkSpanLifecycle(b *testing.B) {
for j := 0; j < spans[i].n; j++ {
s.setMeta(tags[j], "value")
}
releaseSpanMap(s)
}
})
}
Expand Down
2 changes: 0 additions & 2 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ func (t *tracer) worker(tick <-chan time.Time) {
t.sampleChunk(trace)
if len(trace.spans) != 0 {
t.traceWriter.add(trace.spans)
releaseSpanMaps(trace.spans)
}
case <-tick:
t.statsd.Incr("datadog.tracer.flush_triggered", []string{"reason:scheduled"}, 1)
Expand All @@ -395,7 +394,6 @@ func (t *tracer) worker(tick <-chan time.Time) {
t.sampleChunk(trace)
if len(trace.spans) != 0 {
t.traceWriter.add(trace.spans)
releaseSpanMaps(trace.spans)
}
default:
break loop
Expand Down

0 comments on commit 30d6cd8

Please sign in to comment.