Skip to content

Commit

Permalink
Add write_memtable_time to perf level kEnableWait (facebook#12394)
Browse files Browse the repository at this point in the history
Summary:
.. so write time can be measured under the new perf level for single-threaded writes.

Pull Request resolved: facebook#12394

Test Plan: * add a new UT `PerfContextTest.WriteMemtableTimePerfLevel`

Reviewed By: anand1976

Differential Revision: D54326263

Pulled By: cbi42

fbshipit-source-id: d0e334d9581851ba6cf53c776c0bd876365d1e00
  • Loading branch information
cbi42 authored and facebook-github-bot committed Feb 29, 2024
1 parent 13ef21c commit 4aed229
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions db/db_impl/db_impl_write.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options,

if (w.ShouldWriteToMemtable()) {
PERF_TIMER_STOP(write_pre_and_post_process_time);
PERF_TIMER_GUARD(write_memtable_time);
PERF_TIMER_FOR_WAIT_GUARD(write_memtable_time);

ColumnFamilyMemTablesImpl column_family_memtables(
versions_->GetColumnFamilySet());
Expand Down Expand Up @@ -557,7 +557,7 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options,
}

if (status.ok()) {
PERF_TIMER_GUARD(write_memtable_time);
PERF_TIMER_FOR_WAIT_GUARD(write_memtable_time);

if (!parallel) {
// w.sequence will be set inside InsertInto
Expand Down Expand Up @@ -797,7 +797,7 @@ Status DBImpl::PipelinedWriteImpl(const WriteOptions& write_options,
WriteThread::WriteGroup memtable_write_group;

if (w.state == WriteThread::STATE_MEMTABLE_WRITER_LEADER) {
PERF_TIMER_GUARD(write_memtable_time);
PERF_TIMER_FOR_WAIT_GUARD(write_memtable_time);
assert(w.ShouldWriteToMemtable());
write_thread_.EnterAsMemTableWriter(&w, &memtable_write_group);
if (memtable_write_group.size > 1 &&
Expand All @@ -820,7 +820,7 @@ Status DBImpl::PipelinedWriteImpl(const WriteOptions& write_options,

if (w.state == WriteThread::STATE_PARALLEL_MEMTABLE_WRITER) {
PERF_TIMER_STOP(write_pre_and_post_process_time);
PERF_TIMER_GUARD(write_memtable_time);
PERF_TIMER_FOR_WAIT_GUARD(write_memtable_time);

assert(w.ShouldWriteToMemtable());
ColumnFamilyMemTablesImpl column_family_memtables(
Expand Down Expand Up @@ -868,7 +868,7 @@ Status DBImpl::UnorderedWriteMemtable(const WriteOptions& write_options,
RecordTick(stats_, NUMBER_KEYS_WRITTEN, total_count);

PERF_TIMER_STOP(write_pre_and_post_process_time);
PERF_TIMER_GUARD(write_memtable_time);
PERF_TIMER_FOR_WAIT_GUARD(write_memtable_time);

ColumnFamilyMemTablesImpl column_family_memtables(
versions_->GetColumnFamilySet());
Expand Down
17 changes: 17 additions & 0 deletions db/perf_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,23 @@ TEST_F(PerfContextTest, MergeOperandCount) {
verify();
}

TEST_F(PerfContextTest, WriteMemtableTimePerfLevel) {
// Write and check time
ASSERT_OK(DestroyDB(kDbName, Options()));
std::shared_ptr<DB> db = OpenDb();

SetPerfLevel(PerfLevel::kEnableWait);
PerfContext* perf_ctx = get_perf_context();
perf_ctx->Reset();
ASSERT_OK(db->Put(WriteOptions(), "foo1", "bar"));
ASSERT_GT(perf_context.write_memtable_time, 0);

SetPerfLevel(PerfLevel::kEnableCount);
perf_ctx->Reset();
ASSERT_OK(db->Put(WriteOptions(), "foo0", "bar"));
ASSERT_EQ(perf_context.write_memtable_time, 0);
}

} // namespace ROCKSDB_NAMESPACE

int main(int argc, char** argv) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add `write_memtable_time` to the newly introduced PerfLevel `kEnableWait`.

0 comments on commit 4aed229

Please sign in to comment.