diff --git a/libinitializer/Initializer.cpp b/libinitializer/Initializer.cpp index bc58f8dabb..c51aeac975 100644 --- a/libinitializer/Initializer.cpp +++ b/libinitializer/Initializer.cpp @@ -134,7 +134,8 @@ 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(); @@ -142,6 +143,7 @@ RocksDBOption getRocksDBOption(const tool::NodeConfig::Ptr& nodeConfig) option.writeBufferSize = nodeConfig->writeBufferSize(); option.minWriteBufferNumberToMerge = nodeConfig->minWriteBufferNumberToMerge(); option.blockCacheSize = nodeConfig->blockCacheSize(); + option.optimizeLevelStyleCompaction = true; option.enable_blob_files = nodeConfig->enableRocksDBBlob(); return option; } @@ -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); @@ -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 @@ -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); diff --git a/libinitializer/StorageInitializer.h b/libinitializer/StorageInitializer.h index f9751e5294..f03fc0a7cf 100644 --- a/libinitializer/StorageInitializer.h +++ b/libinitializer/StorageInitializer.h @@ -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; }; @@ -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; @@ -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) { @@ -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";