From 7315c8a285fc51a935a73302450b6ab35e1a4276 Mon Sep 17 00:00:00 2001 From: shaozhuguang Date: Sat, 20 Jun 2020 13:35:01 +0800 Subject: [PATCH] add print of rocksdb3 --- .../rocksdb/RocksDBConnectionFactory.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/source/storage/storage-rocksdb/src/main/java/com/jd/blockchain/storage/service/impl/rocksdb/RocksDBConnectionFactory.java b/source/storage/storage-rocksdb/src/main/java/com/jd/blockchain/storage/service/impl/rocksdb/RocksDBConnectionFactory.java index eab7f7f4..0c7dc63a 100644 --- a/source/storage/storage-rocksdb/src/main/java/com/jd/blockchain/storage/service/impl/rocksdb/RocksDBConnectionFactory.java +++ b/source/storage/storage-rocksdb/src/main/java/com/jd/blockchain/storage/service/impl/rocksdb/RocksDBConnectionFactory.java @@ -120,27 +120,32 @@ public class RocksDBConnectionFactory implements DbConnectionFactory { System.out.printf("optionMaxBackgroundCompactions = %s \r\n", optionMaxBackgroundCompactions); System.out.printf("optionMaxBackgroundFlushes = %s \r\n", optionMaxBackgroundFlushes); - Cache cache = new LRUCache(512 * SizeUnit.MB); - - final BlockBasedTableConfig tableOptions = new BlockBasedTableConfig() - .setBlockCache(cache) - .setCacheIndexAndFilterBlocks(true) - ; - - Options options = new Options() - // 最多占用256 * 7 + 512 = 2.25G内存 - .setWriteBufferSize(256 * SizeUnit.MB) - .setMaxWriteBufferNumber(7) - .setMinWriteBufferNumberToMerge(2) - .setMaxOpenFiles(-1) - .setAllowConcurrentMemtableWrite(true) - .setCreateIfMissing(true) - .setTableFormatConfig(tableOptions) - .setMaxBackgroundCompactions(5) - .setMaxBackgroundFlushes(4) - .setMemTableConfig(new SkipListMemTableConfig()) - ; - return options; + Cache cache = new LRUCache(512 * SizeUnit.MB, 64, false); + + final BlockBasedTableConfig tableOptions = new BlockBasedTableConfig() + .setBlockCache(cache) + .setMetadataBlockSize(4096) + .setCacheIndexAndFilterBlocks(true) // 设置索引和布隆过滤器使用Block Cache内存 + .setCacheIndexAndFilterBlocksWithHighPriority(true) + .setIndexType(IndexType.kTwoLevelIndexSearch) // 设置两级索引,控制索引占用内存 + .setPinTopLevelIndexAndFilter(false) + .setBlockSize(4096) + .setFilterPolicy(null) // 不设置布隆过滤器 + ; + + Options options = new Options() + // 最多占用256 * 6 + 512 = 2G内存 + .setWriteBufferSize(256 * SizeUnit.MB) + .setMaxWriteBufferNumber(6) + .setMinWriteBufferNumberToMerge(2) + .setMaxOpenFiles(100) // 控制最大打开文件数量,防止内存持续增加 + .setAllowConcurrentMemtableWrite(true) //允许并行Memtable写入 + .setCreateIfMissing(true) + .setTableFormatConfig(tableOptions) + .setMaxBackgroundCompactions(5) + .setMaxBackgroundFlushes(4) + ; + return options; } /**