-
Notifications
You must be signed in to change notification settings - Fork 963
Tuning pool concurrency #3432
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
Tuning pool concurrency #3432
Changes from all commits
c7dba88
5e94453
ea0c5d8
45098f6
3218e8c
fc09e80
75d4abc
0c7c726
b0e2e7f
ba5fa38
5c33be7
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 |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /** | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * | ||
| */ | ||
| package org.apache.bookkeeper.conf; | ||
|
|
||
| // CHECKSTYLE.OFF: IllegalImport | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import io.netty.buffer.PooledByteBufAllocator; | ||
| import io.netty.util.NettyRuntime; | ||
| import io.netty.util.internal.PlatformDependent; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| // CHECKSTYLE.ON: IllegalImport | ||
|
|
||
| public class DbLedgerStorageConfiguration extends ServerConfiguration { | ||
|
|
||
| private static final int MB = 1024 * 1024; | ||
|
|
||
| @VisibleForTesting | ||
| public static final String WRITE_CACHE_MAX_SIZE_MB = "dbStorage_writeCacheMaxSizeMb"; | ||
|
|
||
| private static final long DEFAULT_WRITE_CACHE_MAX_SIZE_MB = | ||
| (long) (0.25 * PlatformDependent.estimateMaxDirectMemory()) / MB; | ||
|
|
||
| @VisibleForTesting | ||
| public static final String READ_AHEAD_CACHE_MAX_SIZE_MB = "dbStorage_readAheadCacheMaxSizeMb"; | ||
|
|
||
| private static final long DEFAULT_READ_CACHE_MAX_SIZE_MB = | ||
| (long) (0.25 * PlatformDependent.estimateMaxDirectMemory()) / MB; | ||
|
|
||
| private static final String READ_AHEAD_CACHE_BATCH_SIZE = "dbStorage_readAheadCacheBatchSize"; | ||
|
|
||
| private static final int DEFAULT_READ_AHEAD_CACHE_BATCH_SIZE = 100; | ||
|
|
||
| private static final String DIRECT_IO_ENTRYLOGGER = "dbStorage_directIOEntryLogger"; | ||
|
|
||
| private static final String DIRECT_IO_ENTRYLOGGER_TOTAL_WRITEBUFFER_SIZE_MB = | ||
| "dbStorage_directIOEntryLoggerTotalWriteBufferSizeMb"; | ||
|
|
||
| private static final long DEFAULT_DIRECT_IO_TOTAL_WRITEBUFFER_SIZE_MB = | ||
| (long) (0.125 * PlatformDependent.estimateMaxDirectMemory()) / MB; | ||
|
|
||
| private static final String DIRECT_IO_ENTRYLOGGER_TOTAL_READBUFFER_SIZE_MB = | ||
| "dbStorage_directIOEntryLoggerTotalReadBufferSizeMb"; | ||
|
|
||
| private static final long DEFAULT_DIRECT_IO_TOTAL_READBUFFER_SIZE_MB = | ||
| (long) (0.125 * PlatformDependent.estimateMaxDirectMemory()) / MB; | ||
|
|
||
| private static final String DIRECT_IO_ENTRYLOGGER_READBUFFER_SIZE_MB = | ||
| "dbStorage_directIOEntryLoggerReadBufferSizeMb"; | ||
|
|
||
| private static final long DEFAULT_DIRECT_IO_READBUFFER_SIZE_MB = 8; | ||
|
|
||
| private static final String DIRECT_IO_ENTRYLOGGER_MAX_FD_CACHE_TIME_SECONDS = | ||
| "dbStorage_directIOEntryLoggerMaxFdCacheTimeSeconds"; | ||
|
|
||
| private static final int DEFAULT_DIRECT_IO_MAX_FD_CACHE_TIME_SECONDS = 300; | ||
|
|
||
| @VisibleForTesting | ||
| public static final String MAX_THROTTLE_TIME_MILLIS = "dbStorage_maxThrottleTimeMs"; | ||
|
|
||
| private static final long DEFAULT_MAX_THROTTLE_TIME_MILLIS = TimeUnit.SECONDS.toMillis(10); | ||
|
|
||
| public long getWriteCacheMaxSize() { | ||
| return getLongVariableOrDefault(WRITE_CACHE_MAX_SIZE_MB, DEFAULT_WRITE_CACHE_MAX_SIZE_MB) * MB; | ||
| } | ||
|
|
||
| public long getReadCacheMaxSize() { | ||
| return getLongVariableOrDefault(READ_AHEAD_CACHE_MAX_SIZE_MB, DEFAULT_READ_CACHE_MAX_SIZE_MB) * MB; | ||
| } | ||
|
|
||
| public int getReadAheadCacheBatchSize() { | ||
| return this.getInt(READ_AHEAD_CACHE_BATCH_SIZE, DEFAULT_READ_AHEAD_CACHE_BATCH_SIZE); | ||
| } | ||
|
|
||
| public boolean isDirectIOEntryLoggerEnabled() { | ||
| return getBooleanVariableOrDefault(DIRECT_IO_ENTRYLOGGER, false); | ||
| } | ||
|
|
||
| public long getDirectIOEntryLoggerTotalWriteBufferSize() { | ||
| return getLongVariableOrDefault(DIRECT_IO_ENTRYLOGGER_TOTAL_WRITEBUFFER_SIZE_MB, | ||
| DEFAULT_DIRECT_IO_TOTAL_WRITEBUFFER_SIZE_MB) * MB; | ||
| } | ||
|
|
||
| public long getDirectIOEntryLoggerTotalReadBufferSize() { | ||
| return getLongVariableOrDefault(DIRECT_IO_ENTRYLOGGER_TOTAL_READBUFFER_SIZE_MB, | ||
| DEFAULT_DIRECT_IO_TOTAL_READBUFFER_SIZE_MB) * MB; | ||
| } | ||
|
|
||
| public long getDirectIOEntryLoggerReadBufferSize() { | ||
| return getLongVariableOrDefault(DIRECT_IO_ENTRYLOGGER_READBUFFER_SIZE_MB, DEFAULT_DIRECT_IO_READBUFFER_SIZE_MB) | ||
| * MB; | ||
| } | ||
|
|
||
| public long getDirectIOEntryLoggerMaxFDCacheTimeSeconds() { | ||
| return getLongVariableOrDefault(DIRECT_IO_ENTRYLOGGER_MAX_FD_CACHE_TIME_SECONDS, | ||
| DEFAULT_DIRECT_IO_MAX_FD_CACHE_TIME_SECONDS); | ||
| } | ||
|
|
||
| public long getMaxThrottleTimeMillis() { | ||
| return this.getLong(MAX_THROTTLE_TIME_MILLIS, DEFAULT_MAX_THROTTLE_TIME_MILLIS); | ||
| } | ||
|
|
||
| /** | ||
| * 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() { | ||
| long writeCacheSize = this.getWriteCacheMaxSize(); | ||
| long readCacheSize = this.getReadCacheMaxSize(); | ||
| long availableDirectMemory = PlatformDependent.maxDirectMemory() - writeCacheSize - readCacheSize; | ||
|
Contributor
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. Please use
Contributor
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. In dbLedgerStorage,
So I think we'd better keep the default implementation. |
||
| int defaultMinNumArena = NettyRuntime.availableProcessors() * 2; | ||
| final int defaultChunkSize = | ||
| PooledByteBufAllocator.defaultPageSize() << PooledByteBufAllocator.defaultMaxOrder(); | ||
| int suitableNum = (int) (availableDirectMemory / defaultChunkSize / 2 / 3); | ||
| return Math.min(defaultMinNumArena, suitableNum); | ||
| } | ||
|
|
||
| private long getLongVariableOrDefault(String keyName, long defaultValue) { | ||
| Object obj = this.getProperty(keyName); | ||
| if (obj instanceof Number) { | ||
| return ((Number) obj).longValue(); | ||
| } else if (obj == null) { | ||
| return defaultValue; | ||
| } else if (StringUtils.isEmpty(this.getString(keyName))) { | ||
| return defaultValue; | ||
| } else { | ||
| return this.getLong(keyName); | ||
| } | ||
| } | ||
|
|
||
| private boolean getBooleanVariableOrDefault(String keyName, boolean defaultValue) { | ||
| Object obj = this.getProperty(keyName); | ||
| if (obj instanceof Boolean) { | ||
| return (Boolean) obj; | ||
| } else if (obj == null) { | ||
| return defaultValue; | ||
| } else if (StringUtils.isEmpty(this.getString(keyName))) { | ||
| return defaultValue; | ||
| } else { | ||
| return this.getBoolean(keyName); | ||
| } | ||
| } | ||
| } | ||
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.
Could we define
MB?