Skip to content

Commit c9f46a6

Browse files
committed
metrics: fix w-amp calculation w/ blob files
Fix the w-amp calculation to properly account for blob files. We should be including all bytes written to disk in the numerator, and only bytes "in" (flushed in the case of blob files) in the denominator. Informs #4581.
1 parent d742eb8 commit c9f46a6

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

cmd/pebble/ycsb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ func (y *ycsb) done(elapsed time.Duration) {
622622
resultHist.TotalCount(),
623623
float64(resultHist.TotalCount())/elapsed.Seconds(),
624624
total.TableBytesRead,
625-
total.TableBytesFlushed+total.TableBytesCompacted+total.BlobBytesFlushed+total.BlobBytesWritten,
625+
total.TableBytesFlushed+total.TableBytesCompacted+total.BlobBytesFlushed+total.BlobBytesCompacted,
626626
float64(readAmpSum)/float64(readAmpCount),
627627
total.WriteAmp(),
628628
)

compaction.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ func (d *DB) flush1() (bytesFlushed uint64, err error) {
15641564
// resulting in zero bytes in. Instead, use the number of bytes we
15651565
// flushed as the BytesIn. This ensures we get a reasonable w-amp
15661566
// calculation even when the WAL is disabled.
1567-
l0Metrics.TableBytesIn = l0Metrics.TableBytesFlushed
1567+
l0Metrics.TableBytesIn = l0Metrics.TableBytesFlushed + l0Metrics.BlobBytesFlushed
15681568
} else {
15691569
for i := 0; i < n; i++ {
15701570
l0Metrics.TableBytesIn += d.mu.mem.queue[i].logSize
@@ -3277,8 +3277,8 @@ func (c *compaction) makeVersionEdit(result compact.Result) (*versionEdit, error
32773277
TableBytesIn: startLevelBytes,
32783278
// TODO(jackson): This BytesRead value does not include any blob files
32793279
// written. It either should, or we should add a separate metric.
3280-
TableBytesRead: c.outputLevel.files.TableSizeSum(),
3281-
BlobBytesWritten: result.Stats.CumulativeBlobFileSize,
3280+
TableBytesRead: c.outputLevel.files.TableSizeSum(),
3281+
BlobBytesCompacted: result.Stats.CumulativeBlobFileSize,
32823282
}
32833283
if c.flushing != nil {
32843284
outputMetrics.BlobBytesFlushed = result.Stats.CumulativeBlobFileSize

metrics.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ type LevelMetrics struct {
105105
// to values referenced by sstables that were inputs into compactions
106106
// outputting into this level.
107107
BlobBytesReadEstimate uint64
108-
// BlobBytesWritten is the number of bytes written to blob files while
108+
// BlobBytesCompacted is the number of bytes written to blob files while
109109
// compacting sstables in this level.
110-
BlobBytesWritten uint64
110+
BlobBytesCompacted uint64
111111
// BlobBytesFlushed is the number of bytes written to blob files while
112112
// flushing sstables. This metric is always zero for all levels other than
113113
// L0.
@@ -165,7 +165,7 @@ func (m *LevelMetrics) Add(u *LevelMetrics) {
165165
m.TablesFlushed += u.TablesFlushed
166166
m.TablesIngested += u.TablesIngested
167167
m.TablesMoved += u.TablesMoved
168-
m.BlobBytesWritten += u.BlobBytesWritten
168+
m.BlobBytesCompacted += u.BlobBytesCompacted
169169
m.BlobBytesFlushed += u.BlobBytesFlushed
170170
m.BlobBytesReadEstimate += u.BlobBytesReadEstimate
171171
m.MultiLevel.TableBytesInTop += u.MultiLevel.TableBytesInTop
@@ -177,16 +177,22 @@ func (m *LevelMetrics) Add(u *LevelMetrics) {
177177
}
178178

179179
// WriteAmp computes the write amplification for compactions at this
180-
// level. Computed as:
180+
// level.
181181
//
182-
// TableBytesFlushed + TableBytesCompacted + BlobBytesFlushed
183-
// ---------------------------------------------------------
184-
// TableBytesIn + BlobBytesWritten
182+
// The write amplification is computed as the quantity of physical bytes written
183+
// divided by the quantity of logical bytes written.
184+
//
185+
// Concretely, it's computed as:
186+
//
187+
// TableBytesFlushed + TableBytesCompacted + BlobBytesFlushed + BlobBytesWritten
188+
// -----------------------------------------------------------------------------
189+
// TableBytesIn
185190
func (m *LevelMetrics) WriteAmp() float64 {
186191
if m.TableBytesIn == 0 {
187192
return 0
188193
}
189-
return float64(m.TableBytesFlushed+m.TableBytesCompacted+m.BlobBytesFlushed) / float64(m.TableBytesIn+m.BlobBytesWritten)
194+
return float64(m.TableBytesFlushed+m.TableBytesCompacted+m.BlobBytesFlushed+m.BlobBytesCompacted) /
195+
float64(m.TableBytesIn)
190196
}
191197

192198
var categoryCompaction = block.RegisterCategory("pebble-compaction", block.NonLatencySensitiveQoSLevel)

testdata/compaction/value_separation

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ metrics
119119
| | | | ingested | moved | written | | amp | multilevel
120120
level | tables size val-bl vtables | score ff cff | in | tables size | tables size | tables size | read | r w | top in read
121121
------+-----------------------------+----------------+-------+--------------+--------------+--------------+-------+----------+------------------
122-
0 | 0 0B 0B 0 | - 0 0 | 41B | 0 0B | 0 0B | 1 784B | 0B | 0 7.94 | 0B 0B 0B
122+
0 | 0 0B 0B 0 | - 0 0 | 41B | 0 0B | 0 0B | 1 784B | 0B | 0 22.3 | 0B 0B 0B
123123
1 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 1 784B | 0 0B | 0B | 0 0 | 0B 0B 0B
124124
2 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B 0B
125125
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 1 784B | 0 0B | 0B | 0 0 | 0B 0B 0B
126126
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0 | 0B 0B 0B
127127
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 1 784B | 0 0B | 0B | 0 0 | 0B 0B 0B
128-
6 | 1 834B 0B 0 | - 0.00 0.00 | 784B | 0 0B | 0 0B | 1 834B | 1.6KB | 1 0.97 | 0B 0B 0B
129-
total | 1 834B 0B 0 | - - - | 41B | 0 0B | 3 2.3KB | 2 1.6KB | 1.6KB | 1 9.48 | 0B 0B 0B
128+
6 | 1 834B 0B 0 | - 0.00 0.00 | 784B | 0 0B | 0 0B | 1 834B | 1.6KB | 1 1.16 | 0B 0B 0B
129+
total | 1 834B 0B 0 | - - - | 41B | 0 0B | 3 2.3KB | 2 1.6KB | 1.6KB | 1 45.5 | 0B 0B 0B
130130
------------------------------------------------------------------------------------------------------------------------------------------------
131131
WAL: 1 files (0B) in: 30B written: 41B (37% overhead)
132132
Flushes: 1

testdata/metrics

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,14 @@ metrics
342342
| | | | ingested | moved | written | | amp
343343
level | tables size val-bl vtables | score ff cff | in | tables size | tables size | tables size | read | r w
344344
------+-----------------------------+----------------+-------+--------------+--------------+--------------+-------+---------
345-
0 | 7 5.3KB 0B 0 | - 0.25 0.25 | 165B | 0 0B | 0 0B | 9 6.8KB | 0B | 1 12.7
345+
0 | 7 5.3KB 0B 0 | - 0.25 0.25 | 165B | 0 0B | 0 0B | 9 6.8KB | 0B | 1 47.2
346346
1 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
347347
2 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
348348
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
349349
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
350350
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
351351
6 | 2 1.5KB 0B 0 | - 0.00 0.00 | 1.5KB | 0 0B | 0 0B | 2 1.5KB | 1.5KB | 1 1.00
352-
total | 9 6.8KB 0B 0 | - - - | 165B | 0 0B | 0 0B | 11 8.4KB | 1.5KB | 2 15.7
352+
total | 9 6.8KB 0B 0 | - - - | 165B | 0 0B | 0 0B | 11 8.4KB | 1.5KB | 2 57.4
353353
----------------------------------------------------------------------------------------------------------------------------
354354
WAL: 1 files (0B) in: 116B written: 165B (42% overhead)
355355
Flushes: 3
@@ -406,14 +406,14 @@ metrics
406406
| | | | ingested | moved | written | | amp
407407
level | tables size val-bl vtables | score ff cff | in | tables size | tables size | tables size | read | r w
408408
------+-----------------------------+----------------+-------+--------------+--------------+--------------+-------+---------
409-
0 | 0 0B 0B 0 | - 0 0 | 165B | 0 0B | 0 0B | 9 6.8KB | 0B | 0 12.7
409+
0 | 0 0B 0B 0 | - 0 0 | 165B | 0 0B | 0 0B | 9 6.8KB | 0B | 0 47.2
410410
1 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
411411
2 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
412412
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
413413
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
414414
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
415415
6 | 9 6.8KB 0B 0 | - 0.00 0.00 | 6.8KB | 0 0B | 0 0B | 9 6.8KB | 6.8KB | 1 1.00
416-
total | 9 6.8KB 0B 0 | - - - | 165B | 0 0B | 0 0B | 18 14KB | 6.8KB | 1 25.1
416+
total | 9 6.8KB 0B 0 | - - - | 165B | 0 0B | 0 0B | 18 14KB | 6.8KB | 1 90.3
417417
----------------------------------------------------------------------------------------------------------------------------
418418
WAL: 1 files (0B) in: 116B written: 165B (42% overhead)
419419
Flushes: 3
@@ -521,14 +521,14 @@ metrics
521521
| | | | ingested | moved | written | | amp
522522
level | tables size val-bl vtables | score ff cff | in | tables size | tables size | tables size | read | r w
523523
------+-----------------------------+----------------+-------+--------------+--------------+--------------+-------+---------
524-
0 | 6 4.4KB 0B 0 | - 0.50 0.50 | 211B | 3 2.2KB | 0 0B | 12 9.0KB | 0B | 2 15.4
524+
0 | 6 4.4KB 0B 0 | - 0.50 0.50 | 211B | 3 2.2KB | 0 0B | 12 9.0KB | 0B | 2 47.6
525525
1 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
526526
2 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
527527
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
528528
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
529529
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
530530
6 | 9 6.8KB 0B 0 | - 0.00 0.00 | 6.8KB | 0 0B | 0 0B | 9 6.8KB | 6.8KB | 1 1.00
531-
total | 15 11KB 0B 0 | - - - | 2.4KB | 3 2.2KB | 0 0B | 21 18KB | 6.8KB | 3 6.58
531+
total | 15 11KB 0B 0 | - - - | 2.4KB | 3 2.2KB | 0 0B | 21 18KB | 6.8KB | 3 7.84
532532
----------------------------------------------------------------------------------------------------------------------------
533533
WAL: 1 files (0B) in: 176B written: 211B (20% overhead)
534534
Flushes: 8
@@ -598,14 +598,14 @@ metrics
598598
| | | | ingested | moved | written | | amp
599599
level | tables size val-bl vtables | score ff cff | in | tables size | tables size | tables size | read | r w
600600
------+-----------------------------+----------------+-------+--------------+--------------+--------------+-------+---------
601-
0 | 13 9.6KB 0B 0 | - 0.50 0.50 | 277B | 3 2.2KB | 0 0B | 19 14KB | 0B | 2 21.6
601+
0 | 13 9.6KB 0B 0 | - 0.50 0.50 | 277B | 3 2.2KB | 0 0B | 19 14KB | 0B | 2 55.4
602602
1 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
603603
2 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
604604
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
605605
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
606606
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
607607
6 | 9 6.8KB 0B 0 | - 0.00 0.00 | 6.8KB | 0 0B | 0 0B | 9 6.8KB | 6.8KB | 1 1.00
608-
total | 22 16KB 0B 0 | - - - | 2.5KB | 3 2.2KB | 0 0B | 28 23KB | 6.8KB | 3 8.24
608+
total | 22 16KB 0B 0 | - - - | 2.5KB | 3 2.2KB | 0 0B | 28 23KB | 6.8KB | 3 9.73
609609
----------------------------------------------------------------------------------------------------------------------------
610610
WAL: 1 files (0B) in: 223B written: 277B (24% overhead)
611611
Flushes: 9
@@ -687,14 +687,14 @@ metrics zero-cache-hits-misses
687687
| | | | ingested | moved | written | | amp
688688
level | tables size val-bl vtables | score ff cff | in | tables size | tables size | tables size | read | r w
689689
------+-----------------------------+----------------+-------+--------------+--------------+--------------+-------+---------
690-
0 | 11 8.1KB 0B 0 | - 0.50 0.50 | 277B | 3 2.2KB | 0 0B | 19 14KB | 0B | 2 21.6
690+
0 | 11 8.1KB 0B 0 | - 0.50 0.50 | 277B | 3 2.2KB | 0 0B | 19 14KB | 0B | 2 55.4
691691
1 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
692692
2 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
693693
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
694694
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
695695
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
696696
6 | 10 7.5KB 0B 0 | - 0.00 0.00 | 6.8KB | 1 758B | 0 0B | 9 6.8KB | 6.8KB | 1 1.00
697-
total | 21 16KB 0B 0 | - - - | 3.2KB | 4 3.0KB | 0 0B | 28 24KB | 6.8KB | 3 6.76
697+
total | 21 16KB 0B 0 | - - - | 3.2KB | 4 3.0KB | 0 0B | 28 24KB | 6.8KB | 3 7.73
698698
----------------------------------------------------------------------------------------------------------------------------
699699
WAL: 1 files (0B) in: 223B written: 277B (24% overhead)
700700
Flushes: 9
@@ -812,14 +812,14 @@ metrics zero-cache-hits-misses
812812
| | | | ingested | moved | written | | amp
813813
level | tables size val-bl vtables | score ff cff | in | tables size | tables size | tables size | read | r w
814814
------+-----------------------------+----------------+-------+--------------+--------------+--------------+-------+---------
815-
0 | 0 0B 0B 0 | - 0 0 | 277B | 3 2.2KB | 0 0B | 19 14KB | 0B | 0 21.6
815+
0 | 0 0B 0B 0 | - 0 0 | 277B | 3 2.2KB | 0 0B | 19 14KB | 0B | 0 55.4
816816
1 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
817817
2 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
818818
3 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
819819
4 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
820820
5 | 0 0B 0B 0 | - 0 0 | 0B | 0 0B | 0 0B | 0 0B | 0B | 0 0
821821
6 | 18 13KB 0B 0 | - 0.00 0.00 | 14KB | 2 1.5KB | 0 0B | 16 12KB | 14KB | 1 0.84
822-
total | 18 13KB 0B 0 | - - - | 4.0KB | 5 3.7KB | 0 0B | 35 30KB | 14KB | 1 6.99
822+
total | 18 13KB 0B 0 | - - - | 4.0KB | 5 3.7KB | 0 0B | 35 30KB | 14KB | 1 7.80
823823
----------------------------------------------------------------------------------------------------------------------------
824824
WAL: 1 files (0B) in: 223B written: 277B (24% overhead)
825825
Flushes: 9

0 commit comments

Comments
 (0)