Skip to content

Commit

Permalink
feat(collector): add statistics for estimate key number of partition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
foreverneverer authored and acelyc111 committed Dec 3, 2019
1 parent d46429d commit 7ee9fb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/server/pegasus_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r)
snprintf(name, 255, "rdb.memtable.memory_usage@%s", str_gpid.c_str());
_pfc_rdb_memtable_mem_usage.init_app_counter(
"app.pegasus", name, COUNTER_TYPE_NUMBER, "statistic the memory usage of rocksdb memtable");

snprintf(name, 255, "rdb.estimate_num_keys@%s", str_gpid.c_str());
_pfc_rdb_estimate_num_keys.init_app_counter(
"app.pegasus",
name,
COUNTER_TYPE_NUMBER,
"statistics the estimated number of keys inside the rocksdb");
}

void pegasus_server_impl::parse_checkpoints()
Expand Down Expand Up @@ -2242,6 +2249,14 @@ void pegasus_server_impl::update_replica_rocksdb_statistics()
_pfc_rdb_memtable_mem_usage->set(val);
dinfo_replica("_pfc_rdb_memtable_mem_usage: {} bytes", val);
}

// for the same n kv pairs, kEstimateNumKeys will be counted n times, you need compaction to
// remove duplicate
if (_db->GetProperty(rocksdb::DB::Properties::kEstimateNumKeys, &str_val) &&
dsn::buf2uint64(str_val, val)) {
_pfc_rdb_estimate_num_keys->set(val);
dinfo_replica("_pfc_rdb_estimate_num_keys: {}", val);
}
}

void pegasus_server_impl::update_server_rocksdb_statistics()
Expand Down
1 change: 1 addition & 0 deletions src/server/pegasus_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ class pegasus_server_impl : public ::dsn::apps::rrdb_service
::dsn::perf_counter_wrapper _pfc_rdb_block_cache_total_count;
::dsn::perf_counter_wrapper _pfc_rdb_index_and_filter_blocks_mem_usage;
::dsn::perf_counter_wrapper _pfc_rdb_memtable_mem_usage;
::dsn::perf_counter_wrapper _pfc_rdb_estimate_num_keys;
};

} // namespace server
Expand Down

0 comments on commit 7ee9fb2

Please sign in to comment.