Skip to content

Commit

Permalink
modify snapshot size to 128M and IncreaseParallelism when import snap…
Browse files Browse the repository at this point in the history
…shot
  • Loading branch information
bxq2011hust committed Aug 26, 2024
1 parent ba6a83f commit 207536e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions libinitializer/Initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,16 @@ void Initializer::initConfig(std::string const& _configFilePath, std::string con
}
}

RocksDBOption getRocksDBOption(const tool::NodeConfig::Ptr& nodeConfig)
RocksDBOption getRocksDBOption(
const tool::NodeConfig::Ptr& nodeConfig, bool optimizeLevelStyleCompaction = false)
{
RocksDBOption option;
option.maxWriteBufferNumber = nodeConfig->maxWriteBufferNumber();
option.maxBackgroundJobs = nodeConfig->maxBackgroundJobs();
option.writeBufferSize = nodeConfig->writeBufferSize();
option.minWriteBufferNumberToMerge = nodeConfig->minWriteBufferNumberToMerge();
option.blockCacheSize = nodeConfig->blockCacheSize();
option.optimizeLevelStyleCompaction = true;
option.enable_blob_files = nodeConfig->enableRocksDBBlob();
return option;
}
Expand Down Expand Up @@ -823,7 +825,7 @@ bcos::Error::Ptr Initializer::generateSnapshot(const std::string& snapshotPath,
bcos::ledger::SYS_BLOCK_NUMBER_2_NONCES, std::to_string(blockLimit + 1));
auto validNonceEndKey = bcos::storage::toDBKey(
bcos::ledger::SYS_BLOCK_NUMBER_2_NONCES, std::to_string(currentBlockNumber));
const size_t MAX_SST_FILE_BYTE = 256 * 1024 * 1024;
const size_t MAX_SST_FILE_BYTE = 128 << 20; // 128MB
rocksdb::Options options;
options.compression = rocksdb::kZSTD;
auto stateSstFileWriter = rocksdb::SstFileWriter(rocksdb::EnvOptions(), options);
Expand Down Expand Up @@ -1076,7 +1078,6 @@ bcos::Error::Ptr ingestIntoRocksDB(
}
}
std::cout << "check sst files success, ingest sst files" << std::endl;

rocksdb::IngestExternalFileOptions info;
info.move_files = moveFiles;
// Ingest SST files into the DB
Expand Down Expand Up @@ -1163,7 +1164,7 @@ bcos::Error::Ptr Initializer::importSnapshotToRocksDB(
{
moveSSTFiles = false;
}
auto rocksdbOption = getRocksDBOption(nodeConfig);
auto rocksdbOption = getRocksDBOption(nodeConfig, true);
auto rocksDB = StorageInitializer::createRocksDB(
stateDBPath, rocksdbOption, nodeConfig->enableStatistics(), nodeConfig->keyPageSize());
ingestIntoRocksDB(*rocksDB, sstFiles, moveSSTFiles);
Expand Down
15 changes: 10 additions & 5 deletions libinitializer/StorageInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct RocksDBOption
size_t writeBufferSize = 64 << 20; // 64MB
int minWriteBufferNumberToMerge = 1;
size_t blockCacheSize = 128 << 20; // 128MB
bool optimizeLevelStyleCompaction = false;
bool enable_blob_files = false;
};

Expand All @@ -55,10 +56,13 @@ class StorageInitializer
boost::filesystem::create_directories(_path);
rocksdb::DB* db = nullptr;
rocksdb::Options options;
// Note: This option will increase much memory
// options.IncreaseParallelism(std::thread::hardware_concurrency());
// Note: This option will increase much memory
// options.OptimizeLevelStyleCompaction();
if (rocksDBOption.optimizeLevelStyleCompaction)
{
// Note: This option will increase much memory
options.IncreaseParallelism();
// Note: This option will increase much memory
options.OptimizeLevelStyleCompaction();
}

// create the DB if it's not already present
options.create_if_missing = true;
Expand All @@ -80,6 +84,8 @@ class StorageInitializer
rocksDBOption.minWriteBufferNumberToMerge; // default is 1
options.enable_pipelined_write = true;
// options.min_blob_size = 1024;
options.max_bytes_for_level_base = 512 << 20; // 512MB
options.target_file_size_base = 128 << 20; // 128MB

if (_enableDBStatistics)
{
Expand All @@ -96,7 +102,6 @@ class StorageInitializer
// table_options.cache_index_and_filter_blocks = true; // this will increase memory and
// lower performance
options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_options));

if (boost::filesystem::space(_path).available < 1 << 30)
{
BCOS_LOG(INFO) << "available disk space is less than 1GB";
Expand Down

0 comments on commit 207536e

Please sign in to comment.