Skip to content

Commit

Permalink
test(storage): add benchmark for scanning with GLSN (#714)
Browse files Browse the repository at this point in the history
### What this PR does

This PR introduces a new benchmark, BenchmarkStorage_ScanWithGLSN, to measure
storage performance when scanning with GLSN across various scan sizes. The
benchmark will serve as foundational data for performance optimization efforts.

Changes:

- Implemented the BenchmarkStorage_ScanWithGLSN benchmark
- Added logic to measure performance across different scan sizes
- Laid groundwork for recording and analyzing performance measurement results
  • Loading branch information
ijsong authored Feb 26, 2024
2 parents b7fa615 + 2fb6b53 commit 9f9401c
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions internal/storage/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/kakao/varlog/pkg/types"
"github.com/kakao/varlog/proto/varlogpb"
)

func BenchmarkStorage_WriteBatch(b *testing.B) {
Expand Down Expand Up @@ -54,3 +56,68 @@ func BenchmarkStorage_WriteBatch(b *testing.B) {
}
}
}

func BenchmarkStorage_ScanWithGLSN(b *testing.B) {
numLogsList := []int{
1, 10, 100, 1000,
}

for _, numLogs := range numLogsList {
b.Run(fmt.Sprintf("numLogs=%d", numLogs), func(b *testing.B) {
stg := TestNewStorage(b,
WithoutSync(),
WithDataDBOptions(
WithL0CompactionThreshold(2),
WithL0StopWritesThreshold(1000),
WithLBaseMaxBytes(64<<20),
WithMaxOpenFiles(16384),
WithMemTableSize(64<<20),
WithMemTableStopWritesThreshold(4),
WithMaxConcurrentCompaction(3),
),
WithCommitDBOptions(
WithL0CompactionThreshold(2),
WithL0StopWritesThreshold(1000),
WithLBaseMaxBytes(64<<20),
WithMaxOpenFiles(16384),
WithMemTableSize(8<<20),
WithMemTableStopWritesThreshold(4),
WithMaxConcurrentCompaction(3),
),
)
b.Cleanup(func() {
assert.NoError(b, stg.Close())
})

for i := range numLogs {
llsn := types.LLSN(i + 1)
glsn := types.GLSN(i + 1)
data := []byte(fmt.Sprintf("log entry %d", i+1))
TestAppendLogEntryWithoutCommitContext(b, stg, llsn, glsn, data)
}
TestSetCommitContext(b, stg, CommitContext{
Version: 1,
HighWatermark: types.GLSN(numLogs),
CommittedGLSNBegin: types.MinGLSN,
CommittedGLSNEnd: types.GLSN(numLogs + 1),
CommittedLLSNBegin: types.MinLLSN,
})

b.ResetTimer()

var logEntry varlogpb.LogEntry
for range b.N {
scanner, err := stg.NewScanner(WithGLSN(types.MinGLSN, types.GLSN(numLogs+1)))
require.NoError(b, err)
for scanner.Valid() {
logEntry, err = scanner.Value()
require.NoError(b, err)
scanner.Next()
}
err = scanner.Close()
require.NoError(b, err)
}
_ = logEntry
})
}
}

0 comments on commit 9f9401c

Please sign in to comment.