Skip to content

Commit

Permalink
cmd/pebble: sample read amp during write-only ycsb workloads
Browse files Browse the repository at this point in the history
Previously, if a ycsb benchmark performed no reads (eg, workload F), then no
read amplification was reported because no reads were performed. Now in these
cases a separate goroutine will periodically sample the database's worst-case
read amplification.

Close #2590.
  • Loading branch information
jbowens committed Jun 7, 2023
1 parent d96868f commit c3bf955
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/pebble/ycsb.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ func (y *ycsb) init(db DB, wg *sync.WaitGroup) {
y.limiter = maxOpsPerSec.newRateLimiter()

wg.Add(concurrency)

// If this workload doesn't produce reads, sample the worst case read-amp
// from Metrics() periodically.
if y.weights.get(ycsbRead) == 0 && y.weights.get(ycsbScan) == 0 && y.weights.get(ycsbReverseScan) == 0 {
wg.Add(1)
go y.sampleReadAmp(db, wg)
}

for i := 0; i < concurrency; i++ {
go y.run(db, wg)
}
Expand Down Expand Up @@ -395,6 +403,21 @@ func (y *ycsb) run(db DB, wg *sync.WaitGroup) {
}
}

func (y *ycsb) sampleReadAmp(db DB, wg *sync.WaitGroup) {
defer wg.Done()

limiter := rate.NewLimiter(rate.Every(time.Second), 0)
for {
wait(limiter)
m := db.Metrics()
y.readAmpCount.Add(1)
y.readAmpSum.Add(uint64(m.ReadAmp()))
if ycsbConfig.numOps > 0 && atomic.LoadUint64(&y.numOps) >= ycsbConfig.numOps {
break
}
}
}

func (y *ycsb) hashKey(key uint64) uint64 {
// Inlined version of fnv.New64 + Write.
const offset64 = 14695981039346656037
Expand Down

0 comments on commit c3bf955

Please sign in to comment.