From ccc899773e903cae48816edc9ad3c564c161111d Mon Sep 17 00:00:00 2001 From: Philipp Marx Date: Mon, 10 Oct 2016 17:27:28 +0200 Subject: [PATCH] Add "concurrencyLevel" option to DfsBlockCache Allow for higher concurrency on DfsBlockCache by adding a configuration for number of estimated concurrent requests. Change-Id: Ia65e58ecb2c459b6d9c9697a2f715d933270f7e6 Signed-off-by: Philipp Marx --- .../internal/storage/dfs/DfsBlockCache.java | 2 +- .../storage/dfs/DfsBlockCacheConfig.java | 31 +++++++++++++++++++ .../org/eclipse/jgit/lib/ConfigConstants.java | 7 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java index 2c8953555..764ae1284 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java @@ -182,7 +182,7 @@ public final class DfsBlockCache { throw new IllegalArgumentException(JGitText.get().tSizeMustBeGreaterOrEqual1); table = new AtomicReferenceArray(tableSize); - loadLocks = new ReentrantLock[32]; + loadLocks = new ReentrantLock[cfg.getConcurrencyLevel()]; for (int i = 0; i < loadLocks.length; i++) loadLocks[i] = new ReentrantLock(true /* fair */); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java index a7d13defd..7e32554c6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java @@ -47,6 +47,7 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_CORE_SECTION; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DFS_SECTION; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_BLOCK_LIMIT; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_BLOCK_SIZE; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_CONCURRENCY_LEVEL; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_STREAM_RATIO; import java.text.MessageFormat; @@ -65,12 +66,14 @@ public class DfsBlockCacheConfig { private long blockLimit; private int blockSize; private double streamRatio; + private int concurrencyLevel; /** Create a default configuration. */ public DfsBlockCacheConfig() { setBlockLimit(32 * MB); setBlockSize(64 * KB); setStreamRatio(0.30); + setConcurrencyLevel(32); } /** @@ -110,6 +113,28 @@ public class DfsBlockCacheConfig { return this; } + /** + * @return the estimated number of threads concurrently accessing the cache. + * Default is 32. + * @since 4.6 + */ + public int getConcurrencyLevel() { + return concurrencyLevel; + } + + /** + * @param newConcurrencyLevel + * the estimated number of threads concurrently accessing the + * cache. + * @return {@code this} + * @since 4.6 + */ + public DfsBlockCacheConfig setConcurrencyLevel( + final int newConcurrencyLevel) { + concurrencyLevel = newConcurrencyLevel; + return this; + } + /** * @return highest percentage of {@link #getBlockLimit()} a single pack can * occupy while being copied by the pack reuse strategy. Default @@ -154,6 +179,12 @@ public class DfsBlockCacheConfig { CONFIG_KEY_BLOCK_SIZE, getBlockSize())); + setConcurrencyLevel(rc.getInt( + CONFIG_CORE_SECTION, + CONFIG_DFS_SECTION, + CONFIG_KEY_CONCURRENCY_LEVEL, + getConcurrencyLevel())); + String v = rc.getString( CONFIG_CORE_SECTION, CONFIG_DFS_SECTION, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java index 9e3e0b78f..9a1f565d7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java @@ -145,6 +145,13 @@ public class ConfigConstants { /** The "blockSize" key */ public static final String CONFIG_KEY_BLOCK_SIZE = "blockSize"; + /** + * The "concurrencyLevel" key + * + * @since 4.6 + */ + public static final String CONFIG_KEY_CONCURRENCY_LEVEL = "concurrencyLevel"; + /** The "deltaBaseCacheLimit" key */ public static final String CONFIG_KEY_DELTA_BASE_CACHE_LIMIT = "deltaBaseCacheLimit";