Line data Source code
1 : // Copyright 2019 The LevelDB-Go and Pebble Authors. All rights reserved. Use
2 : // of this source code is governed by a BSD-style license that can be found in
3 : // the LICENSE file.
4 :
5 : package pebble
6 :
7 : import (
8 : "fmt"
9 : "math"
10 : "time"
11 :
12 : "github.com/cockroachdb/pebble/internal/base"
13 : "github.com/cockroachdb/pebble/internal/cache"
14 : "github.com/cockroachdb/pebble/internal/humanize"
15 : "github.com/cockroachdb/pebble/objstorage/objstorageprovider/sharedcache"
16 : "github.com/cockroachdb/pebble/record"
17 : "github.com/cockroachdb/pebble/sstable"
18 : "github.com/cockroachdb/pebble/wal"
19 : "github.com/cockroachdb/redact"
20 : "github.com/prometheus/client_golang/prometheus"
21 : )
22 :
23 : // CacheMetrics holds metrics for the block and table cache.
24 : type CacheMetrics = cache.Metrics
25 :
26 : // FilterMetrics holds metrics for the filter policy
27 : type FilterMetrics = sstable.FilterMetrics
28 :
29 : // ThroughputMetric is a cumulative throughput metric. See the detailed
30 : // comment in base.
31 : type ThroughputMetric = base.ThroughputMetric
32 :
33 : // SecondaryCacheMetrics holds metrics for the persistent secondary cache
34 : // that caches commonly accessed blocks from blob storage on a local
35 : // file system.
36 : type SecondaryCacheMetrics = sharedcache.Metrics
37 :
38 : // LevelMetrics holds per-level metrics such as the number of files and total
39 : // size of the files, and compaction related metrics.
40 : type LevelMetrics struct {
41 : // The number of sublevels within the level. The sublevel count corresponds
42 : // to the read amplification for the level. An empty level will have a
43 : // sublevel count of 0, implying no read amplification. Only L0 will have
44 : // a sublevel count other than 0 or 1.
45 : Sublevels int32
46 : // The total number of files in the level.
47 : NumFiles int64
48 : // The total number of virtual sstables in the level.
49 : NumVirtualFiles uint64
50 : // The total size in bytes of the files in the level.
51 : Size int64
52 : // The total size of the virtual sstables in the level.
53 : VirtualSize uint64
54 : // The level's compaction score. This is the compensatedScoreRatio in the
55 : // candidateLevelInfo.
56 : Score float64
57 : // The number of incoming bytes from other levels read during
58 : // compactions. This excludes bytes moved and bytes ingested. For L0 this is
59 : // the bytes written to the WAL.
60 : BytesIn uint64
61 : // The number of bytes ingested. The sibling metric for tables is
62 : // TablesIngested.
63 : BytesIngested uint64
64 : // The number of bytes moved into the level by a "move" compaction. The
65 : // sibling metric for tables is TablesMoved.
66 : BytesMoved uint64
67 : // The number of bytes read for compactions at the level. This includes bytes
68 : // read from other levels (BytesIn), as well as bytes read for the level.
69 : BytesRead uint64
70 : // The number of bytes written during compactions. The sibling
71 : // metric for tables is TablesCompacted. This metric may be summed
72 : // with BytesFlushed to compute the total bytes written for the level.
73 : BytesCompacted uint64
74 : // The number of bytes written during flushes. The sibling
75 : // metrics for tables is TablesFlushed. This metric is always
76 : // zero for all levels other than L0.
77 : BytesFlushed uint64
78 : // The number of sstables compacted to this level.
79 : TablesCompacted uint64
80 : // The number of sstables flushed to this level.
81 : TablesFlushed uint64
82 : // The number of sstables ingested into the level.
83 : TablesIngested uint64
84 : // The number of sstables moved to this level by a "move" compaction.
85 : TablesMoved uint64
86 :
87 : MultiLevel struct {
88 : // BytesInTop are the total bytes in a multilevel compaction coming from the top level.
89 : BytesInTop uint64
90 :
91 : // BytesIn, exclusively for multiLevel compactions.
92 : BytesIn uint64
93 :
94 : // BytesRead, exclusively for multilevel compactions.
95 : BytesRead uint64
96 : }
97 :
98 : // Additional contains misc additional metrics that are not always printed.
99 : Additional struct {
100 : // The sum of Properties.ValueBlocksSize for all the sstables in this
101 : // level. Printed by LevelMetrics.format iff there is at least one level
102 : // with a non-zero value.
103 : ValueBlocksSize uint64
104 : // Cumulative metrics about bytes written to data blocks and value blocks,
105 : // via compactions (except move compactions) or flushes. Not printed by
106 : // LevelMetrics.format, but are available to sophisticated clients.
107 : BytesWrittenDataBlocks uint64
108 : BytesWrittenValueBlocks uint64
109 : }
110 : }
111 :
112 : // Add updates the counter metrics for the level.
113 2 : func (m *LevelMetrics) Add(u *LevelMetrics) {
114 2 : m.NumFiles += u.NumFiles
115 2 : m.NumVirtualFiles += u.NumVirtualFiles
116 2 : m.VirtualSize += u.VirtualSize
117 2 : m.Size += u.Size
118 2 : m.BytesIn += u.BytesIn
119 2 : m.BytesIngested += u.BytesIngested
120 2 : m.BytesMoved += u.BytesMoved
121 2 : m.BytesRead += u.BytesRead
122 2 : m.BytesCompacted += u.BytesCompacted
123 2 : m.BytesFlushed += u.BytesFlushed
124 2 : m.TablesCompacted += u.TablesCompacted
125 2 : m.TablesFlushed += u.TablesFlushed
126 2 : m.TablesIngested += u.TablesIngested
127 2 : m.TablesMoved += u.TablesMoved
128 2 : m.MultiLevel.BytesInTop += u.MultiLevel.BytesInTop
129 2 : m.MultiLevel.BytesRead += u.MultiLevel.BytesRead
130 2 : m.MultiLevel.BytesIn += u.MultiLevel.BytesIn
131 2 : m.Additional.BytesWrittenDataBlocks += u.Additional.BytesWrittenDataBlocks
132 2 : m.Additional.BytesWrittenValueBlocks += u.Additional.BytesWrittenValueBlocks
133 2 : m.Additional.ValueBlocksSize += u.Additional.ValueBlocksSize
134 2 : }
135 :
136 : // WriteAmp computes the write amplification for compactions at this
137 : // level. Computed as (BytesFlushed + BytesCompacted) / BytesIn.
138 1 : func (m *LevelMetrics) WriteAmp() float64 {
139 1 : if m.BytesIn == 0 {
140 1 : return 0
141 1 : }
142 1 : return float64(m.BytesFlushed+m.BytesCompacted) / float64(m.BytesIn)
143 : }
144 :
145 : // Metrics holds metrics for various subsystems of the DB such as the Cache,
146 : // Compactions, WAL, and per-Level metrics.
147 : //
148 : // TODO(peter): The testing of these metrics is relatively weak. There should
149 : // be testing that performs various operations on a DB and verifies that the
150 : // metrics reflect those operations.
151 : type Metrics struct {
152 : BlockCache CacheMetrics
153 :
154 : Compact struct {
155 : // The total number of compactions, and per-compaction type counts.
156 : Count int64
157 : DefaultCount int64
158 : DeleteOnlyCount int64
159 : ElisionOnlyCount int64
160 : CopyCount int64
161 : MoveCount int64
162 : ReadCount int64
163 : RewriteCount int64
164 : MultiLevelCount int64
165 : CounterLevelCount int64
166 : // An estimate of the number of bytes that need to be compacted for the LSM
167 : // to reach a stable state.
168 : EstimatedDebt uint64
169 : // Number of bytes present in sstables being written by in-progress
170 : // compactions. This value will be zero if there are no in-progress
171 : // compactions.
172 : InProgressBytes int64
173 : // Number of compactions that are in-progress.
174 : NumInProgress int64
175 : // MarkedFiles is a count of files that are marked for
176 : // compaction. Such files are compacted in a rewrite compaction
177 : // when no other compactions are picked.
178 : MarkedFiles int
179 : // Duration records the cumulative duration of all compactions since the
180 : // database was opened.
181 : Duration time.Duration
182 : }
183 :
184 : Ingest struct {
185 : // The total number of ingestions
186 : Count uint64
187 : }
188 :
189 : Flush struct {
190 : // The total number of flushes.
191 : Count int64
192 : WriteThroughput ThroughputMetric
193 : // Number of flushes that are in-progress. In the current implementation
194 : // this will always be zero or one.
195 : NumInProgress int64
196 : // AsIngestCount is a monotonically increasing counter of flush operations
197 : // handling ingested tables.
198 : AsIngestCount uint64
199 : // AsIngestCount is a monotonically increasing counter of tables ingested as
200 : // flushables.
201 : AsIngestTableCount uint64
202 : // AsIngestBytes is a monotonically increasing counter of the bytes flushed
203 : // for flushables that originated as ingestion operations.
204 : AsIngestBytes uint64
205 : }
206 :
207 : Filter FilterMetrics
208 :
209 : Levels [numLevels]LevelMetrics
210 :
211 : MemTable struct {
212 : // The number of bytes allocated by memtables and large (flushable)
213 : // batches.
214 : Size uint64
215 : // The count of memtables.
216 : Count int64
217 : // The number of bytes present in zombie memtables which are no longer
218 : // referenced by the current DB state. An unbounded number of memtables
219 : // may be zombie if they're still in use by an iterator. One additional
220 : // memtable may be zombie if it's no longer in use and waiting to be
221 : // recycled.
222 : ZombieSize uint64
223 : // The count of zombie memtables.
224 : ZombieCount int64
225 : }
226 :
227 : Keys struct {
228 : // The approximate count of internal range key set keys in the database.
229 : RangeKeySetsCount uint64
230 : // The approximate count of internal tombstones (DEL, SINGLEDEL and
231 : // RANGEDEL key kinds) within the database.
232 : TombstoneCount uint64
233 : // A cumulative total number of missized DELSIZED keys encountered by
234 : // compactions since the database was opened.
235 : MissizedTombstonesCount uint64
236 : }
237 :
238 : Snapshots struct {
239 : // The number of currently open snapshots.
240 : Count int
241 : // The sequence number of the earliest, currently open snapshot.
242 : EarliestSeqNum base.SeqNum
243 : // A running tally of keys written to sstables during flushes or
244 : // compactions that would've been elided if it weren't for open
245 : // snapshots.
246 : PinnedKeys uint64
247 : // A running cumulative sum of the size of keys and values written to
248 : // sstables during flushes or compactions that would've been elided if
249 : // it weren't for open snapshots.
250 : PinnedSize uint64
251 : }
252 :
253 : Table struct {
254 : // The number of bytes present in obsolete tables which are no longer
255 : // referenced by the current DB state or any open iterators.
256 : ObsoleteSize uint64
257 : // The count of obsolete tables.
258 : ObsoleteCount int64
259 : // The number of bytes present in zombie tables which are no longer
260 : // referenced by the current DB state but are still in use by an iterator.
261 : ZombieSize uint64
262 : // The count of zombie tables.
263 : ZombieCount int64
264 : // The count of sstables backing virtual tables.
265 : BackingTableCount uint64
266 : // The sum of the sizes of the BackingTableCount sstables that are backing virtual tables.
267 : BackingTableSize uint64
268 : // The number of sstables that are compressed with an unknown compression
269 : // algorithm.
270 : CompressedCountUnknown int64
271 : // The number of sstables that are compressed with the default compression
272 : // algorithm, snappy.
273 : CompressedCountSnappy int64
274 : // The number of sstables that are compressed with zstd.
275 : CompressedCountZstd int64
276 : // The number of sstables that are uncompressed.
277 : CompressedCountNone int64
278 :
279 : // Local file sizes.
280 : Local struct {
281 : // LiveSize is the number of bytes in live tables.
282 : LiveSize uint64
283 : // ObsoleteSize is the number of bytes in obsolete tables.
284 : ObsoleteSize uint64
285 : // ZombieSize is the number of bytes in zombie tables.
286 : ZombieSize uint64
287 : }
288 : }
289 :
290 : TableCache CacheMetrics
291 :
292 : // Count of the number of open sstable iterators.
293 : TableIters int64
294 : // Uptime is the total time since this DB was opened.
295 : Uptime time.Duration
296 :
297 : WAL struct {
298 : // Number of live WAL files.
299 : Files int64
300 : // Number of obsolete WAL files.
301 : ObsoleteFiles int64
302 : // Physical size of the obsolete WAL files.
303 : ObsoletePhysicalSize uint64
304 : // Size of the live data in the WAL files. Note that with WAL file
305 : // recycling this is less than the actual on-disk size of the WAL files.
306 : Size uint64
307 : // Physical size of the WAL files on-disk. With WAL file recycling,
308 : // this is greater than the live data in WAL files.
309 : //
310 : // TODO(sumeer): it seems this does not include ObsoletePhysicalSize.
311 : // Should the comment be updated?
312 : PhysicalSize uint64
313 : // Number of logical bytes written to the WAL.
314 : BytesIn uint64
315 : // Number of bytes written to the WAL.
316 : BytesWritten uint64
317 : // Failover contains failover stats. Empty if failover is not enabled.
318 : Failover wal.FailoverStats
319 : }
320 :
321 : LogWriter struct {
322 : FsyncLatency prometheus.Histogram
323 : record.LogWriterMetrics
324 : }
325 :
326 : CategoryStats []sstable.CategoryStatsAggregate
327 :
328 : SecondaryCacheMetrics SecondaryCacheMetrics
329 :
330 : private struct {
331 : optionsFileSize uint64
332 : manifestFileSize uint64
333 : }
334 : }
335 :
336 : var (
337 : // FsyncLatencyBuckets are prometheus histogram buckets suitable for a histogram
338 : // that records latencies for fsyncs.
339 : FsyncLatencyBuckets = append(
340 : prometheus.LinearBuckets(0.0, float64(time.Microsecond*100), 50),
341 : prometheus.ExponentialBucketsRange(float64(time.Millisecond*5), float64(10*time.Second), 50)...,
342 : )
343 :
344 : // SecondaryCacheIOBuckets exported to enable exporting from package pebble to
345 : // enable exporting metrics with below buckets in CRDB.
346 : SecondaryCacheIOBuckets = sharedcache.IOBuckets
347 : // SecondaryCacheChannelWriteBuckets exported to enable exporting from package
348 : // pebble to enable exporting metrics with below buckets in CRDB.
349 : SecondaryCacheChannelWriteBuckets = sharedcache.ChannelWriteBuckets
350 : )
351 :
352 : // DiskSpaceUsage returns the total disk space used by the database in bytes,
353 : // including live and obsolete files. This only includes local files, i.e.,
354 : // remote files (as known to objstorage.Provider) are not included.
355 1 : func (m *Metrics) DiskSpaceUsage() uint64 {
356 1 : var usageBytes uint64
357 1 : usageBytes += m.WAL.PhysicalSize
358 1 : usageBytes += m.WAL.ObsoletePhysicalSize
359 1 : usageBytes += m.Table.Local.LiveSize
360 1 : usageBytes += m.Table.Local.ObsoleteSize
361 1 : usageBytes += m.Table.Local.ZombieSize
362 1 : usageBytes += m.private.optionsFileSize
363 1 : usageBytes += m.private.manifestFileSize
364 1 : // TODO(sumeer): InProgressBytes does not distinguish between local and
365 1 : // remote files. This causes a small error. Fix.
366 1 : usageBytes += uint64(m.Compact.InProgressBytes)
367 1 : return usageBytes
368 1 : }
369 :
370 : // NumVirtual is the number of virtual sstables in the latest version
371 : // summed over every level in the lsm.
372 1 : func (m *Metrics) NumVirtual() uint64 {
373 1 : var n uint64
374 1 : for _, level := range m.Levels {
375 1 : n += level.NumVirtualFiles
376 1 : }
377 1 : return n
378 : }
379 :
380 : // VirtualSize is the sum of the sizes of the virtual sstables in the
381 : // latest version. BackingTableSize - VirtualSize gives an estimate for
382 : // the space amplification caused by not compacting virtual sstables.
383 1 : func (m *Metrics) VirtualSize() uint64 {
384 1 : var size uint64
385 1 : for _, level := range m.Levels {
386 1 : size += level.VirtualSize
387 1 : }
388 1 : return size
389 : }
390 :
391 : // ReadAmp returns the current read amplification of the database.
392 : // It's computed as the number of sublevels in L0 + the number of non-empty
393 : // levels below L0.
394 1 : func (m *Metrics) ReadAmp() int {
395 1 : var ramp int32
396 1 : for _, l := range m.Levels {
397 1 : ramp += l.Sublevels
398 1 : }
399 1 : return int(ramp)
400 : }
401 :
402 : // Total returns the sum of the per-level metrics and WAL metrics.
403 2 : func (m *Metrics) Total() LevelMetrics {
404 2 : var total LevelMetrics
405 2 : for level := 0; level < numLevels; level++ {
406 2 : l := &m.Levels[level]
407 2 : total.Add(l)
408 2 : total.Sublevels += l.Sublevels
409 2 : }
410 : // Compute total bytes-in as the bytes written to the WAL + bytes ingested.
411 2 : total.BytesIn = m.WAL.BytesWritten + total.BytesIngested
412 2 : // Add the total bytes-in to the total bytes-flushed. This is to account for
413 2 : // the bytes written to the log and bytes written externally and then
414 2 : // ingested.
415 2 : total.BytesFlushed += total.BytesIn
416 2 : return total
417 : }
418 :
419 : // String pretty-prints the metrics as below:
420 : //
421 : // | | | | ingested | moved | written | | amp
422 : // level | tables size val-bl vtables | score | in | tables size | tables size | tables size | read | r w
423 : // ------+-----------------------------+-------+-------+--------------+--------------+--------------+-------+---------
424 : // 0 | 101 102B 0B 0 | 103.0 | 104B | 112 104B | 113 106B | 221 217B | 107B | 1 2.1
425 : // 1 | 201 202B 0B 0 | 203.0 | 204B | 212 204B | 213 206B | 421 417B | 207B | 2 2.0
426 : // 2 | 301 302B 0B 0 | 303.0 | 304B | 312 304B | 313 306B | 621 617B | 307B | 3 2.0
427 : // 3 | 401 402B 0B 0 | 403.0 | 404B | 412 404B | 413 406B | 821 817B | 407B | 4 2.0
428 : // 4 | 501 502B 0B 0 | 503.0 | 504B | 512 504B | 513 506B | 1.0K 1017B | 507B | 5 2.0
429 : // 5 | 601 602B 0B 0 | 603.0 | 604B | 612 604B | 613 606B | 1.2K 1.2KB | 607B | 6 2.0
430 : // 6 | 701 702B 0B 0 | - | 704B | 712 704B | 713 706B | 1.4K 1.4KB | 707B | 7 2.0
431 : // total | 2.8K 2.7KB 0B 0 | - | 2.8KB | 2.9K 2.8KB | 2.9K 2.8KB | 5.7K 8.4KB | 2.8KB | 28 3.0
432 : // -------------------------------------------------------------------------------------------------------------------
433 : // WAL: 22 files (24B) in: 25B written: 26B (4% overhead)
434 : // Flushes: 8
435 : // Compactions: 5 estimated debt: 6B in progress: 2 (7B)
436 : // default: 27 delete: 28 elision: 29 move: 30 read: 31 rewrite: 32 multi-level: 33
437 : // MemTables: 12 (11B) zombie: 14 (13B)
438 : // Zombie tables: 16 (15B)
439 : // Backing tables: 0 (0B)
440 : // Block cache: 2 entries (1B) hit rate: 42.9%
441 : // Table cache: 18 entries (17B) hit rate: 48.7%
442 : // Secondary cache: 40 entries (40B) hit rate: 49.9%
443 : // Snapshots: 4 earliest seq num: 1024
444 : // Table iters: 21
445 : // Filter utility: 47.4%
446 : // Ingestions: 27 as flushable: 36 (34B in 35 tables)
447 1 : func (m *Metrics) String() string {
448 1 : return redact.StringWithoutMarkers(m)
449 1 : }
450 :
451 : var _ redact.SafeFormatter = &Metrics{}
452 :
453 : // SafeFormat implements redact.SafeFormatter.
454 1 : func (m *Metrics) SafeFormat(w redact.SafePrinter, _ rune) {
455 1 : // NB: Pebble does not make any assumptions as to which Go primitive types
456 1 : // have been registered as safe with redact.RegisterSafeType and does not
457 1 : // register any types itself. Some of the calls to `redact.Safe`, etc are
458 1 : // superfluous in the context of CockroachDB, which registers all the Go
459 1 : // numeric types as safe.
460 1 :
461 1 : // TODO(jackson): There are a few places where we use redact.SafeValue
462 1 : // instead of redact.RedactableString. This is necessary because of a bug
463 1 : // whereby formatting a redact.RedactableString argument does not respect
464 1 : // width specifiers. When the issue is fixed, we can convert these to
465 1 : // RedactableStrings. https://github.com/cockroachdb/redact/issues/17
466 1 :
467 1 : multiExists := m.Compact.MultiLevelCount > 0
468 1 : appendIfMulti := func(line redact.SafeString) {
469 1 : if multiExists {
470 1 : w.SafeString(line)
471 1 : }
472 : }
473 1 : newline := func() {
474 1 : w.SafeString("\n")
475 1 : }
476 :
477 1 : w.SafeString(" | | | | ingested | moved | written | | amp")
478 1 : appendIfMulti(" | multilevel")
479 1 : newline()
480 1 : w.SafeString("level | tables size val-bl vtables | score | in | tables size | tables size | tables size | read | r w")
481 1 : appendIfMulti(" | top in read")
482 1 : newline()
483 1 : w.SafeString("------+-----------------------------+-------+-------+--------------+--------------+--------------+-------+---------")
484 1 : appendIfMulti("-+------------------")
485 1 : newline()
486 1 :
487 1 : // formatRow prints out a row of the table.
488 1 : formatRow := func(m *LevelMetrics, score float64) {
489 1 : scoreStr := "-"
490 1 : if !math.IsNaN(score) {
491 1 : // Try to keep the string no longer than 5 characters.
492 1 : switch {
493 1 : case score < 99.995:
494 1 : scoreStr = fmt.Sprintf("%.2f", score)
495 1 : case score < 999.95:
496 1 : scoreStr = fmt.Sprintf("%.1f", score)
497 0 : default:
498 0 : scoreStr = fmt.Sprintf("%.0f", score)
499 : }
500 : }
501 1 : var wampStr string
502 1 : if wamp := m.WriteAmp(); wamp > 99.5 {
503 0 : wampStr = fmt.Sprintf("%.0f", wamp)
504 1 : } else {
505 1 : wampStr = fmt.Sprintf("%.1f", wamp)
506 1 : }
507 :
508 1 : w.Printf("| %5s %6s %6s %7s | %5s | %5s | %5s %6s | %5s %6s | %5s %6s | %5s | %3d %4s",
509 1 : humanize.Count.Int64(m.NumFiles),
510 1 : humanize.Bytes.Int64(m.Size),
511 1 : humanize.Bytes.Uint64(m.Additional.ValueBlocksSize),
512 1 : humanize.Count.Uint64(m.NumVirtualFiles),
513 1 : redact.Safe(scoreStr),
514 1 : humanize.Bytes.Uint64(m.BytesIn),
515 1 : humanize.Count.Uint64(m.TablesIngested),
516 1 : humanize.Bytes.Uint64(m.BytesIngested),
517 1 : humanize.Count.Uint64(m.TablesMoved),
518 1 : humanize.Bytes.Uint64(m.BytesMoved),
519 1 : humanize.Count.Uint64(m.TablesFlushed+m.TablesCompacted),
520 1 : humanize.Bytes.Uint64(m.BytesFlushed+m.BytesCompacted),
521 1 : humanize.Bytes.Uint64(m.BytesRead),
522 1 : redact.Safe(m.Sublevels),
523 1 : redact.Safe(wampStr))
524 1 :
525 1 : if multiExists {
526 1 : w.Printf(" | %5s %5s %5s",
527 1 : humanize.Bytes.Uint64(m.MultiLevel.BytesInTop),
528 1 : humanize.Bytes.Uint64(m.MultiLevel.BytesIn),
529 1 : humanize.Bytes.Uint64(m.MultiLevel.BytesRead))
530 1 : }
531 1 : newline()
532 : }
533 :
534 1 : var total LevelMetrics
535 1 : for level := 0; level < numLevels; level++ {
536 1 : l := &m.Levels[level]
537 1 : w.Printf("%5d ", redact.Safe(level))
538 1 :
539 1 : // Format the score.
540 1 : score := math.NaN()
541 1 : if level < numLevels-1 {
542 1 : score = l.Score
543 1 : }
544 1 : formatRow(l, score)
545 1 : total.Add(l)
546 1 : total.Sublevels += l.Sublevels
547 : }
548 : // Compute total bytes-in as the bytes written to the WAL + bytes ingested.
549 1 : total.BytesIn = m.WAL.BytesWritten + total.BytesIngested
550 1 : // Add the total bytes-in to the total bytes-flushed. This is to account for
551 1 : // the bytes written to the log and bytes written externally and then
552 1 : // ingested.
553 1 : total.BytesFlushed += total.BytesIn
554 1 : w.SafeString("total ")
555 1 : formatRow(&total, math.NaN())
556 1 :
557 1 : w.SafeString("-------------------------------------------------------------------------------------------------------------------")
558 1 : appendIfMulti("--------------------")
559 1 : newline()
560 1 : w.Printf("WAL: %d files (%s) in: %s written: %s (%.0f%% overhead)",
561 1 : redact.Safe(m.WAL.Files),
562 1 : humanize.Bytes.Uint64(m.WAL.Size),
563 1 : humanize.Bytes.Uint64(m.WAL.BytesIn),
564 1 : humanize.Bytes.Uint64(m.WAL.BytesWritten),
565 1 : redact.Safe(percent(int64(m.WAL.BytesWritten)-int64(m.WAL.BytesIn), int64(m.WAL.BytesIn))))
566 1 : failoverStats := m.WAL.Failover
567 1 : failoverStats.FailoverWriteAndSyncLatency = nil
568 1 : if failoverStats == (wal.FailoverStats{}) {
569 1 : w.Printf("\n")
570 1 : } else {
571 0 : w.Printf(" failover: (switches: %d, primary: %s, secondary: %s)\n", m.WAL.Failover.DirSwitchCount,
572 0 : m.WAL.Failover.PrimaryWriteDuration.String(), m.WAL.Failover.SecondaryWriteDuration.String())
573 0 : }
574 :
575 1 : w.Printf("Flushes: %d\n", redact.Safe(m.Flush.Count))
576 1 :
577 1 : w.Printf("Compactions: %d estimated debt: %s in progress: %d (%s)\n",
578 1 : redact.Safe(m.Compact.Count),
579 1 : humanize.Bytes.Uint64(m.Compact.EstimatedDebt),
580 1 : redact.Safe(m.Compact.NumInProgress),
581 1 : humanize.Bytes.Int64(m.Compact.InProgressBytes))
582 1 :
583 1 : w.Printf(" default: %d delete: %d elision: %d move: %d read: %d rewrite: %d copy: %d multi-level: %d\n",
584 1 : redact.Safe(m.Compact.DefaultCount),
585 1 : redact.Safe(m.Compact.DeleteOnlyCount),
586 1 : redact.Safe(m.Compact.ElisionOnlyCount),
587 1 : redact.Safe(m.Compact.MoveCount),
588 1 : redact.Safe(m.Compact.ReadCount),
589 1 : redact.Safe(m.Compact.RewriteCount),
590 1 : redact.Safe(m.Compact.CopyCount),
591 1 : redact.Safe(m.Compact.MultiLevelCount))
592 1 :
593 1 : w.Printf("MemTables: %d (%s) zombie: %d (%s)\n",
594 1 : redact.Safe(m.MemTable.Count),
595 1 : humanize.Bytes.Uint64(m.MemTable.Size),
596 1 : redact.Safe(m.MemTable.ZombieCount),
597 1 : humanize.Bytes.Uint64(m.MemTable.ZombieSize))
598 1 :
599 1 : w.Printf("Zombie tables: %d (%s, local: %s)\n",
600 1 : redact.Safe(m.Table.ZombieCount),
601 1 : humanize.Bytes.Uint64(m.Table.ZombieSize),
602 1 : humanize.Bytes.Uint64(m.Table.Local.ZombieSize))
603 1 :
604 1 : w.Printf("Backing tables: %d (%s)\n",
605 1 : redact.Safe(m.Table.BackingTableCount),
606 1 : humanize.Bytes.Uint64(m.Table.BackingTableSize))
607 1 : w.Printf("Virtual tables: %d (%s)\n",
608 1 : redact.Safe(m.NumVirtual()),
609 1 : humanize.Bytes.Uint64(m.VirtualSize()))
610 1 : w.Printf("Local tables size: %s\n", humanize.Bytes.Uint64(m.Table.Local.LiveSize))
611 1 : w.SafeString("Compression types:")
612 1 : if count := m.Table.CompressedCountSnappy; count > 0 {
613 1 : w.Printf(" snappy: %d", redact.Safe(count))
614 1 : }
615 1 : if count := m.Table.CompressedCountZstd; count > 0 {
616 0 : w.Printf(" zstd: %d", redact.Safe(count))
617 0 : }
618 1 : if count := m.Table.CompressedCountNone; count > 0 {
619 0 : w.Printf(" none: %d", redact.Safe(count))
620 0 : }
621 1 : if count := m.Table.CompressedCountUnknown; count > 0 {
622 1 : w.Printf(" unknown: %d", redact.Safe(count))
623 1 : }
624 1 : w.Print("\n")
625 1 :
626 1 : formatCacheMetrics := func(m *CacheMetrics, name redact.SafeString) {
627 1 : w.Printf("%s: %s entries (%s) hit rate: %.1f%%\n",
628 1 : name,
629 1 : humanize.Count.Int64(m.Count),
630 1 : humanize.Bytes.Int64(m.Size),
631 1 : redact.Safe(hitRate(m.Hits, m.Misses)))
632 1 : }
633 1 : formatCacheMetrics(&m.BlockCache, "Block cache")
634 1 : formatCacheMetrics(&m.TableCache, "Table cache")
635 1 :
636 1 : formatSharedCacheMetrics := func(w redact.SafePrinter, m *SecondaryCacheMetrics, name redact.SafeString) {
637 1 : w.Printf("%s: %s entries (%s) hit rate: %.1f%%\n",
638 1 : name,
639 1 : humanize.Count.Int64(m.Count),
640 1 : humanize.Bytes.Int64(m.Size),
641 1 : redact.Safe(hitRate(m.ReadsWithFullHit, m.ReadsWithPartialHit+m.ReadsWithNoHit)))
642 1 : }
643 1 : formatSharedCacheMetrics(w, &m.SecondaryCacheMetrics, "Secondary cache")
644 1 :
645 1 : w.Printf("Snapshots: %d earliest seq num: %d\n",
646 1 : redact.Safe(m.Snapshots.Count),
647 1 : redact.Safe(m.Snapshots.EarliestSeqNum))
648 1 :
649 1 : w.Printf("Table iters: %d\n", redact.Safe(m.TableIters))
650 1 : w.Printf("Filter utility: %.1f%%\n", redact.Safe(hitRate(m.Filter.Hits, m.Filter.Misses)))
651 1 : w.Printf("Ingestions: %d as flushable: %d (%s in %d tables)\n",
652 1 : redact.Safe(m.Ingest.Count),
653 1 : redact.Safe(m.Flush.AsIngestCount),
654 1 : humanize.Bytes.Uint64(m.Flush.AsIngestBytes),
655 1 : redact.Safe(m.Flush.AsIngestTableCount))
656 : }
657 :
658 1 : func hitRate(hits, misses int64) float64 {
659 1 : return percent(hits, hits+misses)
660 1 : }
661 :
662 1 : func percent(numerator, denominator int64) float64 {
663 1 : if denominator == 0 {
664 1 : return 0
665 1 : }
666 1 : return 100 * float64(numerator) / float64(denominator)
667 : }
668 :
669 : // StringForTests is identical to m.String() on 64-bit platforms. It is used to
670 : // provide a platform-independent result for tests.
671 1 : func (m *Metrics) StringForTests() string {
672 1 : mCopy := *m
673 1 : if math.MaxInt == math.MaxInt32 {
674 0 : // This is the difference in Sizeof(sstable.Reader{})) between 64 and 32 bit
675 0 : // platforms.
676 0 : const tableCacheSizeAdjustment = 212
677 0 : mCopy.TableCache.Size += mCopy.TableCache.Count * tableCacheSizeAdjustment
678 0 : }
679 1 : return redact.StringWithoutMarkers(&mCopy)
680 : }
|