Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [ENHANCEMENT] Update tempo operational dashboard for new block-builder and v2 traces api [#4559](https://github.com/grafana/tempo/pull/4559) (@mdisibio)
* [ENHANCEMENT] Improve block-builder performance by flushing blocks concurrently [#4565](https://github.com/grafana/tempo/pull/4565) (@mdisibio)
* [ENHANCEMENT] Improve block-builder performance [#4596](https://github.com/grafana/tempo/pull/4596) (@mdisibio)
* [ENHANCEMENT] Improve block-builder performance by not using WAL stage [#4647](https://github.com/grafana/tempo/pull/4647) [#4671](https://github.com/grafana/tempo/pull/4671) (@mdisibio)
* [ENHANCEMENT] Export new `tempo_ingest_group_partition_lag` metric from block-builders and metrics-generators [#4571](https://github.com/grafana/tempo/pull/4571) (@mdisibio)
* [ENHANCEMENT] Use distroless base container images for improved security [#4556](https://github.com/grafana/tempo/pull/4556) (@carles-grafana)
* [BUGFIX] Choose a default step for a gRPC streaming query range request if none is provided. [#4546](https://github.com/grafana/tempo/pull/4576) (@joe-elliott)
Expand Down
20 changes: 4 additions & 16 deletions modules/blockbuilder/tenant_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ type chEntry struct {

type liveTracesIter struct {
mtx sync.Mutex
entries []entry
liveTraces *livetraces.LiveTraces[[]byte]
ch chan []chEntry
chBuf []chEntry
Expand All @@ -200,20 +199,9 @@ type liveTracesIter struct {
}

func newLiveTracesIter(liveTraces *livetraces.LiveTraces[[]byte]) *liveTracesIter {
// Get the list of all traces sorted by ID
tids := make([]entry, 0, len(liveTraces.Traces))
for hash, t := range liveTraces.Traces {
tids = append(tids, entry{t.ID, hash})
}

slices.SortFunc(tids, func(a, b entry) int {
return bytes.Compare(a.id, b.id)
})

ctx, cancel := context.WithCancel(context.Background())

l := &liveTracesIter{
entries: tids,
liveTraces: liveTraces,
ch: make(chan []chEntry, 1),
cancel: cancel,
Expand Down Expand Up @@ -254,16 +242,16 @@ func (i *liveTracesIter) iter(ctx context.Context) {
defer close(i.ch)

// Get the list of all traces sorted by ID
tids := make([]entry, 0, len(i.liveTraces.Traces))
entries := make([]entry, 0, len(i.liveTraces.Traces))
for hash, t := range i.liveTraces.Traces {
tids = append(tids, entry{t.ID, hash})
entries = append(entries, entry{t.ID, hash})
}
slices.SortFunc(tids, func(a, b entry) int {
slices.SortFunc(entries, func(a, b entry) int {
return bytes.Compare(a.id, b.id)
})

// Begin sending to channel in chunks to reduce channel overhead.
seq := slices.Chunk(i.entries, 10)
seq := slices.Chunk(entries, 10)
for entries := range seq {
output := make([]chEntry, 0, len(entries))

Expand Down
34 changes: 34 additions & 0 deletions pkg/livetraces/livetraces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/grafana/tempo/pkg/tempopb"
v1 "github.com/grafana/tempo/pkg/tempopb/trace/v1"
"github.com/grafana/tempo/pkg/util/test"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -45,3 +46,36 @@ func TestLiveTracesSizesAndLen(t *testing.T) {
require.Equal(t, expectedLen, lt.Len())
}
}

func BenchmarkLiveTracesWrite(b *testing.B) {
lt := New[*v1.ResourceSpans](func(rs *v1.ResourceSpans) uint64 { return uint64(rs.Size()) })

var traces []*tempopb.Trace
for i := 0; i < 100_000; i++ {
traces = append(traces, test.MakeTrace(1, nil))
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
for _, tr := range traces {
lt.Push(tr.ResourceSpans[0].ScopeSpans[0].Spans[0].TraceId, tr.ResourceSpans[0], 0)
}
}
}

func BenchmarkLiveTracesRead(b *testing.B) {
lt := New[*v1.ResourceSpans](func(rs *v1.ResourceSpans) uint64 { return uint64(rs.Size()) })

for i := 0; i < 100_000; i++ {
tr := test.MakeTrace(1, nil)
lt.Push(tr.ResourceSpans[0].ScopeSpans[0].Spans[0].TraceId, tr.ResourceSpans[0], 0)
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
// This won't anything, instead of will benchmark the map iteration performance.
lt.CutIdle(time.Now().Add(-time.Hour), false)
}
}