Skip to content
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

fix(ci): transform TestChunkSize into a benchmark #15361

Merged
merged 3 commits into from
Dec 12, 2024
Merged
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
47 changes: 31 additions & 16 deletions pkg/chunkenc/memchunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,41 +677,56 @@ func TestMemChunk_AppendOutOfOrder(t *testing.T) {
}
}

func TestChunkSize(t *testing.T) {
func BenchmarkEncodingsAndChunkSize(b *testing.B) {
type res struct {
name string
count uint64
size uint64
compressedSize uint64
ratio float64
}
var result []res
for _, bs := range testBlockSizes {
for _, f := range allPossibleFormats {
for _, enc := range testEncodings {
name := fmt.Sprintf("%s_%s", enc.String(), humanize.Bytes(uint64(bs)))
t.Run(name, func(t *testing.T) {
c := newMemChunkWithFormat(f.chunkFormat, enc, f.headBlockFmt, bs, testTargetSize)
inserted := fillChunk(c)
b, err := c.Bytes()
if err != nil {
t.Fatal(err)

resBuffer := make([]byte, 0, 50*1024*1024)
for _, enc := range testEncodings {
for _, bs := range testBlockSizes {
for fi, f := range allPossibleFormats {
name := fmt.Sprintf("%s_block_size_%s_format_%d", enc.String(), humanize.Bytes(uint64(bs)), fi)
b.Run(name, func(b *testing.B) {
var insertedTotal, compressedTotal, count uint64
for range b.N {
c := newMemChunkWithFormat(f.chunkFormat, enc, f.headBlockFmt, bs, testTargetSize)
inserted := fillChunk(c)
insertedTotal += uint64(inserted)
cb, err := c.BytesWith(resBuffer)
if err != nil {
b.Fatal(err)
}
compressedTotal += uint64(len(cb))
count++
}

averageRatio := float64(insertedTotal) / float64(compressedTotal)
result = append(result, res{
name: name,
size: uint64(inserted),
compressedSize: uint64(len(b)),
ratio: float64(inserted) / float64(len(b)),
count: count,
size: insertedTotal,
compressedSize: compressedTotal,
ratio: averageRatio,
})
b.ReportMetric(averageRatio, "compression_ratio")
b.ReportMetric(float64(insertedTotal)/float64(count*1024), "avg_size_kb")
b.ReportMetric(float64(compressedTotal)/float64(count*1024), "avg_compressed_size_kb")
})
}
}
}
sort.Slice(result, func(i, j int) bool {
return result[i].ratio > result[j].ratio
})
fmt.Printf("%s\t%s\t%s\t%s\n", "name", "uncompressed", "compressed", "ratio")
fmt.Printf("%s\t%s\t%s\t%s\t%s\n", "name", "count", "uncompressed", "compressed", "ratio")
for _, r := range result {
fmt.Printf("%s\t%s\t%s\t%f\n", r.name, humanize.Bytes(r.size), humanize.Bytes(r.compressedSize), r.ratio)
fmt.Printf("%s\t(count %d)\n%s\t%s\t%f\n", r.name, r.count, humanize.Bytes(r.size/r.count), humanize.Bytes(r.compressedSize/r.count), r.ratio)
na-- marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading