Skip to content

perf(blooms): Replace JSON lib for encoding/decoding metas #14767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add benchmark
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
  • Loading branch information
chaudum committed Nov 5, 2024
commit 7bb4b8b78926473c5f1d871121b54823dfb3abc3
53 changes: 46 additions & 7 deletions pkg/storage/stores/shipper/bloomshipper/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -436,16 +437,54 @@ func TestFetcher_IsBlockDir(t *testing.T) {
})
}

func metasFromCache(data map[string][]byte) []Meta {
metas := make([]Meta, 0, len(data))
for _, v := range data {
func Benchmark_Fetcher_processMetasCacheResponse(b *testing.B) {
b.Log(b.N)

cfg := bloomStoreConfig{
numWorkers: 1,
workingDirs: []string{b.TempDir()},
}

c, err := NewBloomClient(cfg, nil, log.NewNopLogger())
require.NoError(b, err)
f, err := NewFetcher(cfg, c, nil, nil, nil, log.NewNopLogger(), v1.NewMetrics(nil))
require.NoError(b, err)

step := math.MaxUint64 / uint64(b.N)

refs := make([]MetaRef, 0, b.N)
keys := make([]string, 0, b.N)
bufs := make([][]byte, 0, b.N)

for i := 0; i < b.N; i++ {
minFp := model.Fingerprint(uint64(i) * step)
maxFp := model.Fingerprint(uint64(i)*step + step)

ref := Ref{
TenantID: "fake",
TableName: "tsdb_index_20000",
Bounds: v1.NewBounds(minFp, maxFp),
StartTimestamp: model.Earliest,
EndTimestamp: model.Latest,
}
metaRef := MetaRef{Ref: ref}
refs = append(refs, metaRef)

keys = append(keys, f.client.Meta(metaRef).Addr())

meta := Meta{
MetaRef: MetaRef{},
MetaRef: metaRef,
Blocks: []BlockRef{{Ref: ref}},
}
_ = json.Unmarshal(v, &meta)
metas = append(metas, meta)

buf, _ := json.Marshal(meta)
bufs = append(bufs, buf)
}
return metas

b.ReportAllocs()
b.ResetTimer()

_, _, _ = f.processMetasCacheResponse(context.TODO(), refs, keys, bufs)
}

func metaRefs(metas []Meta) []MetaRef {
Expand Down
Loading