-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable large cache per column family #9127
Changes from all commits
f367972
25b84f0
38ee9ed
772a0a2
7dda8f8
7bd2bec
b5c7b0c
4a2d322
ab733b0
58a1a2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.hyperledger.besu.plugin.services.MetricsSystem; | ||
import org.hyperledger.besu.plugin.services.metrics.MetricCategory; | ||
|
@@ -56,6 +58,8 @@ public class RocksDbInstanceFactory { | |
RocksDbUtil.loadNativeLibrary(); | ||
} | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
public static KvStoreAccessor create( | ||
final MetricsSystem metricsSystem, | ||
final MetricCategory metricCategory, | ||
|
@@ -75,19 +79,16 @@ public static KvStoreAccessor create( | |
final TransactionDBOptions txOptions = new TransactionDBOptions(); | ||
final RocksDbStats rocksDbStats = new RocksDbStats(metricsSystem, metricCategory); | ||
final DBOptions dbOptions = createDBOptions(configuration, rocksDbStats.getStats()); | ||
final LRUCache blockCache = new LRUCache(configuration.getCacheCapacity()); | ||
final ColumnFamilyOptions columnFamilyOptions = | ||
createColumnFamilyOptions(configuration, blockCache); | ||
|
||
final List<AutoCloseable> resources = | ||
new ArrayList<>( | ||
List.of(txOptions, dbOptions, columnFamilyOptions, rocksDbStats, blockCache)); | ||
new ArrayList<>(List.of(txOptions, dbOptions, rocksDbStats)); | ||
|
||
List<ColumnFamilyDescriptor> columnDescriptors = | ||
createColumnFamilyDescriptors(columns, deletedColumns, columnFamilyOptions); | ||
Map<Bytes, KvStoreColumn<?, ?>> columnsById = | ||
columns.stream().collect(Collectors.toMap(KvStoreColumn::getId, Function.identity())); | ||
|
||
try { | ||
final List<ColumnFamilyDescriptor> columnDescriptors = | ||
createColumnFamilyDescriptors(columns, deletedColumns, configuration); | ||
// columnHandles will be filled when the db is opened | ||
final List<ColumnFamilyHandle> columnHandles = new ArrayList<>(columnDescriptors.size()); | ||
final TransactionDB db = | ||
|
@@ -164,24 +165,71 @@ private static DBOptions createDBOptions( | |
} | ||
|
||
private static ColumnFamilyOptions createColumnFamilyOptions( | ||
final KvStoreConfiguration configuration, final Cache cache) { | ||
return new ColumnFamilyOptions() | ||
.setCompressionType(configuration.getCompressionType()) | ||
.setBottommostCompressionType(configuration.getBottomMostCompressionType()) | ||
.setLevelCompactionDynamicLevelBytes(true) | ||
.setTableFormatConfig(createBlockBasedTableConfig(cache)); | ||
final KvStoreConfiguration configuration, final KvStoreColumn<?, ?> column) { | ||
final ColumnFamilyOptions cfOptions; | ||
try { | ||
final LRUCache cache = | ||
column | ||
.getIsLargerCacheAvalilable() | ||
.map( | ||
isLarger -> { | ||
if (isLarger) { | ||
LOG.info("Using larger cache for column {}", column.getId().toHexString()); | ||
return new LRUCache(configuration.getLargerCacheCapacity()); | ||
} else { | ||
return new LRUCache(configuration.getCacheCapacity()); | ||
} | ||
}) | ||
.orElse(new LRUCache(configuration.getCacheCapacity())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So long story short the default value used to be 8MB, which is low. We've changed to 128MB as a first step to get the db performing better and we're trying to narrow down what columns need larger caches, that being said the default should be something lower than 128MB, Rocks default is 32MB (as of release 8.x) which is what I believe we should be using by default as well, 8MB was set long time ago and I don't think is suitable anymore for the current needs. |
||
cfOptions = | ||
new ColumnFamilyOptions() | ||
.setCompressionType(configuration.getCompressionType()) | ||
.setBottommostCompressionType(configuration.getBottomMostCompressionType()) | ||
.setLevelCompactionDynamicLevelBytes(true) | ||
.setTableFormatConfig(createBlockBasedTableConfig(cache)); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Error creating column family options", e); | ||
} | ||
return cfOptions; | ||
} | ||
|
||
private static ColumnFamilyOptions createColumnFamilyOptions( | ||
final KvStoreConfiguration configuration) { | ||
final ColumnFamilyOptions cfOptions; | ||
try { | ||
final LRUCache cache = new LRUCache(configuration.getCacheCapacity()); | ||
cfOptions = | ||
new ColumnFamilyOptions() | ||
.setCompressionType(configuration.getCompressionType()) | ||
.setBottommostCompressionType(configuration.getBottomMostCompressionType()) | ||
.setLevelCompactionDynamicLevelBytes(true) | ||
.setTableFormatConfig(createBlockBasedTableConfig(cache)); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Error creating column family options", e); | ||
} | ||
return cfOptions; | ||
} | ||
|
||
private static List<ColumnFamilyDescriptor> createColumnFamilyDescriptors( | ||
final Collection<KvStoreColumn<?, ?>> columns, | ||
final Collection<Bytes> deletedColumns, | ||
final ColumnFamilyOptions columnFamilyOptions) { | ||
final KvStoreConfiguration configuration) { | ||
final List<ColumnFamilyDescriptor> columnDescriptors = | ||
Stream.concat(columns.stream().map(KvStoreColumn::getId), deletedColumns.stream()) | ||
.map(id -> new ColumnFamilyDescriptor(id.toArrayUnsafe(), columnFamilyOptions)) | ||
columns.stream() | ||
.map( | ||
column -> | ||
new ColumnFamilyDescriptor( | ||
column.getId().toArrayUnsafe(), | ||
createColumnFamilyOptions(configuration, column))) | ||
.collect(Collectors.toCollection(ArrayList::new)); | ||
columnDescriptors.addAll( | ||
deletedColumns.stream() | ||
.map(Bytes::toArrayUnsafe) | ||
.map(id -> new ColumnFamilyDescriptor(id, createColumnFamilyOptions(configuration))) | ||
.toList()); | ||
columnDescriptors.add( | ||
new ColumnFamilyDescriptor(Schema.DEFAULT_COLUMN_ID.toArrayUnsafe(), columnFamilyOptions)); | ||
new ColumnFamilyDescriptor( | ||
Schema.DEFAULT_COLUMN_ID.toArrayUnsafe(), createColumnFamilyOptions(configuration))); | ||
return Collections.unmodifiableList(columnDescriptors); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: not sure if we need this as a info. It seems to be pretty low level and I belive we are happy that most users are gonna use default values anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just for testing purposes.