Reply by the question author:
It should be the default level compression. During ingestion I do see multiple threads working, like around 8.
I think it finally finished.
In the FAQ there is this:
Q: Can I close the DB when a manual compaction is in progress?
A: No, it’s not safe to do that. However, you call CancelAllBackgroundWork(db, true) in another thread to abort the running compactions, so that you can close the DB sooner. Since 6.5, you can also speed it up using DB::DisableManualCompaction().
Would this be the exception to the rule of crash safety?
Here are my configs. Do they look OK?
db_options.create_if_missing = true;
db_options.create_missing_column_families = true;
db_options.unordered_write = true;
auto num_threads = 32;
db_options.env->SetBackgroundThreads(num_threads, rocksdb::Env::Priority::HIGH);
db_options.env->SetBackgroundThreads(num_threads, rocksdb::Env::Priority::LOW);
db_options.max_background_jobs = num_threads;
db_options.bytes_per_sync = 1048576; // 1MB
std::vectorrocksdb::ColumnFamilyDescriptor column_families;
rocksdb::ColumnFamilyOptions cf_options;
cf_options.compression = rocksdb::CompressionType::kLZ4Compression;
cf_options.bottommost_compression = rocksdb::CompressionType::kZSTD;
// custom for SSD RocksDB Tuning Guide · facebook/rocksdb Wiki · GitHub
cf_options.write_buffer_size = 64 << 20;
cf_options.max_write_buffer_number = 4;
cf_options.min_write_buffer_number_to_merge = 1;
cf_options.level_compaction_dynamic_level_bytes = true;
// table_options.index_type = rocksdb::BlockBasedTableOptions::kHashSearch; // maybe good for prefix db
// recommended at Setup Options and Basic Tuning · facebook/rocksdb Wiki · GitHub
rocksdb::BlockBasedTableOptions table_options;
table_options.block_cache = rocksdb::NewLRUCache(128 << 20);
table_options.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
table_options.optimize_filters_for_memory = true;
table_options.block_size = 16 * 1024;
table_options.cache_index_and_filter_blocks = true;
table_options.pin_l0_filter_and_index_blocks_in_cache = true;
cf_options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_options));
// prefix
cf_options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform(sizeof(uint32_t)));
cf_options.memtable_prefix_bloom_size_ratio = 0.1;
cf_options.memtable_whole_key_filtering = true;
column_families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, cf_options));
Reply by Mark C.:
When compaction took a long time to run
- was it a manual or normal compaction
- how many threads appeared to be in progress?
- do you have any compaction IO stats in the RocksDB LOG (grep for L0, it is formatted as a table)
Too bad the docs don’t elaborate on what is meant by “not safe”. Compaction state should be crash-safe and I would consider it to be a bug otherwise. But I have little experience with manual compaction – long ago it was single-threaded so I stayed away from it given the poor performance.
Options look OK for the most part.
- I don’t know much about prefix bloom filters, so I won’t answer about that
- I filed a bug to improve the docs for SetBackgroundThreads, Fix the docs for SetBackgroundThreads vs max_background_jobs · Issue #11097 · facebook/rocksdb · GitHub
- I am not sure about your usage of SetBackgroundThreads
You have:
auto num_threads = 32;
db_options.env->SetBackgroundThreads(num_threads, rocksdb::Env::Priority::HIGH);
db_options.env->SetBackgroundThreads(num_threads, rocksdb::Env::Priority::LOW);
db_options.max_background_jobs = num_threads;
I prefer:
auto num_threads = 32;
auto num_flushes = num_threads/4;
auto num_compactions = num_threads - num_flushes;
db_options.env->SetBackgroundThreads(num_compactions, rocksdb::Env::Priority::HIGH);
db_options.env->SetBackgroundThreads(num_flushes, rocksdb::Env::Priority::LOW);
db_options.max_background_jobs = num_threads;