提交 7a5f71d1 编写于 作者: A Abhishek Kona

[Rocksdb] measure table open io in a histogram

Summary: Table is setup for compaction using Table::SetupForCompaction. So read block calls can be differentiated b/w Gets/Compaction. Use this and measure times.

Test Plan: db_bench --statistics=1

Reviewers: dhruba, haobo

Reviewed By: haobo

CC: leveldb, MarkCallaghan

Differential Revision: https://reviews.facebook.net/D11217
上级 0c2a2dd5
......@@ -100,7 +100,7 @@ Iterator* TableCache::NewIterator(const ReadOptions& options,
}
if (for_compaction) {
table->SetAccessHintForCompaction();
table->SetupForCompaction();
}
return result;
......
......@@ -103,10 +103,13 @@ enum Histograms {
// TIME SPENT IN IO DURING TABLE OPEN
TABLE_OPEN_IO_MICROS = 7,
DB_MULTIGET = 8,
HISTOGRAM_ENUM_MAX = 9
READ_BLOCK_COMPACTION_MICROS = 9,
READ_BLOCK_GET_MICROS = 10,
HISTOGRAM_ENUM_MAX = 11
};
const std::vector<std::pair<Histograms, std::string>> HistogramsNameMap = {
// Over 80 char by choice
std::make_pair(DB_GET, "rocksdb.db.get.micros"),
std::make_pair(DB_WRITE, "rocksdb.db.write.micros"),
std::make_pair(COMPACTION_TIME, "rocksdb.compaction.times.micros"),
......@@ -115,7 +118,9 @@ const std::vector<std::pair<Histograms, std::string>> HistogramsNameMap = {
std::make_pair(WAL_FILE_SYNC_MICROS, "rocksdb.wal.file.sync.micros"),
std::make_pair(MANIFEST_FILE_SYNC_MICROS, "rocksdb.manifest.file.sync.micros"),
std::make_pair(TABLE_OPEN_IO_MICROS, "rocksdb.table.open.io.micros"),
std::make_pair(DB_MULTIGET, "rocksdb.db.multiget.micros")
std::make_pair(DB_MULTIGET, "rocksdb.db.multiget.micros"),
std::make_pair(READ_BLOCK_COMPACTION_MICROS, "rocksdb.read.block.compaction.micros"),
std::make_pair(READ_BLOCK_GET_MICROS, "rocksdb.read.block.get.micros")
};
struct HistogramData {
......
......@@ -2,18 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "table/table.h"
#include "leveldb/cache.h"
#include "leveldb/comparator.h"
#include "leveldb/env.h"
#include "leveldb/filter_policy.h"
#include "leveldb/options.h"
#include "leveldb/statistics.h"
#include "table/block.h"
#include "table/filter_block.h"
#include "table/format.h"
#include "table/table.h"
#include "table/two_level_iterator.h"
#include "util/coding.h"
#include "util/stop_watch.h"
namespace leveldb {
......@@ -141,7 +145,7 @@ Status Table::Open(const Options& options,
return s;
}
void Table::SetAccessHintForCompaction() {
void Table::SetupForCompaction() {
switch (rep_->options.access_hint_on_compaction_start) {
case Options::NONE:
break;
......@@ -157,6 +161,7 @@ void Table::SetAccessHintForCompaction() {
default:
assert(false);
}
compaction_optimized_ = true;
}
void Table::ReadMeta(const Footer& footer) {
......@@ -229,7 +234,8 @@ static void ReleaseBlock(void* arg, void* h) {
Iterator* Table::BlockReader(void* arg,
const ReadOptions& options,
const Slice& index_value,
bool* didIO) {
bool* didIO,
bool for_compaction) {
Table* table = reinterpret_cast<Table*>(arg);
Cache* block_cache = table->rep_->options.block_cache.get();
std::shared_ptr<Statistics> statistics = table->rep_->options.statistics;
......@@ -259,7 +265,18 @@ Iterator* Table::BlockReader(void* arg,
RecordTick(statistics, BLOCK_CACHE_HIT);
} else {
s = ReadBlock(table->rep_->file.get(), options, handle, &block, didIO);
Histograms histogram = for_compaction ?
READ_BLOCK_COMPACTION_MICROS : READ_BLOCK_GET_MICROS;
{ // block for stop watch
StopWatch sw(table->rep_->options.env, statistics, histogram);
s = ReadBlock(
table->rep_->file.get(),
options,
handle,
&block,
didIO
);
}
if (s.ok()) {
if (block->isCachable() && options.fill_cache) {
cache_handle = block_cache->Insert(
......@@ -293,7 +310,7 @@ Iterator* Table::BlockReader(void* arg,
const EnvOptions& soptions,
const Slice& index_value,
bool for_compaction) {
return BlockReader(arg, options, index_value, nullptr);
return BlockReader(arg, options, index_value, nullptr, for_compaction);
}
Iterator* Table::NewIterator(const ReadOptions& options) const {
......
......@@ -64,18 +64,20 @@ class Table {
// REQUIRES: key is in this table.
bool TEST_KeyInCache(const ReadOptions& options, const Slice& key);
void SetAccessHintForCompaction();
// Set up the table for Compaction. Might change some parameters with
// posix_fadvise
void SetupForCompaction();
private:
struct Rep;
Rep* rep_;
explicit Table(Rep* rep) { rep_ = rep; }
bool compaction_optimized_;
explicit Table(Rep* rep) : compaction_optimized_(false) { rep_ = rep; }
static Iterator* BlockReader(void*, const ReadOptions&,
const EnvOptions& soptions, const Slice&,
bool for_compaction);
static Iterator* BlockReader(void*, const ReadOptions&, const Slice&,
bool* didIO);
bool* didIO, bool for_compaction = false);
// Calls (*handle_result)(arg, ...) repeatedly, starting with the entry found
// after a call to Seek(key), until handle_result returns false.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册