|
22 | 22 | #include "kvstore_config.h" |
23 | 23 | #include "persistence_callback.h" |
24 | 24 | #include "rollback_result.h" |
| 25 | +#include "statistics/cbstat_collector.h" |
25 | 26 | #include "vb_commit.h" |
26 | 27 | #include "vbucket.h" |
27 | 28 | #include "vbucket_bgfetch_item.h" |
@@ -353,9 +354,9 @@ CouchKVStore::CouchKVStore(const CouchKVStoreConfig& config, |
353 | 354 | std::vector<std::atomic_bool>(configuration.getMaxVBuckets()); |
354 | 355 | vbAbortCompaction = |
355 | 356 | std::vector<std::atomic_bool>(configuration.getMaxVBuckets()); |
356 | | - statCollectingFileOps = getCouchstoreStatsOps(st.fsStats, base_ops); |
357 | | - statCollectingFileOpsCompaction = getCouchstoreStatsOps( |
358 | | - st.fsStatsCompaction, base_ops); |
| 357 | + statCollectingFileOps = getCouchstoreStatsOps(fsStats, base_ops); |
| 358 | + statCollectingFileOpsCompaction = |
| 359 | + getCouchstoreStatsOps(fsStatsCompaction, base_ops); |
359 | 360 |
|
360 | 361 | // init db file map with default revision number, 1 |
361 | 362 | auto numDbFiles = configuration.getMaxVBuckets(); |
@@ -398,6 +399,84 @@ CouchKVStore::CouchKVStore(const CouchKVStoreConfig& config, |
398 | 399 | initialize(map); |
399 | 400 | } |
400 | 401 |
|
| 402 | +size_t CouchKVStore::getMemFootPrint() const { |
| 403 | + return KVStore::getMemFootPrint() + fsStats.getMemFootPrint() + |
| 404 | + fsStatsCompaction.getMemFootPrint(); |
| 405 | +} |
| 406 | + |
| 407 | +void CouchKVStore::resetStats() { |
| 408 | + KVStore::resetStats(); |
| 409 | + fsStats.reset(); |
| 410 | + fsStatsCompaction.reset(); |
| 411 | +} |
| 412 | + |
| 413 | +void CouchKVStore::addStats(const AddStatFn& add_stat, |
| 414 | + const void* c, |
| 415 | + const std::string& args) const { |
| 416 | + KVStore::addStats(add_stat, c, args); |
| 417 | + const auto prefix = getStatsPrefix(); |
| 418 | + |
| 419 | + const size_t read = fsStats.totalBytesRead.load() + |
| 420 | + fsStatsCompaction.totalBytesRead.load(); |
| 421 | + add_prefixed_stat(prefix, "io_total_read_bytes", read, add_stat, c); |
| 422 | + |
| 423 | + const size_t written = fsStats.totalBytesWritten.load() + |
| 424 | + fsStatsCompaction.totalBytesWritten.load(); |
| 425 | + add_prefixed_stat(prefix, "io_total_write_bytes", written, add_stat, c); |
| 426 | + |
| 427 | + // Flusher Write Amplification - ratio of bytes written to disk by |
| 428 | + // flusher to "useful" user data written - i.e. doesn't include bytes |
| 429 | + // written later by compaction (after initial flush). Used to measure |
| 430 | + // the impact of KVstore on persistTo times. |
| 431 | + const double flusherWriteAmp = double(fsStats.totalBytesWritten.load()) / |
| 432 | + st.io_document_write_bytes; |
| 433 | + add_prefixed_stat(prefix, |
| 434 | + "io_flusher_write_amplification", |
| 435 | + flusherWriteAmp, |
| 436 | + add_stat, |
| 437 | + c); |
| 438 | + |
| 439 | + // Total Write Amplification - ratio of total bytes written to disk |
| 440 | + // to "useful" user data written over entire disk lifecycle. Includes |
| 441 | + // bytes during initial item flush to disk and compaction. |
| 442 | + // Used to measure the overall write amplification. |
| 443 | + const double totalWriteAmp = double(written) / st.io_document_write_bytes; |
| 444 | + add_prefixed_stat( |
| 445 | + prefix, "io_total_write_amplification", totalWriteAmp, add_stat, c); |
| 446 | + |
| 447 | + add_prefixed_stat(prefix, |
| 448 | + "io_compaction_read_bytes", |
| 449 | + fsStatsCompaction.totalBytesRead, |
| 450 | + add_stat, |
| 451 | + c); |
| 452 | + add_prefixed_stat(prefix, |
| 453 | + "io_compaction_write_bytes", |
| 454 | + fsStatsCompaction.totalBytesWritten, |
| 455 | + add_stat, |
| 456 | + c); |
| 457 | +} |
| 458 | + |
| 459 | +void CouchKVStore::addTimingStats(const AddStatFn& add_stat, |
| 460 | + const CookieIface* c) const { |
| 461 | + KVStore::addTimingStats(add_stat, c); |
| 462 | + |
| 463 | + const auto prefix = getStatsPrefix(); |
| 464 | + |
| 465 | + // file ops stats. |
| 466 | + add_prefixed_stat(prefix, "fsReadTime", fsStats.readTimeHisto, add_stat, c); |
| 467 | + add_prefixed_stat( |
| 468 | + prefix, "fsWriteTime", fsStats.writeTimeHisto, add_stat, c); |
| 469 | + add_prefixed_stat(prefix, "fsSyncTime", fsStats.syncTimeHisto, add_stat, c); |
| 470 | + add_prefixed_stat(prefix, "fsReadSize", fsStats.readSizeHisto, add_stat, c); |
| 471 | + add_prefixed_stat( |
| 472 | + prefix, "fsWriteSize", fsStats.writeSizeHisto, add_stat, c); |
| 473 | + add_prefixed_stat(prefix, "fsReadSeek", fsStats.readSeekHisto, add_stat, c); |
| 474 | + add_prefixed_stat( |
| 475 | + prefix, "fsReadCount", fsStats.readCountHisto, add_stat, c); |
| 476 | + add_prefixed_stat( |
| 477 | + prefix, "fsWriteCount", fsStats.writeCountHisto, add_stat, c); |
| 478 | +} |
| 479 | + |
401 | 480 | void CouchKVStore::initialize( |
402 | 481 | const std::unordered_map<Vbid, std::unordered_set<uint64_t>>& map) { |
403 | 482 | for (const auto& [vbid, revisions] : map) { |
@@ -1973,21 +2052,21 @@ bool CouchKVStore::getStat(std::string_view name, size_t& value) const { |
1973 | 2052 | value = st.io_document_write_bytes; |
1974 | 2053 | return true; |
1975 | 2054 | } else if (name == "io_flusher_write_bytes") { |
1976 | | - value = st.fsStats.totalBytesWritten; |
| 2055 | + value = fsStats.totalBytesWritten; |
1977 | 2056 | return true; |
1978 | 2057 | } else if (name == "io_total_read_bytes") { |
1979 | | - value = st.fsStats.totalBytesRead.load() + |
1980 | | - st.fsStatsCompaction.totalBytesRead.load(); |
| 2058 | + value = fsStats.totalBytesRead.load() + |
| 2059 | + fsStatsCompaction.totalBytesRead.load(); |
1981 | 2060 | return true; |
1982 | 2061 | } else if (name == "io_total_write_bytes") { |
1983 | | - value = st.fsStats.totalBytesWritten.load() + |
1984 | | - st.fsStatsCompaction.totalBytesWritten.load(); |
| 2062 | + value = fsStats.totalBytesWritten.load() + |
| 2063 | + fsStatsCompaction.totalBytesWritten.load(); |
1985 | 2064 | return true; |
1986 | 2065 | } else if (name == "io_compaction_read_bytes") { |
1987 | | - value = st.fsStatsCompaction.totalBytesRead; |
| 2066 | + value = fsStatsCompaction.totalBytesRead; |
1988 | 2067 | return true; |
1989 | 2068 | } else if (name == "io_compaction_write_bytes") { |
1990 | | - value = st.fsStatsCompaction.totalBytesWritten; |
| 2069 | + value = fsStatsCompaction.totalBytesWritten; |
1991 | 2070 | return true; |
1992 | 2071 | } else if (name == "io_bg_fetch_read_count") { |
1993 | 2072 | value = st.getMultiFsReadCount; |
|
0 commit comments