@Override public HPCMemoryConfig apply(String s) { HPCMemoryConfig.Source source = HPCMemoryConfig.Source.EXPLICIT_MEMORY_RATIO; //noinspection StringEquality if (s == DEFAULT) // Note instance equality check is on purpose { s = "50.0"; source = HPCMemoryConfig.Source.DEFAULT_MEMORY_RATIO; } long oldGenSize = memoryPoolMax("java.lang:type=MemoryPool,name=G1 Old Gen") .or(memoryPoolMax("java.lang:type=MemoryPool,name=PS Old Gen")) .or(heap() / 2) // Conservative, to be on the safe side .get(); long allocated = (long) ((FLOAT.apply(s) / 100.0) * oldGenSize); return new HPCMemoryConfig( /* Node cache size */ (long) (allocated * 0.3), /* Rel cache size */ (long) (allocated * 0.4), /* Node lookup table */ asPercentageOfHeap(allocated * 0.1), /* Rel lookup table */ asPercentageOfHeap(allocated * 0.1), source); }
@Override public HPCMemoryConfig apply( HPCMemoryConfig basedOnRatio, Function<String, String> settings) { String explicitNodeCacheSize = settings.apply(HighPerformanceCacheSettings.node_cache_size.name()); String explicitRelCacheSize = settings.apply(HighPerformanceCacheSettings.relationship_cache_size.name()); String explicitNodeArrayFraction = settings.apply(HighPerformanceCacheSettings.node_cache_array_fraction.name()); String explicitRelArrayFraction = settings.apply( HighPerformanceCacheSettings.relationship_cache_array_fraction.name()); if (explicitNodeCacheSize != null || explicitRelCacheSize != null || explicitNodeArrayFraction != null || explicitRelArrayFraction != null) { // At least one explicit config set, swap to explicit mode long nodeCacheBytes = explicitNodeCacheSize != null ? BYTES.apply(explicitNodeCacheSize) : heap() / 8; long relCacheBytes = explicitRelCacheSize != null ? BYTES.apply(explicitRelCacheSize) : heap() / 8; float nodeArrRatio = explicitNodeArrayFraction != null ? FLOAT.apply(explicitNodeArrayFraction) : 1.0f; float relArrRatio = explicitRelArrayFraction != null ? FLOAT.apply(explicitRelArrayFraction) : 1.0f; // Figure out if user is inadvertently overwriting her own configuration HPCMemoryConfig.Source source = basedOnRatio.source() == HPCMemoryConfig.Source.DEFAULT_MEMORY_RATIO ? HPCMemoryConfig.Source.SPECIFIC : HPCMemoryConfig.Source.SPECIFIC_OVERRIDING_RATIO; return new HPCMemoryConfig( nodeCacheBytes, relCacheBytes, nodeArrRatio, relArrRatio, source); } return basedOnRatio; }