Skip to content

Commit f04d4f9

Browse files
rohansuridaverigby
authored andcommitted
MB-46907 Move Couchstore file system histograms to CouchKVStore
Couchstore specific file system histograms are kept in KVStore. These are not used by any other KVStore implementation, hence can be moved inside CouchKVStore itself. Stats dependent on these histograms are also moved inside CouchKVStore. Change-Id: Ib80b2cfa8878de22b8d342443e42466a976f1b19 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/156145 Reviewed-by: Dave Rigby <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 9bed8e4 commit f04d4f9

File tree

4 files changed

+111
-81
lines changed

4 files changed

+111
-81
lines changed

engines/ep/src/couch-kvstore/couch-kvstore.cc

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "kvstore_config.h"
2323
#include "persistence_callback.h"
2424
#include "rollback_result.h"
25+
#include "statistics/cbstat_collector.h"
2526
#include "vb_commit.h"
2627
#include "vbucket.h"
2728
#include "vbucket_bgfetch_item.h"
@@ -353,9 +354,9 @@ CouchKVStore::CouchKVStore(const CouchKVStoreConfig& config,
353354
std::vector<std::atomic_bool>(configuration.getMaxVBuckets());
354355
vbAbortCompaction =
355356
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);
359360

360361
// init db file map with default revision number, 1
361362
auto numDbFiles = configuration.getMaxVBuckets();
@@ -398,6 +399,84 @@ CouchKVStore::CouchKVStore(const CouchKVStoreConfig& config,
398399
initialize(map);
399400
}
400401

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+
401480
void CouchKVStore::initialize(
402481
const std::unordered_map<Vbid, std::unordered_set<uint64_t>>& map) {
403482
for (const auto& [vbid, revisions] : map) {
@@ -1973,21 +2052,21 @@ bool CouchKVStore::getStat(std::string_view name, size_t& value) const {
19732052
value = st.io_document_write_bytes;
19742053
return true;
19752054
} else if (name == "io_flusher_write_bytes") {
1976-
value = st.fsStats.totalBytesWritten;
2055+
value = fsStats.totalBytesWritten;
19772056
return true;
19782057
} 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();
19812060
return true;
19822061
} 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();
19852064
return true;
19862065
} else if (name == "io_compaction_read_bytes") {
1987-
value = st.fsStatsCompaction.totalBytesRead;
2066+
value = fsStatsCompaction.totalBytesRead;
19882067
return true;
19892068
} else if (name == "io_compaction_write_bytes") {
1990-
value = st.fsStatsCompaction.totalBytesWritten;
2069+
value = fsStatsCompaction.totalBytesWritten;
19912070
return true;
19922071
} else if (name == "io_bg_fetch_read_count") {
19932072
value = st.getMultiFsReadCount;

engines/ep/src/couch-kvstore/couch-kvstore.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ class CouchKVStore : public KVStore
196196

197197
using KVStore::get;
198198

199+
void addTimingStats(const AddStatFn& add_stat,
200+
const CookieIface* c) const override;
201+
202+
size_t getMemFootPrint() const override;
203+
204+
void resetStats() override;
205+
206+
void addStats(const AddStatFn& add_stat,
207+
const void* c,
208+
const std::string& args) const override;
209+
199210
GetValue getWithHeader(const KVFileHandle& kvFileHandle,
200211
const DiskDocKey& key,
201212
Vbid vb,
@@ -945,15 +956,15 @@ class CouchKVStore : public KVStore
945956
* FileOpsInterface implementation for couchstore which tracks
946957
* all bytes read/written by couchstore *except* compaction.
947958
*
948-
* Backed by this->st.fsStats
959+
* Backed by this->fsStats
949960
*/
950961
std::unique_ptr<FileOpsInterface> statCollectingFileOps;
951962

952963
/**
953964
* FileOpsInterface implementation for couchstore which tracks
954965
* all bytes read/written by couchstore just for compaction
955966
*
956-
* Backed by this->st.fsStatsCompaction
967+
* Backed by this->fsStatsCompaction
957968
*/
958969
std::unique_ptr<FileOpsInterface> statCollectingFileOpsCompaction;
959970

@@ -1030,4 +1041,11 @@ class CouchKVStore : public KVStore
10301041
/// re-acquired. This allows the actual flusher to run in the hook rather
10311042
/// poking the kvstore manually
10321043
TestingHook<const std::string&> concurrentCompactionPreLockHook;
1044+
1045+
private:
1046+
// Stats from the underlying OS file operations
1047+
FileStats fsStats;
1048+
1049+
// Underlying stats for OS file operations during compaction
1050+
FileStats fsStatsCompaction;
10331051
};

engines/ep/src/kvstore.cc

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ void KVStoreStats::reset() {
174174
getMultiFsReadHisto.reset();
175175
getMultiFsReadPerDocHisto.reset();
176176
flusherWriteAmplificationHisto.reset();
177-
178-
fsStats.reset();
179-
fsStatsCompaction.reset();
180177
}
181178

182179
std::unique_ptr<KVStore> KVStoreFactory::create(KVStoreConfig& config) {
@@ -406,45 +403,6 @@ void KVStore::addStats(const AddStatFn& add_stat,
406403
st.io_document_write_bytes,
407404
add_stat,
408405
c);
409-
410-
const size_t read = st.fsStats.totalBytesRead.load() +
411-
st.fsStatsCompaction.totalBytesRead.load();
412-
add_prefixed_stat(prefix, "io_total_read_bytes", read, add_stat, c);
413-
414-
const size_t written = st.fsStats.totalBytesWritten.load() +
415-
st.fsStatsCompaction.totalBytesWritten.load();
416-
add_prefixed_stat(prefix, "io_total_write_bytes", written, add_stat, c);
417-
418-
// Flusher Write Amplification - ratio of bytes written to disk by
419-
// flusher to "useful" user data written - i.e. doesn't include bytes
420-
// written later by compaction (after initial flush). Used to measure
421-
// the impact of KVstore on persistTo times.
422-
const double flusherWriteAmp = double(st.fsStats.totalBytesWritten.load()) /
423-
st.io_document_write_bytes;
424-
add_prefixed_stat(prefix,
425-
"io_flusher_write_amplification",
426-
flusherWriteAmp,
427-
add_stat,
428-
c);
429-
430-
// Total Write Amplification - ratio of total bytes written to disk
431-
// to "useful" user data written over entire disk lifecycle. Includes
432-
// bytes during initial item flush to disk and compaction.
433-
// Used to measure the overall write amplification.
434-
const double totalWriteAmp = double(written) / st.io_document_write_bytes;
435-
add_prefixed_stat(
436-
prefix, "io_total_write_amplification", totalWriteAmp, add_stat, c);
437-
438-
add_prefixed_stat(prefix,
439-
"io_compaction_read_bytes",
440-
st.fsStatsCompaction.totalBytesRead,
441-
add_stat,
442-
c);
443-
add_prefixed_stat(prefix,
444-
"io_compaction_write_bytes",
445-
st.fsStatsCompaction.totalBytesWritten,
446-
add_stat,
447-
c);
448406
}
449407

450408
void KVStore::addTimingStats(const AddStatFn& add_stat,
@@ -474,24 +432,6 @@ void KVStore::addTimingStats(const AddStatFn& add_stat,
474432
st.flusherWriteAmplificationHisto,
475433
add_stat,
476434
c);
477-
478-
//file ops stats
479-
add_prefixed_stat(
480-
prefix, "fsReadTime", st.fsStats.readTimeHisto, add_stat, c);
481-
add_prefixed_stat(
482-
prefix, "fsWriteTime", st.fsStats.writeTimeHisto, add_stat, c);
483-
add_prefixed_stat(
484-
prefix, "fsSyncTime", st.fsStats.syncTimeHisto, add_stat, c);
485-
add_prefixed_stat(
486-
prefix, "fsReadSize", st.fsStats.readSizeHisto, add_stat, c);
487-
add_prefixed_stat(
488-
prefix, "fsWriteSize", st.fsStats.writeSizeHisto, add_stat, c);
489-
add_prefixed_stat(
490-
prefix, "fsReadSeek", st.fsStats.readSeekHisto, add_stat, c);
491-
add_prefixed_stat(
492-
prefix, "fsReadCount", st.fsStats.readCountHisto, add_stat, c);
493-
add_prefixed_stat(
494-
prefix, "fsWriteCount", st.fsStats.writeCountHisto, add_stat, c);
495435
}
496436

497437
void KVStore::optimizeWrites(std::vector<queued_item>& items) {

engines/ep/src/kvstore.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,6 @@ class KVStoreStats {
515515
HdrHistogram flusherWriteAmplificationHisto{
516516
1, 1000, 2, HdrHistogram::Iterator::IterMode::Percentiles};
517517

518-
// Stats from the underlying OS file operations
519-
FileStats fsStats;
520-
521-
// Underlying stats for OS file operations during compaction
522-
FileStats fsStatsCompaction;
523-
524518
size_t getMemFootPrint() const {
525519
return readTimeHisto.getMemFootPrint() +
526520
readSizeHisto.getMemFootPrint() +
@@ -531,7 +525,6 @@ class KVStoreStats {
531525
saveDocsHisto.getMemFootPrint() + batchSize.getMemFootPrint() +
532526
getMultiFsReadHisto.getMemFootPrint() +
533527
getMultiFsReadPerDocHisto.getMemFootPrint() +
534-
fsStats.getMemFootPrint() + fsStatsCompaction.getMemFootPrint() +
535528
flusherWriteAmplificationHisto.getMemFootPrint();
536529
}
537530
};
@@ -681,11 +674,11 @@ class KVStore {
681674
/**
682675
* Resets kvstore specific stats
683676
*/
684-
void resetStats() {
677+
virtual void resetStats() {
685678
st.reset();
686679
}
687680

688-
size_t getMemFootPrint() const {
681+
virtual size_t getMemFootPrint() const {
689682
return st.getMemFootPrint();
690683
}
691684

0 commit comments

Comments
 (0)