From aeb4612685c0ab83db367d9ab83fb8f704234049 Mon Sep 17 00:00:00 2001 From: Manuel Ung Date: Fri, 11 Sep 2015 11:37:44 -0700 Subject: [PATCH] Add counters for seek/next/prev Summary: There are currently no statistics on seeks, only on gets. This adds the following counters: rocksdb.number.db.seek rocksdb.number.db.next rocksdb.number.db.prev (number of calls) rocksdb.db.iterate.bytes.read (number of bytes read from key + value using seek/next/prev) rocksdb.number.keys.seek.found rocksdb.number.keys.next.found rocksdb.number.keys.prev.found (number of calls where seek/next/prev found a value) Test Plan: ./db_bench -statistics -benchmarks fillrandom,seekrandom -seek_nexts 5 ./db_bench -statistics -benchmarks fillrandom,seekrandom -seek_nexts 5 -reverse_iterator Reviewers: yhchiang, rven, kradhakrishnan, IslamAbdelRahman, MarkCallaghan, sdong, igor Reviewed By: sdong Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D46605 --- db/db_iter.cc | 35 +++++++++++++++++++++++++++++++++++ include/rocksdb/statistics.h | 18 ++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/db/db_iter.cc b/db/db_iter.cc index 587da72adf..571e8ee2ae 100644 --- a/db/db_iter.cc +++ b/db/db_iter.cc @@ -189,6 +189,13 @@ void DBIter::Next() { return; } FindNextUserEntry(true /* skipping the current user key */); + if (statistics_ != nullptr) { + RecordTick(statistics_, NUMBER_DB_NEXT); + if (valid_) { + RecordTick(statistics_, NUMBER_DB_NEXT_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } // PRE: saved_key_ has the current user key if skipping @@ -355,6 +362,13 @@ void DBIter::Prev() { ReverseToBackward(); } PrevInternal(); + if (statistics_ != nullptr) { + RecordTick(statistics_, NUMBER_DB_PREV); + if (valid_) { + RecordTick(statistics_, NUMBER_DB_PREV_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } void DBIter::ReverseToBackward() { @@ -637,10 +651,17 @@ void DBIter::Seek(const Slice& target) { iter_->Seek(saved_key_.GetKey()); } + RecordTick(statistics_, NUMBER_DB_SEEK); if (iter_->Valid()) { direction_ = kForward; ClearSavedValue(); FindNextUserEntry(false /* not skipping */); + if (statistics_ != nullptr) { + if (valid_) { + RecordTick(statistics_, NUMBER_DB_SEEK_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } else { valid_ = false; } @@ -660,8 +681,15 @@ void DBIter::SeekToFirst() { iter_->SeekToFirst(); } + RecordTick(statistics_, NUMBER_DB_SEEK); if (iter_->Valid()) { FindNextUserEntry(false /* not skipping */); + if (statistics_ != nullptr) { + if (valid_) { + RecordTick(statistics_, NUMBER_DB_SEEK_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } else { valid_ = false; } @@ -703,6 +731,13 @@ void DBIter::SeekToLast() { } } PrevInternal(); + if (statistics_ != nullptr) { + RecordTick(statistics_, NUMBER_DB_SEEK); + if (valid_) { + RecordTick(statistics_, NUMBER_DB_SEEK_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } Iterator* NewDBIterator(Env* env, const ImmutableCFOptions& ioptions, diff --git a/include/rocksdb/statistics.h b/include/rocksdb/statistics.h index 2aa1ce7a09..5d610c15af 100644 --- a/include/rocksdb/statistics.h +++ b/include/rocksdb/statistics.h @@ -82,6 +82,17 @@ enum Tickers : uint32_t { // For the number of logical bytes read from DB::MultiGet(), // please use NUMBER_MULTIGET_BYTES_READ. BYTES_READ, + // The number of calls to seek/next/prev + NUMBER_DB_SEEK, + NUMBER_DB_NEXT, + NUMBER_DB_PREV, + // The number of calls to seek/next/prev that returned data + NUMBER_DB_SEEK_FOUND, + NUMBER_DB_NEXT_FOUND, + NUMBER_DB_PREV_FOUND, + // The number of uncompressed bytes read from an iterator. + // Includes size of key and value. + ITER_BYTES_READ, NO_FILE_CLOSES, NO_FILE_OPENS, NO_FILE_ERRORS, @@ -180,6 +191,13 @@ const std::vector> TickersNameMap = { {NUMBER_KEYS_UPDATED, "rocksdb.number.keys.updated"}, {BYTES_WRITTEN, "rocksdb.bytes.written"}, {BYTES_READ, "rocksdb.bytes.read"}, + {NUMBER_DB_SEEK, "rocksdb.number.db.seek"}, + {NUMBER_DB_NEXT, "rocksdb.number.db.next"}, + {NUMBER_DB_PREV, "rocksdb.number.db.prev"}, + {NUMBER_DB_SEEK_FOUND, "rocksdb.number.db.seek.found"}, + {NUMBER_DB_NEXT_FOUND, "rocksdb.number.db.next.found"}, + {NUMBER_DB_PREV_FOUND, "rocksdb.number.db.prev.found"}, + {ITER_BYTES_READ, "rocksdb.db.iter.bytes.read"}, {NO_FILE_CLOSES, "rocksdb.no.file.closes"}, {NO_FILE_OPENS, "rocksdb.no.file.opens"}, {NO_FILE_ERRORS, "rocksdb.no.file.errors"},