Skip to content

Commit

Permalink
Add flag to disable collecting rocksdb statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
dungeon-master-666 committed Mar 20, 2024
1 parent 8af5768 commit eb39fa2
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions validator-engine/validator-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ td::Status ValidatorEngine::load_global_config() {
validator_options_.write().set_celldb_compress_depth(celldb_compress_depth_);
validator_options_.write().set_max_open_archive_files(max_open_archive_files_);
validator_options_.write().set_archive_preload_period(archive_preload_period_);
validator_options_.write().set_disable_rocksdb_stats(disable_rocksdb_stats_);

std::vector<ton::BlockIdExt> h;
for (auto &x : conf.validator_->hardforks_) {
Expand Down Expand Up @@ -3816,6 +3817,9 @@ int main(int argc, char *argv[]) {
p.add_option('\0', "enable-precompiled-smc",
"enable exectuion of precompiled contracts (experimental, disabled by default)",
[]() { block::precompiled::set_precompiled_execution_enabled(true); });
p.add_option('\0', "disable-rocksdb-stats", "disable gathering rocksdb statistics (enabled by default)", [&]() {
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_disable_rocksdb_stats, true); });
});
auto S = p.run(argc, argv);
if (S.is_error()) {
LOG(ERROR) << "failed to parse options: " << S.move_as_error();
Expand Down
4 changes: 4 additions & 0 deletions validator-engine/validator-engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class ValidatorEngine : public td::actor::Actor {
td::uint32 celldb_compress_depth_ = 0;
size_t max_open_archive_files_ = 0;
double archive_preload_period_ = 0.0;
bool disable_rocksdb_stats_ = false;
bool read_config_ = false;
bool started_keyring_ = false;
bool started_ = false;
Expand Down Expand Up @@ -272,6 +273,9 @@ class ValidatorEngine : public td::actor::Actor {
void set_archive_preload_period(double value) {
archive_preload_period_ = value;
}
void set_disable_rocksdb_stats(bool value) {
disable_rocksdb_stats_ = value;
}
void start_up() override;
ValidatorEngine() {
}
Expand Down
8 changes: 6 additions & 2 deletions validator/db/archive-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,9 @@ void ArchiveManager::start_up() {
if (opts_->get_max_open_archive_files() > 0) {
archive_lru_ = td::actor::create_actor<ArchiveLru>("archive_lru", opts_->get_max_open_archive_files());
}
statistics_ = td::RocksDb::create_statistics();
if (!opts_->get_disable_rocksdb_stats()) {
statistics_ = td::RocksDb::create_statistics();
}
index_ = std::make_shared<td::RocksDb>(td::RocksDb::open(db_root_ + "/files/globalindex", statistics_).move_as_ok());
std::string value;
auto v = index_->get(create_serialize_tl_object<ton_api::db_files_index_key>().as_slice(), value);
Expand Down Expand Up @@ -905,7 +907,9 @@ void ArchiveManager::start_up() {
}
}

alarm_timestamp() = td::Timestamp::in(60.0);
if (!opts_->get_disable_rocksdb_stats()) {
alarm_timestamp() = td::Timestamp::in(60.0);
}
}

void ArchiveManager::alarm() {
Expand Down
9 changes: 6 additions & 3 deletions validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ void CellDbIn::start_up() {
};

CellDbBase::start_up();
statistics_ = td::RocksDb::create_statistics();
if (!opts_->get_disable_rocksdb_stats()) {
statistics_ = td::RocksDb::create_statistics();
statistics_flush_at_ = td::Timestamp::in(60.0);
}
cell_db_ = std::make_shared<td::RocksDb>(td::RocksDb::open(path_, statistics_).move_as_ok());
statistics_flush_at_ = td::Timestamp::in(60.0);


boc_ = vm::DynamicBagOfCellsDb::create();
boc_->set_celldb_compress_depth(opts_->get_celldb_compress_depth());
Expand Down Expand Up @@ -159,7 +162,7 @@ void CellDbIn::get_cell_db_reader(td::Promise<std::shared_ptr<vm::CellDbReader>>
}

void CellDbIn::alarm() {
if (statistics_flush_at_.is_in_past()) {
if (statistics_flush_at_ && statistics_flush_at_.is_in_past()) {
statistics_flush_at_ = td::Timestamp::in(60.0);
auto stats = td::RocksDb::statistics_to_string(statistics_);
td::atomic_write_file(path_ + "/db_stats.txt", stats);
Expand Down
2 changes: 1 addition & 1 deletion validator/db/celldb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CellDbIn : public CellDbBase {
std::unique_ptr<vm::DynamicBagOfCellsDb> boc_;
std::shared_ptr<vm::KeyValue> cell_db_;
std::shared_ptr<rocksdb::Statistics> statistics_;
td::Timestamp statistics_flush_at_;
td::Timestamp statistics_flush_at_ = td::Timestamp::never();

std::function<void(const vm::CellLoader::LoadResult&)> on_load_callback_;
std::set<td::Bits256> cells_to_migrate_;
Expand Down
7 changes: 7 additions & 0 deletions validator/validator-options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
double get_archive_preload_period() const override {
return archive_preload_period_;
}
bool get_disable_rocksdb_stats() const override {
return disable_rocksdb_stats_;
}

void set_zero_block_id(BlockIdExt block_id) override {
zero_block_id_ = block_id;
Expand Down Expand Up @@ -185,6 +188,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
void set_archive_preload_period(double value) override {
archive_preload_period_ = value;
}
void set_disable_rocksdb_stats(bool value) override {
disable_rocksdb_stats_ = value;
}

ValidatorManagerOptionsImpl *make_copy() const override {
return new ValidatorManagerOptionsImpl(*this);
Expand Down Expand Up @@ -230,6 +236,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
td::uint32 celldb_compress_depth_{0};
size_t max_open_archive_files_ = 0;
double archive_preload_period_ = 0.0;
bool disable_rocksdb_stats_;
};

} // namespace validator
Expand Down
2 changes: 2 additions & 0 deletions validator/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct ValidatorManagerOptions : public td::CntObject {
virtual td::uint32 get_celldb_compress_depth() const = 0;
virtual size_t get_max_open_archive_files() const = 0;
virtual double get_archive_preload_period() const = 0;
virtual bool get_disable_rocksdb_stats() const = 0;

virtual void set_zero_block_id(BlockIdExt block_id) = 0;
virtual void set_init_block_id(BlockIdExt block_id) = 0;
Expand All @@ -106,6 +107,7 @@ struct ValidatorManagerOptions : public td::CntObject {
virtual void set_celldb_compress_depth(td::uint32 value) = 0;
virtual void set_max_open_archive_files(size_t value) = 0;
virtual void set_archive_preload_period(double value) = 0;
virtual void set_disable_rocksdb_stats(bool value) = 0;

static td::Ref<ValidatorManagerOptions> create(
BlockIdExt zero_block_id, BlockIdExt init_block_id,
Expand Down

0 comments on commit eb39fa2

Please sign in to comment.