Skip to content

Commit

Permalink
[metrics] Add bloom filter related metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Apr 23, 2020
1 parent fb8fc12 commit b0104b9
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rdsn
Submodule rdsn updated 49 files
+2 −0 include/dsn/dist/replication/duplication_common.h
+1 −0 include/dsn/dist/replication/replication.codes.h
+2 −0 include/dsn/dist/replication/replication_ddl_client.h
+99 −9 include/dsn/dist/replication/replication_types.h
+1 −1 scripts/linux/build.sh
+10 −0 src/dist/replication/common/duplication_common.cpp
+8 −0 src/dist/replication/common/replication_common.cpp
+1 −0 src/dist/replication/common/replication_common.h
+1,054 −924 src/dist/replication/common/replication_types.cpp
+14 −0 src/dist/replication/ddl_lib/replication_ddl_client.cpp
+10 −1 src/dist/replication/lib/CMakeLists.txt
+186 −0 src/dist/replication/lib/backup/replica_backup_manager.cpp
+35 −0 src/dist/replication/lib/backup/replica_backup_manager.h
+22 −0 src/dist/replication/lib/backup/test/CMakeLists.txt
+34 −0 src/dist/replication/lib/backup/test/config-test.ini
+39 −0 src/dist/replication/lib/backup/test/main.cpp
+34 −0 src/dist/replication/lib/backup/test/replica_backup_manager_test.cpp
+11 −0 src/dist/replication/lib/backup/test/run.sh
+1 −0 src/dist/replication/lib/duplication/duplication_sync_timer.cpp
+1 −0 src/dist/replication/lib/duplication/duplication_sync_timer.h
+47 −0 src/dist/replication/lib/duplication/load_from_private_log.cpp
+11 −0 src/dist/replication/lib/duplication/load_from_private_log.h
+10 −0 src/dist/replication/lib/duplication/replica_duplicator.h
+4 −0 src/dist/replication/lib/duplication/replica_duplicator_manager.cpp
+1 −0 src/dist/replication/lib/duplication/replica_duplicator_manager.h
+126 −34 src/dist/replication/lib/duplication/test/load_from_private_log_test.cpp
+1 −1 src/dist/replication/lib/duplication/test/replica_http_service_test.cpp
+20 −0 src/dist/replication/lib/log_block.cpp
+53 −0 src/dist/replication/lib/log_block.h
+117 −155 src/dist/replication/lib/mutation_log.cpp
+17 −11 src/dist/replication/lib/mutation_log.h
+5 −6 src/dist/replication/lib/replica.cpp
+11 −4 src/dist/replication/lib/replica.h
+11 −132 src/dist/replication/lib/replica_backup.cpp
+1 −1 src/dist/replication/lib/replica_context.h
+1 −0 src/dist/replication/lib/replica_http_service.cpp
+2 −8 src/dist/replication/lib/replica_init.cpp
+58 −12 src/dist/replication/lib/replica_stub.cpp
+8 −0 src/dist/replication/lib/replica_stub.h
+34 −2 src/dist/replication/meta_server/duplication/duplication_info.cpp
+13 −4 src/dist/replication/meta_server/duplication/duplication_info.h
+4 −2 src/dist/replication/meta_server/duplication/meta_duplication_service.cpp
+15 −0 src/dist/replication/meta_server/meta_backup_service.cpp
+25 −4 src/dist/replication/replication.thrift
+26 −3 src/dist/replication/test/meta_test/unit_test/backup_test.cpp
+64 −0 src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp
+5 −5 src/dist/replication/test/meta_test/unit_test/meta_http_service_test.cpp
+157 −0 src/dist/replication/test/replica_test/unit_test/log_block_test.cpp
+73 −0 src/dist/replication/test/replica_test/unit_test/log_file_test.cpp
3 changes: 3 additions & 0 deletions src/server/info_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ info_collector::app_stat_counters *info_collector::get_app_counters(const std::s
INIT_COUNTER(rdb_index_and_filter_blocks_mem_usage);
INIT_COUNTER(rdb_memtable_mem_usage);
INIT_COUNTER(rdb_estimate_num_keys);
INIT_COUNTER(rdb_bf_seek_negatives_rate);
INIT_COUNTER(rdb_bf_point_negatives_rate);
INIT_COUNTER(rdb_bf_point_false_positive_rate);
INIT_COUNTER(read_qps);
INIT_COUNTER(write_qps);
INIT_COUNTER(backup_request_qps);
Expand Down
17 changes: 12 additions & 5 deletions src/server/info_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class info_collector
public:
struct app_stat_counters
{
double convert_to_1M_ratio(double hit, double total) {
return std::abs(total) < 1e-6 ? 0 : hit / total * 1e6;
}

void set(const table_stats &row_stats)
{
get_qps->set(row_stats.total_get_qps);
Expand All @@ -54,15 +58,15 @@ class info_collector
row_stats.total_recent_write_throttling_reject_count);
storage_mb->set(row_stats.total_storage_mb);
storage_count->set(row_stats.total_storage_count);
rdb_block_cache_hit_rate->set(
std::abs(row_stats.total_rdb_block_cache_total_count) < 1e-6
? 0
: row_stats.total_rdb_block_cache_hit_count /
row_stats.total_rdb_block_cache_total_count * 1000000);
rdb_block_cache_hit_rate->set(convert_to_1M_ratio(row_stats.total_rdb_block_cache_hit_count, row_stats.total_rdb_block_cache_total_count));
rdb_index_and_filter_blocks_mem_usage->set(
row_stats.total_rdb_index_and_filter_blocks_mem_usage);
rdb_memtable_mem_usage->set(row_stats.total_rdb_memtable_mem_usage);
rdb_estimate_num_keys->set(row_stats.total_rdb_estimate_num_keys);
rdb_bf_seek_negatives_rate->set(convert_to_1M_ratio(row_stats.total_rdb_bf_seek_negatives, row_stats.total_rdb_bf_seek_total));
rdb_bf_point_negatives_rate->set(convert_to_1M_ratio(row_stats.total_rdb_bf_point_negatives, row_stats.total_rdb_bf_point_negatives + row_stats.total_rdb_bf_point_positive_total));
rdb_bf_point_false_positive_rate->set(convert_to_1M_ratio(
row_stats.total_rdb_bf_point_positive_total - row_stats.total_rdb_bf_point_positive_true, (row_stats.total_rdb_bf_point_positive_total - row_stats.total_rdb_bf_point_positive_true) + row_stats.total_rdb_bf_point_negatives));
read_qps->set(row_stats.get_total_read_qps());
write_qps->set(row_stats.get_total_write_qps());
backup_request_qps->set(row_stats.total_backup_request_qps);
Expand Down Expand Up @@ -101,6 +105,9 @@ class info_collector
::dsn::perf_counter_wrapper rdb_index_and_filter_blocks_mem_usage;
::dsn::perf_counter_wrapper rdb_memtable_mem_usage;
::dsn::perf_counter_wrapper rdb_estimate_num_keys;
::dsn::perf_counter_wrapper rdb_bf_seek_negatives_rate;
::dsn::perf_counter_wrapper rdb_bf_point_negatives_rate;
::dsn::perf_counter_wrapper rdb_bf_point_false_positive_rate;
::dsn::perf_counter_wrapper read_qps;
::dsn::perf_counter_wrapper write_qps;
::dsn::perf_counter_wrapper backup_request_qps;
Expand Down
70 changes: 69 additions & 1 deletion src/server/pegasus_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,41 @@ pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r)
name,
COUNTER_TYPE_NUMBER,
"statistics the estimated number of keys inside the rocksdb");

