@@ -94,32 +94,45 @@ public MerkleTree(String treeName) throws RocksDBException {
9494 throw new RocksDBException ("Failed to create directory: " + path );
9595 }
9696
97- // Replace your current RocksDB configuration with these balanced settings
97+ // Extreme memory conservation settings
9898 DBOptions dbOptions = new DBOptions ()
9999 .setCreateIfMissing (true )
100100 .setCreateMissingColumnFamilies (true )
101- .setParanoidChecks (false ) // Reduced safety checks for performance
102- .setMaxOpenFiles (100 ) // Balanced setting for 30+ trees
103- .setMaxTotalWalSize (10 * 1024 * 1024L ) // Reduced from 45MB to 10MB
104- .setWalSizeLimitMB (5 ) // Reduced from 15MB to 5MB
105- .setInfoLogLevel (InfoLogLevel .ERROR_LEVEL ); // Minimal logging
106-
107- // Configure table options with bloom filters for faster lookups
101+ .setParanoidChecks (false )
102+ .setMaxOpenFiles (10 ) // Minimum reasonable value
103+ .setMaxTotalWalSize (1 * 1024 * 1024L ) // 1MB total WAL size
104+ .setWalSizeLimitMB (1 ) // 1MB per WAL file
105+ .setInfoLogLevel (InfoLogLevel .ERROR_LEVEL )
106+ .setMaxBackgroundJobs (1 ) // Minimize background threads
107+ .setAvoidFlushDuringShutdown (false )
108+ .setStatsDumpPeriodSec (0 ) // Disable stats dumping
109+ .setDelayedWriteRate (2 * 1024 * 1024 ); // Slow down writes when needed
110+
111+ // No block cache configuration - completely disable caching
108112 BlockBasedTableConfig tableConfig = new BlockBasedTableConfig ()
109- .setBlockCache (new LRUCache (8 * 1024 * 1024L )) // Shared 8MB block cache
110- .setFilterPolicy (new BloomFilter (10 , false )) // Memory-efficient lookups
111- .setBlockSize (4 * 1024 ) // 4KB blocks (smaller than default)
112- .setCacheIndexAndFilterBlocks (true )
113- .setPinL0FilterAndIndexBlocksInCache (true );
114-
115- // Configure column family options with smaller write buffers
113+ .setBlockCache (new LRUCache (512 * 1024L )) // Minimal 512KB cache
114+ .setNoBlockCache (false ) // Can't disable completely, but set very small
115+ .setFilterPolicy (null ) // Disable bloom filters completely
116+ .setBlockSize (1 * 1024 ) // 1KB blocks (very small)
117+ .setCacheIndexAndFilterBlocks (false )
118+ .setIndexType (IndexType .kBinarySearch ) // Uses less memory than hash
119+ .setWholeKeyFiltering (true );
120+
121+ // Minimal write buffer configuration
116122 ColumnFamilyOptions cfOptions = new ColumnFamilyOptions ()
117- .setWriteBufferSize (4 * 1024 * 1024L ) // 4MB instead of 64MB
118- .setMaxWriteBufferNumber (2 ) // 2 instead of 3
123+ .setWriteBufferSize (1 * 1024 * 1024L ) // 1MB write buffer
124+ .setMaxWriteBufferNumber (1 ) // Only one buffer
119125 .setMinWriteBufferNumberToMerge (1 )
126+ .setCompressionType (CompressionType .ZSTD_COMPRESSION ) // Best compression
127+ .setBottommostCompressionType (CompressionType .ZSTD_COMPRESSION )
128+ .setCompressionOptions (new CompressionOptions ().setMaxDictBytes (4 * 1024 ))
120129 .setTableFormatConfig (tableConfig )
121- .setCompressionType (CompressionType .LZ4_COMPRESSION ) // Fast compression
122- .setBottommostCompressionType (CompressionType .ZSTD_COMPRESSION ); // Better for cold data
130+ .setOptimizeFiltersForHits (true )
131+ .setMemtablePrefixBloomSizeRatio (0 ) // Disable memtable bloom filter
132+ .setMemtableHugePageSize (0 )
133+ .setArenaBlockSize (256 * 1024 ) // Smaller arena blocks
134+ .setMaxSuccessiveMerges (1 ) // Minimize merges
135+ .setInplaceUpdateSupport (false ); // Save memory by disabling
123136
124137 // 4. Prepare column families
125138 List <ColumnFamilyDescriptor > cfDescriptors = new ArrayList <>();
@@ -150,8 +163,14 @@ public MerkleTree(String treeName) throws RocksDBException {
150163
151164 // 8. Register instance
152165 openTrees .put (treeName , this );
153- }
154166
167+ // 9. Force manual compaction on startup to reduce memory footprint
168+ try {
169+ db .compactRange ();
170+ } catch (Exception e ) {
171+ // Ignore compaction errors
172+ }
173+ }
155174 //endregion
156175
157176 //region ===================== Public Methods =====================
0 commit comments