Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public class DbLedgerStorage implements LedgerStorage {

private static final int MB = 1024 * 1024;

private static final long DEFAULT_WRITE_CACHE_MAX_SIZE_MB =
public static final long DEFAULT_WRITE_CACHE_MAX_SIZE_MB =
(long) (0.25 * PlatformDependent.estimateMaxDirectMemory()) / MB;
private static final long DEFAULT_READ_CACHE_MAX_SIZE_MB =
public static final long DEFAULT_READ_CACHE_MAX_SIZE_MB =
(long) (0.25 * PlatformDependent.estimateMaxDirectMemory()) / MB;

static final String READ_AHEAD_CACHE_BATCH_SIZE = "dbStorage_readAheadCacheBatchSize";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
// CHECKSTYLE.OFF: IllegalImport
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.util.NettyRuntime;
import io.netty.util.internal.PlatformDependent;
// CHECKSTYLE.ON: IllegalImport
import java.io.File;
Expand Down Expand Up @@ -3858,6 +3860,50 @@ public boolean isLocalConsistencyCheckOnStartup() {
return this.getBoolean(LOCAL_CONSISTENCY_CHECK_ON_STARTUP, false);
}

/**
* The configured pooling concurrency for the allocator, if user config it, we should consider the unpooled
* direct memory which readCache and writeCache occupy when use DbLedgerStorage.
*/
public int getAllocatorPoolingConcurrency() {
Integer allocatorPoolingConcurrency = this.getInteger(ALLOCATOR_POOLING_CONCURRENCY, null);
if (allocatorPoolingConcurrency != null) {
return allocatorPoolingConcurrency;
}
String ledgerStorageClass = getLedgerStorageClass();
if (DbLedgerStorage.class.getName().equals(ledgerStorageClass)) {
long writeCacheMb;
Object writeCacheConf = this.getProperty(DbLedgerStorage.WRITE_CACHE_MAX_SIZE_MB);
if (writeCacheConf instanceof Number) {
writeCacheMb = ((Number) writeCacheConf).longValue();
} else if (writeCacheConf == null) {
writeCacheMb = DbLedgerStorage.DEFAULT_WRITE_CACHE_MAX_SIZE_MB;
} else if (StringUtils.isEmpty(this.getString(DbLedgerStorage.WRITE_CACHE_MAX_SIZE_MB))) {
writeCacheMb = DbLedgerStorage.DEFAULT_WRITE_CACHE_MAX_SIZE_MB;
} else {
writeCacheMb = this.getLong(DbLedgerStorage.WRITE_CACHE_MAX_SIZE_MB);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all this can be done better by moving

        long writeCacheMaxSize = getLongVariableOrDefault(conf, WRITE_CACHE_MAX_SIZE_MB,
                DEFAULT_WRITE_CACHE_MAX_SIZE_MB) * MB;
        long readCacheMaxSize = getLongVariableOrDefault(conf, READ_AHEAD_CACHE_MAX_SIZE_MB,
                DEFAULT_READ_CACHE_MAX_SIZE_MB) * MB;
        boolean directIOEntryLogger = getBooleanVariableOrDefault(conf, DIRECT_IO_ENTRYLOGGER, false);

and related config magic out of DbLedgerStorage into the ServerConfig
and then all you'd need to do is something like this.getWriteCacheMaxSize()

Copy link
Member Author

@horizonzy horizonzy Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, I green with @dlg99

  1. move DbLedgerStorage.DEFAULT_WRITE_CACHE_MAX_SIZE_MB to ServerConfiguration.DEFAULT_WRITE_CACHE_MAX_SIZE_MB

  2. use new code

long writeCacheMaxSize = getLongVariableOrDefault(conf, WRITE_CACHE_MAX_SIZE_MB, conf.getAllocatorPoolingConcurrency()) * MB; 
long readCacheMaxSize = getLongVariableOrDefault(conf, READ_AHEAD_CACHE_MAX_SIZE_MB, conf.getAllocatorPoolingConcurrency()) * MB;

instead of

long writeCacheMaxSize = getLongVariableOrDefault(conf, WRITE_CACHE_MAX_SIZE_MB, DEFAULT_WRITE_CACHE_MAX_SIZE_MB) * MB; 
long readCacheMaxSize = getLongVariableOrDefault(conf, READ_AHEAD_CACHE_MAX_SIZE_MB, DEFAULT_READ_CACHE_MAX_SIZE_MB) * MB;

long readCacheMb;
Object readCacheConf = this.getProperty(DbLedgerStorage.READ_AHEAD_CACHE_MAX_SIZE_MB);
if (readCacheConf instanceof Number) {
readCacheMb = ((Number) readCacheConf).longValue();
} else if (readCacheConf == null) {
readCacheMb = DbLedgerStorage.DEFAULT_READ_CACHE_MAX_SIZE_MB;
} else if (StringUtils.isEmpty(this.getString(DbLedgerStorage.READ_AHEAD_CACHE_MAX_SIZE_MB))) {
readCacheMb = DbLedgerStorage.DEFAULT_READ_CACHE_MAX_SIZE_MB;
} else {
readCacheMb = this.getLong(DbLedgerStorage.READ_AHEAD_CACHE_MAX_SIZE_MB);
}
int mb = 1024 * 1024;
long availableDirectMemory = PlatformDependent.maxDirectMemory() - writeCacheMb * mb - readCacheMb * mb;
int defaultMinNumArena = NettyRuntime.availableProcessors() * 2;
final int defaultChunkSize =
PooledByteBufAllocator.defaultPageSize() << PooledByteBufAllocator.defaultMaxOrder();
int suitableNum = (int) (availableDirectMemory / defaultChunkSize / 2 / 3);
return Math.min(defaultMinNumArena, suitableNum);
}
return super.getAllocatorPoolingConcurrency();
}

/**
* Get the authorized roles.
*
Expand Down