snprintf(name, 255, "rdb.bf_seek_negatives@%s", str_gpid.c_str());
_pfc_rdb_bf_seek_negatives.init_app_counter(
"app.pegasus",
name,
COUNTER_TYPE_NUMBER,
"statistics the number of times bloom filter was checked before creating iterator on a file and useful in avoiding iterator creation (and thus likely IOPs)");

snprintf(name, 255, "rdb.bf_seek_total@%s", str_gpid.c_str());
_pfc_rdb_bf_seek_total.init_app_counter(
"app.pegasus",
name,
COUNTER_TYPE_NUMBER,
"statistics the number of times bloom filter was checked before creating iterator on a file");

snprintf(name, 255, "rdb.bf_point_positive_true@%s", str_gpid.c_str());
_pfc_rdb_bf_point_positive_true.init_app_counter(
"app.pegasus",
name,
COUNTER_TYPE_NUMBER,
"statistics the number of times bloom filter has avoided file reads, i.e., negatives");

snprintf(name, 255, "rdb.bf_point_positive_total@%s", str_gpid.c_str());
_pfc_rdb_bf_point_positive_total.init_app_counter(
"app.pegasus",
name,
COUNTER_TYPE_NUMBER,
"statistics the number of times bloom FullFilter has not avoided the reads");

