diff --git a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java index 26a06a2505c..9136719280a 100644 --- a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java +++ b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java @@ -102,6 +102,7 @@ public String getVersion() { .build(); private boolean _useRegex; private boolean _allPoolsActive; + public boolean _cachingEnabeled; /** * Ok, this is the critical part of PoolManager, but (!!!) the whole select path is READ-ONLY, @@ -115,6 +116,12 @@ public String getVersion() { private final NetHandler _netHandler = new NetHandler(); private transient PnfsHandler _pnfsHandler; + + public void setCachingEnabeled(boolean cachingEnabeled) { + _cachingEnabeled = cachingEnabeled; + } + + @Override public Map getLinks() { rlock(); @@ -655,28 +662,36 @@ public PoolPreferenceLevel[] match(DirectionType type, String netUnitName, type, storeUnitName, dCacheUnitName, netUnitName, protocolUnitName, variableMap, storageInfo.locations(), linkGroupName); + + String cacheKey = null; - try { - Unit unit = _netHandler.match(netUnitName); - netUnitGroup = unit._uGroupList.values() - .stream() - .map(UGroup::getName).findFirst().get(); + if (_cachingEnabeled) { + + try { + Unit unit = _netHandler.match(netUnitName); + netUnitGroup = unit._uGroupList.values() + .stream() + .map(UGroup::getName).findFirst().get(); - LOGGER.debug("this IP address belongs to {} in uGroup {} ", netUnitName, netUnitGroup); + LOGGER.debug("this IP address belongs to {} in uGroup {} ", netUnitName, netUnitGroup); - } catch (UnknownHostException e) { - LOGGER.error("Caching did not work, please check the configuration " + e); - } + } catch (UnknownHostException e) { + LOGGER.error("Caching did not work, please check the configuration " + e); + } - cacheKey = type.toString() + storeUnitName + dCacheUnitName + - netUnitGroup + protocolUnitName + linkGroupName; + cacheKey = type.toString() + storeUnitName + dCacheUnitName + + netUnitGroup + protocolUnitName + linkGroupName; - PoolPreferenceLevel[] cachedMatchValueTmp = cachedMatchValue.getIfPresent(cacheKey); - if (cachedMatchValueTmp != null) { - return cachedMatchValueTmp; + PoolPreferenceLevel[] cachedMatchValueTmp = cachedMatchValue.getIfPresent(cacheKey); + if (cachedMatchValueTmp != null) { + //counter = counter + 1; + //System.out.println("counter " + counter); + return cachedMatchValueTmp; + } } + PoolPreferenceLevel[] result = null; rlock(); try { @@ -699,7 +714,9 @@ public PoolPreferenceLevel[] match(DirectionType type, String netUnitName, if (LOGGER.isDebugEnabled()) { logResult(result); } - cachedMatchValue.put(cacheKey, result); + if (_cachingEnabeled){ + cachedMatchValue.put(cacheKey, result); + } return result; } @@ -1157,7 +1174,7 @@ public void setAllPoolsActive(String mode) { break; default: throw new IllegalArgumentException( - "Syntax error, no such mode: " + mode); + "Syntax error," + " no such mode: " + mode); } } finally { wunlock(); @@ -2629,8 +2646,11 @@ private String poolCountDescriptionFor(int count) { } protected void wlock() { + _psuWriteLock.lock(); - cachedMatchValue.invalidateAll(); + if (_cachingEnabeled) { + cachedMatchValue.invalidateAll(); + } } protected void wunlock() { diff --git a/modules/dcache/src/test/java/org/dcache/tests/poolmanager/PoolSelectionUnitTest.java b/modules/dcache/src/test/java/org/dcache/tests/poolmanager/PoolSelectionUnitTest.java index c6f9d06cc3c..942741d1af6 100644 --- a/modules/dcache/src/test/java/org/dcache/tests/poolmanager/PoolSelectionUnitTest.java +++ b/modules/dcache/src/test/java/org/dcache/tests/poolmanager/PoolSelectionUnitTest.java @@ -334,6 +334,8 @@ public void testTheSameCached() throws CommandException { FileAttributes fileAttributes = new FileAttributes(); StorageInfos.injectInto(GenericStorageInfo.valueOf("*", "*"), fileAttributes); + _psu._cachingEnabeled = true; + PoolPreferenceLevel[] preferenceRes1 = _psu.match( DirectionType.READ, // operation "131.169.214.149", // net unit diff --git a/skel/share/defaults/poolmanager.properties b/skel/share/defaults/poolmanager.properties index 7c2ae5a5569..91eaeffb220 100644 --- a/skel/share/defaults/poolmanager.properties +++ b/skel/share/defaults/poolmanager.properties @@ -114,3 +114,11 @@ poolmanager.request-notifier.timeout=1 (obsolete)poolmanager.cell.export = See poolmanager.cell.consume (forbidden)poolmanager.plugins.selection-unit = (forbidden)poolmanager.plugins.quota-manager = + +# +# This property is used to optimise pool selection based on the idea that +# when a request is coming the probability that the next request for pool selection will +# have the same selection parameters is very high. depending on the set up you can switch on/ and off +# the caching of the selected pools. + +(one-of?true|false)poolmanager.selection.unit.cachingenabeled = false