|
1 | 1 | use async_trait::async_trait;
|
2 |
| -use rocksdb::{ColumnFamilyDescriptor, OptimisticTransactionDB, Options, Transaction}; |
| 2 | +use rocksdb::{ |
| 3 | + ColumnFamilyDescriptor, DBCompressionType, OptimisticTransactionDB, Options, Transaction, |
| 4 | +}; |
3 | 5 | use serde::{de::DeserializeOwned, Serialize};
|
4 | 6 | use std::{
|
5 | 7 | fmt::Debug,
|
@@ -44,17 +46,25 @@ impl RocksDbBackend {
|
44 | 46 | opts.increase_parallelism(num_cpus::get() as i32);
|
45 | 47 | opts.set_max_background_jobs(4);
|
46 | 48 | opts.set_max_write_buffer_number(3);
|
47 |
| - opts.set_write_buffer_size(8 * 1024 * 1024 * 1024); |
| 49 | + opts.set_write_buffer_size(64 * 1024 * 1024); // 64MB |
48 | 50 | opts.set_target_file_size_base(64 * 1024 * 1024); // 64MB
|
| 51 | + opts.set_level_compaction_dynamic_level_bytes(true); |
| 52 | + opts.set_max_bytes_for_level_base(256 * 1024 * 1024); // 256MB |
| 53 | + opts.set_bloom_locality(1); |
| 54 | + opts.set_compression_type(DBCompressionType::Lz4); |
| 55 | + opts.set_periodic_compaction_seconds(86400); // 24 hours |
| 56 | + |
| 57 | + let mut cf_opts = Options::default(); |
| 58 | + cf_opts.set_compression_type(DBCompressionType::Lz4); |
| 59 | + cf_opts.set_bottommost_compression_type(DBCompressionType::Zstd); |
49 | 60 |
|
50 | 61 | let cf_descriptors = vec![
|
51 |
| - ColumnFamilyDescriptor::new(INSTANCE_INDEX_CF, Options::default()), |
52 |
| - ColumnFamilyDescriptor::new(TAPESTRY_METADATA_CF, Options::default()), |
53 |
| - ColumnFamilyDescriptor::new(TAPESTRY_FRAGMENT_CF, Options::default()), |
| 62 | + ColumnFamilyDescriptor::new(INSTANCE_INDEX_CF, cf_opts.clone()), |
| 63 | + ColumnFamilyDescriptor::new(TAPESTRY_METADATA_CF, cf_opts.clone()), |
| 64 | + ColumnFamilyDescriptor::new(TAPESTRY_FRAGMENT_CF, cf_opts), |
54 | 65 | ];
|
55 | 66 |
|
56 | 67 | let db_path = std::env::var("ROCKSDB_PATH").unwrap_or_else(|_| "rocksdb-data".to_string());
|
57 |
| - |
58 | 68 | OptimisticTransactionDB::open_cf_descriptors(&opts, db_path, cf_descriptors)
|
59 | 69 | .map(Arc::new)
|
60 | 70 | .map_err(|e| StorageError::DatabaseError(e.to_string()).into())
|
|
0 commit comments