snprintf(name, 255, "rdb.bf_point_negatives@%s", str_gpid.c_str());
_pfc_rdb_bf_point_negatives.init_app_counter(
"app.pegasus",
name,
COUNTER_TYPE_NUMBER,
"statistics the number of times bloom FullFilter has not avoided the reads and data actually exist");
}

void pegasus_server_impl::parse_checkpoints()
Expand Down Expand Up @@ -2408,6 +2443,8 @@ void pegasus_server_impl::update_replica_rocksdb_statistics()
{
std::string str_val;
uint64_t val = 0;

// Update _pfc_rdb_sst_count
for (int i = 0; i < _data_cf_opts.num_levels; ++i) {
int cur_level_count = 0;
if (_db->GetProperty(rocksdb::DB::Properties::kNumFilesAtLevelPrefix + std::to_string(i),
Expand All @@ -2419,13 +2456,15 @@ void pegasus_server_impl::update_replica_rocksdb_statistics()
_pfc_rdb_sst_count->set(val);
dinfo_replica("_pfc_rdb_sst_count: {}", val);

// Update _pfc_rdb_sst_size
if (_db->GetProperty(_data_cf, rocksdb::DB::Properties::kTotalSstFilesSize, &str_val) &&
dsn::buf2uint64(str_val, val)) {
static uint64_t bytes_per_mb = 1U << 20U;
_pfc_rdb_sst_size->set(val / bytes_per_mb);
dinfo_replica("_pfc_rdb_sst_size: {} bytes", val);
}

// Update _pfc_rdb_block_cache_hit_count and _pfc_rdb_block_cache_total_count
uint64_t block_cache_hit = _statistics->getTickerCount(rocksdb::BLOCK_CACHE_HIT);
_pfc_rdb_block_cache_hit_count->set(block_cache_hit);
dinfo_replica("_pfc_rdb_block_cache_hit_count: {}", block_cache_hit);
Expand All @@ -2435,29 +2474,58 @@ void pegasus_server_impl::update_replica_rocksdb_statistics()
_pfc_rdb_block_cache_total_count->set(block_cache_total);
dinfo_replica("_pfc_rdb_block_cache_total_count: {}", block_cache_total);

// Update _pfc_rdb_index_and_filter_blocks_mem_usage
if (_db->GetProperty(_data_cf, rocksdb::DB::Properties::kEstimateTableReadersMem, &str_val) &&
dsn::buf2uint64(str_val, val)) {
_pfc_rdb_index_and_filter_blocks_mem_usage->set(val);
dinfo_replica("_pfc_rdb_index_and_filter_blocks_mem_usage: {} bytes", val);
}

// Update _pfc_rdb_memtable_mem_usage
if (_db->GetProperty(_data_cf, rocksdb::DB::Properties::kCurSizeAllMemTables, &str_val) &&
dsn::buf2uint64(str_val, val)) {
_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
// Update _pfc_rdb_estimate_num_keys
// NOTE: for the same n kv pairs, kEstimateNumKeys will be counted n times, you need compaction to
// remove duplicate
if (_db->GetProperty(_data_cf, 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);
}

// Update _pfc_rdb_bf_seek_negatives
uint64_t bf_seek_negatives = _statistics->getTickerCount(rocksdb::BLOOM_FILTER_PREFIX_USEFUL);
_pfc_rdb_bf_seek_negatives->set(bf_seek_negatives);
dinfo_replica("_pfc_rdb_bf_seek_negatives: {}", bf_seek_negatives);

// Update _pfc_rdb_bf_seek_total
uint64_t bf_seek_total = _statistics->getTickerCount(rocksdb::BLOOM_FILTER_PREFIX_CHECKED);
_pfc_rdb_bf_seek_total->set(bf_seek_total);
dinfo_replica("_pfc_rdb_bf_seek_total: {}", bf_seek_total);

// Update _pfc_rdb_bf_point_positive_true
uint64_t bf_point_positive_true = _statistics->getTickerCount(rocksdb::BLOOM_FILTER_FULL_TRUE_POSITIVE);
_pfc_rdb_bf_point_positive_true->set(bf_point_positive_true);
dinfo_replica("_pfc_rdb_bf_point_positive_true: {}", bf_point_positive_true);

// Update _pfc_rdb_bf_point_positive_total
uint64_t bf_point_positive_total = _statistics->getTickerCount(rocksdb::BLOOM_FILTER_FULL_POSITIVE);
_pfc_rdb_bf_point_positive_total->set(bf_point_positive_total);
dinfo_replica("_pfc_rdb_bf_point_positive_total: {}", bf_point_positive_total);

// Update _pfc_rdb_bf_point_negatives
uint64_t bf_point_negatives = _statistics->getTickerCount(rocksdb::BLOOM_FILTER_USEFUL);
_pfc_rdb_bf_point_negatives->set(bf_point_negatives);
dinfo_replica("_pfc_rdb_bf_point_negatives: {}", bf_point_negatives);
}

void pegasus_server_impl::update_server_rocksdb_statistics()
{
// Update _pfc_rdb_block_cache_mem_usage
if (_s_block_cache) {
uint64_t val = _s_block_cache->GetUsage();
_pfc_rdb_block_cache_mem_usage->set(val);
Expand Down
5 changes: 5 additions & 0 deletions src/server/pegasus_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ class pegasus_server_impl : public ::dsn::apps::rrdb_service
::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;
::dsn::perf_counter_wrapper _pfc_rdb_bf_seek_negatives;
::dsn::perf_counter_wrapper _pfc_rdb_bf_seek_total;
::dsn::perf_counter_wrapper _pfc_rdb_bf_point_positive_true;
::dsn::perf_counter_wrapper _pfc_rdb_bf_point_positive_total;
::dsn::perf_counter_wrapper _pfc_rdb_bf_point_negatives;
};

} // namespace server
Expand Down
15 changes: 15 additions & 0 deletions src/server/table_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ struct table_stats
total_rdb_index_and_filter_blocks_mem_usage += row.rdb_index_and_filter_blocks_mem_usage;
total_rdb_memtable_mem_usage += row.rdb_memtable_mem_usage;
total_rdb_estimate_num_keys += row.rdb_estimate_num_keys;
total_rdb_bf_seek_negatives += row.rdb_bf_seek_negatives;
total_rdb_bf_seek_total += row.rdb_bf_seek_total;
total_rdb_bf_point_positive_true += row.rdb_bf_point_positive_true;
total_rdb_bf_point_positive_total += row.rdb_bf_point_positive_total;
total_rdb_bf_point_negatives += row.rdb_bf_point_negatives;
total_backup_request_qps += row.backup_request_qps;
total_get_bytes += row.get_bytes;
total_multi_get_bytes += row.multi_get_bytes;
Expand Down Expand Up @@ -95,6 +100,11 @@ struct table_stats
row_stats.total_rdb_index_and_filter_blocks_mem_usage;
total_rdb_memtable_mem_usage += row_stats.total_rdb_memtable_mem_usage;
total_rdb_estimate_num_keys += row_stats.total_rdb_estimate_num_keys;
total_rdb_bf_seek_negatives += row_stats.total_rdb_bf_seek_negatives;
total_rdb_bf_seek_total += row_stats.total_rdb_bf_seek_total;
total_rdb_bf_point_positive_true += row_stats.total_rdb_bf_point_positive_true;
total_rdb_bf_point_positive_total += row_stats.total_rdb_bf_point_positive_total;
total_rdb_bf_point_negatives += row_stats.total_rdb_bf_point_negatives;
total_backup_request_qps += row_stats.total_backup_request_qps;
total_get_bytes += row_stats.total_get_bytes;
total_multi_get_bytes += row_stats.total_multi_get_bytes;
Expand Down Expand Up @@ -130,6 +140,11 @@ struct table_stats
double total_rdb_index_and_filter_blocks_mem_usage = 0;
double total_rdb_memtable_mem_usage = 0;
double total_rdb_estimate_num_keys = 0;
double total_rdb_bf_seek_negatives = 0;
double total_rdb_bf_seek_total = 0;
double total_rdb_bf_point_positive_true = 0;
double total_rdb_bf_point_positive_total = 0;
double total_rdb_bf_point_negatives = 0;
double total_backup_request_qps = 0;
double total_get_bytes = 0;
double total_multi_get_bytes = 0;
Expand Down
15 changes: 15 additions & 0 deletions src/shell/command_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ struct row_data
double rdb_index_and_filter_blocks_mem_usage = 0;
double rdb_memtable_mem_usage = 0;
double rdb_estimate_num_keys = 0;
double rdb_bf_seek_negatives = 0;
double rdb_bf_seek_total = 0;
double rdb_bf_point_positive_true = 0;
double rdb_bf_point_positive_total = 0;
double rdb_bf_point_negatives = 0;
double backup_request_qps = 0;
double get_bytes = 0;
double multi_get_bytes = 0;
Expand Down Expand Up @@ -635,6 +640,16 @@ update_app_pegasus_perf_counter(row_data &row, const std::string &counter_name,
row.rdb_memtable_mem_usage += value;
else if (counter_name == "rdb.estimate_num_keys")
row.rdb_estimate_num_keys += value;
else if (counter_name == "rdb.bf_seek_negatives")
row.rdb_bf_seek_negatives += value;
else if (counter_name == "rdb.bf_seek_total")
row.rdb_bf_seek_total += value;
else if (counter_name == "rdb.bf_point_positive_true")
row.rdb_bf_point_positive_true += value;
else if (counter_name == "rdb.bf_point_positive_total")
row.rdb_bf_point_positive_total += value;
else if (counter_name == "rdb.bf_point_negatives")
row.rdb_bf_point_negatives += value;
else if (counter_name == "backup_request_qps")
row.backup_request_qps += value;
else if (counter_name == "get_bytes")
Expand Down
21 changes: 16 additions & 5 deletions src/shell/commands/table_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include "shell/commands.h"

double convert_to_ratio(double hit, double total) {
return std::abs(total) < 1e-6 ? 0 : hit / total;
}

bool ls_apps(command_executor *e, shell_context *sc, arguments args)
{
static struct option long_options[] = {{"all", no_argument, 0, 'a'},
Expand Down Expand Up @@ -493,6 +497,11 @@ bool app_stat(command_executor *e, shell_context *sc, arguments args)
sum.rdb_block_cache_total_count += row.rdb_block_cache_total_count;
sum.rdb_index_and_filter_blocks_mem_usage += row.rdb_index_and_filter_blocks_mem_usage;
sum.rdb_memtable_mem_usage += row.rdb_memtable_mem_usage;
sum.rdb_bf_seek_negatives += row.rdb_bf_seek_negatives;
sum.rdb_bf_seek_total += row.rdb_bf_seek_total;
sum.rdb_bf_point_positive_true += row.rdb_bf_point_positive_true;
sum.rdb_bf_point_positive_total += row.rdb_bf_point_positive_total;
sum.rdb_bf_point_negatives += row.rdb_bf_point_negatives;
}

std::streambuf *buf;
Expand Down Expand Up @@ -538,6 +547,9 @@ bool app_stat(command_executor *e, shell_context *sc, arguments args)
tp.add_column("mem_idx_mb", tp_alignment::kRight);
}
tp.add_column("hit_rate", tp_alignment::kRight);
tp.add_column("seek_n_rate", tp_alignment::kRight);
tp.add_column("point_n_rate", tp_alignment::kRight);
tp.add_column("point_fp_rate", tp_alignment::kRight);

for (row_data &row : rows) {
tp.add_row(row.row_name);
Expand Down Expand Up @@ -570,11 +582,10 @@ bool app_stat(command_executor *e, shell_context *sc, arguments args)
tp.append_data(row.rdb_memtable_mem_usage / (1 << 20U));
tp.append_data(row.rdb_index_and_filter_blocks_mem_usage / (1 << 20U));
}
double block_cache_hit_rate =
std::abs(row.rdb_block_cache_total_count) < 1e-6
? 0.0
: row.rdb_block_cache_hit_count / row.rdb_block_cache_total_count;
tp.append_data(block_cache_hit_rate);
tp.append_data(convert_to_ratio(row.rdb_block_cache_hit_count, row.rdb_block_cache_total_count));
tp.append_data(convert_to_ratio(row.rdb_bf_seek_negatives, row.rdb_bf_seek_total));
tp.append_data(convert_to_ratio(row.rdb_bf_point_negatives, row.rdb_bf_point_negatives + row.rdb_bf_point_positive_total));
tp.append_data(convert_to_ratio(row.rdb_bf_point_positive_total - row.rdb_bf_point_positive_true, (row.rdb_bf_point_positive_total - row.rdb_bf_point_positive_true) + row.rdb_bf_point_negatives));
}
tp.output(out, json ? tp_output_format::kJsonPretty : tp_output_format::kTabular);

Expand Down

0 comments on commit b0104b9

Please sign in to comment.