Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Statistics ticker count #2769

Merged
merged 13 commits into from
Aug 9, 2024
3 changes: 3 additions & 0 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ level0-slowdown-writes-trigger : 20
# rocksdb level0_file_num_compaction_trigger
level0-file-num-compaction-trigger : 4

#rocksdb statistics tickers
open-rocksdb-statistics-tickers : no

# The maximum size of the response package to client to prevent memory
# exhaustion caused by commands like 'keys *' and 'Scan' which can generate huge response.
# Supported Units [K|M|G]. The default unit is in [bytes].
Expand Down
12 changes: 12 additions & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ class PikaConf : public pstd::BaseConf {
std::shared_lock l(rwlock_);
return max_total_wal_size_;
}
bool open_rocksdb_statistics_tickers() {
return open_rocksdb_statistics_tickers_;
}
int64_t max_client_response_size() {
std::shared_lock l(rwlock_);
return max_client_response_size_;
Expand Down Expand Up @@ -841,6 +844,14 @@ class PikaConf : public pstd::BaseConf {
pstd::StringSplit2Set(lower_value, ',', admin_cmd_set_);
}

void SetOpenRocksdbStatisticsTickers(const std::string& value) {
std::lock_guard l(rwlock_);
std::string lower_value = value;
pstd::StringToLower(lower_value);
TryPushDiffCommands("open-rocksdb-statistics-tickers", lower_value);
open_rocksdb_statistics_tickers_ = value == "yes";
}

void SetCacheType(const std::string &value);
void SetCacheDisableFlag() { tmp_cache_disable_flag_ = true; }
int zset_cache_start_direction() { return zset_cache_start_direction_; }
Expand Down Expand Up @@ -887,6 +898,7 @@ class PikaConf : public pstd::BaseConf {
int64_t thread_migrate_keys_num_ = 0;
int64_t max_write_buffer_size_ = 0;
int64_t max_total_wal_size_ = 0;
bool open_rocksdb_statistics_tickers_ = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个命令最好是支持可以动态修改不用重启进程,线上用来定位问题的时候更方便。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rocksdb statics统计 不支持动态

int max_write_buffer_num_ = 0;
int min_write_buffer_number_to_merge_ = 1;
int level0_stop_writes_trigger_ = 36;
Expand Down
23 changes: 22 additions & 1 deletion src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,12 @@ void InfoCmd::InfoRocksDB(std::string& info) {
}
std::string rocksdb_info;
db_item.second->DBLockShared();
db_item.second->storage()->GetRocksDBInfo(rocksdb_info);
if (g_pika_conf->open_rocksdb_statistics_tickers()) {
db_item.second->storage()->GetRocksDBInfo(rocksdb_info, true);
} else {
db_item.second->storage()->GetRocksDBInfo(rocksdb_info, false);
}

db_item.second->DBUnlockShared();
tmp_stream << rocksdb_info;
}
Expand Down Expand Up @@ -2147,6 +2152,12 @@ void ConfigCmd::ConfigGet(std::string& ret) {
: EncodeString(&config_body, "resetchannels");
}

if (pstd::stringmatch(pattern.data(), "open-rocksdb-statistics-tickers", 1)) {
elements += 2;
EncodeString(&config_body, "open-rocksdb-statistics-tickers");
EncodeString(&config_body, g_pika_conf->open_rocksdb_statistics_tickers() ? "yes" : "no");
}

std::stringstream resp;
resp << "*" << std::to_string(elements) << "\r\n" << config_body;
ret = resp.str();
Expand Down Expand Up @@ -2209,6 +2220,7 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
"zset-cache-field-num-per-key",
"cache-lfu-decay-time",
"max-conn-rbuf-size",
"open-rocksdb-statistics-tickers",
});
res_.AppendStringVector(replyVt);
return;
Expand Down Expand Up @@ -2850,6 +2862,15 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
}
g_pika_conf->SetMaxConnRbufSize(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");
} else if (set_item == "open-rocksdb-statistics-tickers") {
std::string v(value);
pstd::StringToLower(v);
if (v != "yes" && v != "no") {
res_.AppendStringRaw("-ERR Invalid argument \'" + value + "\' for CONFIG SET 'open-rocksdb-statistics-tickers'\r\n");
return;
}
g_pika_conf->SetOpenRocksdbStatisticsTickers(value);
res_.AppendStringRaw("+OK\r\n");
} else {
res_.AppendStringRaw("-ERR Unsupported CONFIG parameter: " + set_item + "\r\n");
}
Expand Down
6 changes: 6 additions & 0 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,11 @@ int PikaConf::Load() {
max_rsync_parallel_num_ = kMaxRsyncParallelNum;
}

// rocksdb_statistics_tickers
std::string open_tickers;
GetConfStr("open-rocksdb-statistics-tickers", &open_tickers);
open_rocksdb_statistics_tickers_ = open_tickers == "yes";

int64_t tmp_rsync_timeout_ms = -1;
GetConfInt64("rsync-timeout-ms", &tmp_rsync_timeout_ms);
if(tmp_rsync_timeout_ms <= 0){
Expand Down Expand Up @@ -797,6 +802,7 @@ int PikaConf::ConfigRewrite() {
SetConfStr("slotmigrate", slotmigrate_.load() ? "yes" : "no");
SetConfInt64("slotmigrate-thread-num", slotmigrate_thread_num_);
SetConfInt64("thread-migrate-keys-num", thread_migrate_keys_num_);
SetConfStr("open-rocksdb-statistics-tickers", open_rocksdb_statistics_tickers_ ? "yes" : "no");
// slaveof config item is special
SetConfStr("slaveof", slaveof_);
// cache config
Expand Down
2 changes: 1 addition & 1 deletion src/storage/include/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ class Storage {
const std::string& db_type, const std::unordered_map<std::string, std::string>& options);
Status EnableAutoCompaction(const OptionType& option_type,
const std::string& db_type, const std::unordered_map<std::string, std::string>& options);
void GetRocksDBInfo(std::string& info);
void GetRocksDBInfo(std::string& info, bool open_ticker);

private:
std::vector<std::unique_ptr<Redis>> insts_;
Expand Down
Loading
Loading