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

pkg/chunkenc: Fix BenchmarkRead to focus on reading chunks, not converting bytes to string #1423

Merged
merged 1 commit into from
Dec 19, 2019
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
40 changes: 35 additions & 5 deletions pkg/chunkenc/memchunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,32 +365,62 @@ func BenchmarkWrite(b *testing.B) {
func BenchmarkRead(b *testing.B) {
for _, enc := range testEncoding {
b.Run(enc.String(), func(b *testing.B) {
chunks := generateData(enc)
chunks, size := generateData(enc)
b.ResetTimer()
bytesRead := int64(0)
bytesRead := uint64(0)
now := time.Now()
for n := 0; n < b.N; n++ {
for _, c := range chunks {
// use forward iterator for benchmark -- backward iterator does extra allocations by keeping entries in memory
iterator, err := c.Iterator(time.Unix(0, 0), time.Now(), logproto.FORWARD, nil)
iterator, err := c.Iterator(time.Unix(0, 0), time.Now(), logproto.FORWARD, func(line []byte) bool {
return false
})
if err != nil {
panic(err)
}
for iterator.Next() {
e := iterator.Entry()
bytesRead += int64(len(e.Line))
_ = iterator.Entry()
}
if err := iterator.Close(); err != nil {
b.Fatal(err)
}
}
bytesRead += size
}
b.Log("bytes per second ", humanize.Bytes(uint64(float64(bytesRead)/time.Since(now).Seconds())))
b.Log("n=", b.N)
})
}
}

func TestGenerateDataSize(t *testing.T) {
for _, enc := range testEncoding {
t.Run(enc.String(), func(t *testing.T) {
chunks, size := generateData(enc)

bytesRead := uint64(0)
for _, c := range chunks {
// use forward iterator for benchmark -- backward iterator does extra allocations by keeping entries in memory
iterator, err := c.Iterator(time.Unix(0, 0), time.Now(), logproto.FORWARD, func(line []byte) bool {
return true // return all
})
if err != nil {
panic(err)
}
for iterator.Next() {
e := iterator.Entry()
bytesRead += uint64(len(e.Line))
}
if err := iterator.Close(); err != nil {
t.Fatal(err)
}
}

require.Equal(t, size, bytesRead)
})
}
}

func BenchmarkHeadBlockIterator(b *testing.B) {

for _, j := range []int{100000, 50000, 15000, 10000} {
Expand Down
7 changes: 5 additions & 2 deletions pkg/chunkenc/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ func logprotoEntry(ts int64, line string) *logproto.Entry {
}
}

func generateData(enc Encoding) []Chunk {
func generateData(enc Encoding) ([]Chunk, uint64) {
chunks := []Chunk{}
i := int64(0)
size := uint64(0)

for n := 0; n < 50; n++ {
entry := logprotoEntry(0, testdata.LogString(0))
c := NewMemChunk(enc)
for c.SpaceFor(entry) {
size += uint64(len(entry.Line))
_ = c.Append(entry)
i++
entry = logprotoEntry(i, testdata.LogString(i))
}
c.Close()
chunks = append(chunks, c)
}
return chunks
return chunks, size
}

func fillChunk(c Chunk) int64 {
Expand Down