public static RebalanceResults rebalanceCache(GemFireCache cache) throws CancellationException, InterruptedException { ResourceManager resourceManager = cache.getResourceManager(); RebalanceFactory rebalanceFactory = resourceManager.createRebalanceFactory(); RebalanceOperation rebalanceOperation = rebalanceFactory.start(); return rebalanceOperation.getResults(); }
@Override public void rebalance() { try { RebalanceOperation operation = getCache().getResourceManager().createRebalanceFactory().start(); RebalanceResults result = operation.getResults(); logger .info("Rebalance result: [TotalBucketCreateBytes=" + result.getTotalBucketCreateBytes() + ", TotalBucketCreateTime=" + result.getTotalBucketCreateTime() + ", TotalBucketCreatesCompleted=" + result.getTotalBucketCreatesCompleted() + ", TotalBucketTransferBytes=" + result.getTotalBucketTransferBytes() + ", TotalBucketTransferTime=" + result.getTotalBucketTransferTime() + ", TotalBucketTransfersCompleted=" + +result.getTotalBucketTransfersCompleted() + ", TotalPrimaryTransferTime=" + result.getTotalPrimaryTransferTime() + ", TotalPrimaryTransfersCompleted=" + result.getTotalPrimaryTransfersCompleted() + ", TotalTime=" + result.getTotalTime() + "]"); } catch (CancellationException e) { logger.info("Error rebalancing the cluster", e); } catch (InterruptedException e) { logger.info("Error rebalancing the cluster", e); } }
@Override public long getTotalTransferSize() { try { RebalanceOperation operation = getCache().getResourceManager().createRebalanceFactory().simulate(); RebalanceResults result = operation.getResults(); if (logger.isDebugEnabled()) { logger.debug("Rebalance estimate: RebalanceResultsImpl [TotalBucketCreateBytes=" + result.getTotalBucketCreateBytes() + ", TotalBucketCreatesCompleted=" + result.getTotalBucketCreatesCompleted() + ", TotalBucketTransferBytes=" + result.getTotalBucketTransferBytes() + ", TotalBucketTransfersCompleted=" + result.getTotalBucketTransfersCompleted() + ", TotalPrimaryTransfersCompleted=" + result.getTotalPrimaryTransfersCompleted() + "]"); } return result.getTotalBucketTransferBytes(); } catch (CancellationException e) { logger.info("Error while trying to estimate rebalance cost ", e); } catch (InterruptedException e) { logger.info("Error while trying to estimate rebalance cost ", e); } return 0; }
Set<String> includeRegionNames = (Set<String>) args[1]; Set<String> excludeRegionNames = (Set<String>) args[2]; RebalanceFactory rbFactory = manager.createRebalanceFactory(); rbFactory.excludeRegions(excludeRegionNames); rbFactory.includeRegions(includeRegionNames); RebalanceResults results = null; op = rbFactory.simulate(); } else { op = rbFactory.start(); results = op.getResults(); logger.info("Starting RebalanceFunction got results = {}", results); StringBuilder str1 = new StringBuilder(); str1.append(results.getTotalBucketCreateBytes() + "," + results.getTotalBucketCreateTime() + "," + results.getTotalBucketCreatesCompleted() + "," + results.getTotalBucketTransferBytes() + "," + results.getTotalBucketTransferTime() + "," + results.getTotalBucketTransfersCompleted() + "," + results.getTotalPrimaryTransferTime() + "," + results.getTotalPrimaryTransfersCompleted() + "," + results.getTotalTime() + ","); Set<PartitionRebalanceInfo> regns1 = results.getPartitionRebalanceDetails(); Iterator it = regns1.iterator(); while (it.hasNext()) {
/** * Do a rebalance and verify balance was improved. If evictionPercentage > 0 (the default) then we * have heapLRU and this can cause simulate and rebalance results to differ if eviction kicks in * between. (See BUG 44899). */ public static void doRebalance() { ResourceManager resMan = cache.getResourceManager(); boolean heapEviction = (resMan.getEvictionHeapPercentage() > 0); RebalanceFactory factory = resMan.createRebalanceFactory(); try { RebalanceResults simulateResults = null; if (!heapEviction) { LogWriterUtils.getLogWriter().info("Calling rebalance simulate"); RebalanceOperation simulateOp = factory.simulate(); simulateResults = simulateOp.getResults(); } LogWriterUtils.getLogWriter().info("Starting rebalancing"); RebalanceOperation rebalanceOp = factory.start(); RebalanceResults rebalanceResults = rebalanceOp.getResults(); } catch (InterruptedException e) { Assert.fail("Interrupted", e); } }
public void configure(ResourceManager r) { if (hasCriticalHeap()) { r.setCriticalHeapPercentage(this.criticalHeapPercentage); } if (hasCriticalOffHeap()) { r.setCriticalOffHeapPercentage(this.criticalOffHeapPercentage); } if (hasEvictionHeap()) { r.setEvictionHeapPercentage(this.evictionHeapPercentage); } if (hasEvictionOffHeap()) { r.setEvictionOffHeapPercentage(this.evictionOffHeapPercentage); } }
float currentEvictionHeapPercentage = rm.getEvictionHeapPercentage(); float currentCriticalHeapPercentage = rm.getCriticalHeapPercentage(); rm.setEvictionHeapPercentage(getEvictionHeapPercentage()); rm.setCriticalHeapPercentage(getCriticalHeapPercentage()); } catch (IllegalArgumentException e) { handleResourceManagerException(e, currentEvictionHeapPercentage, currentCriticalHeapPercentage); rm.setEvictionHeapPercentage(currentEvictionHeapPercentage); rm.setCriticalHeapPercentage(currentCriticalHeapPercentage); rm.setCriticalHeapPercentage(getCriticalHeapPercentage()); rm.setEvictionHeapPercentage(getEvictionHeapPercentage()); } catch (IllegalArgumentException e) { handleResourceManagerException(e, currentEvictionHeapPercentage, currentCriticalHeapPercentage); rm.setCriticalHeapPercentage(currentCriticalHeapPercentage); rm.setEvictionHeapPercentage(currentEvictionHeapPercentage); rm.setEvictionHeapPercentage(getEvictionHeapPercentage()); rm.setCriticalHeapPercentage(getCriticalHeapPercentage()); } catch (IllegalArgumentException e) { handleResourceManagerException(e, currentEvictionHeapPercentage, currentCriticalHeapPercentage); rm.setEvictionHeapPercentage(currentEvictionHeapPercentage); rm.setCriticalHeapPercentage(currentCriticalHeapPercentage); builder.append("Actual eviction heap percentage=").append(rm.getEvictionHeapPercentage()) .append("; critical heap percentage=").append(rm.getCriticalHeapPercentage());
RebalanceFactory rbFactory = manager.createRebalanceFactory(); Set<String> excludeRegionSet = new HashSet<>(); if (excludeRegions != null) { Collections.addAll(excludeRegionSet, excludeRegions); rbFactory.excludeRegions(excludeRegionSet); Set<String> includeRegionSet = new HashSet<>(); includeRegionSet.add(regionName); rbFactory.includeRegions(includeRegionSet); op = manager.createRebalanceFactory().simulate(); result = ResultBuilder.buildResult(buildResultForRebalance(rebalanceResultData, op.getResults(), index, true, cache)); op = manager.createRebalanceFactory().start(); op.getResults(), index, false, cache));
/** * @param other the other ResourceManager with which to compare */ public void sameAs(ResourceManager other) { if (getCriticalHeapPercentage() != other.getCriticalHeapPercentage()) { throw new RuntimeException("Resource Manager critical heap percentages differ: " + getCriticalHeapPercentage() + " != " + other.getCriticalHeapPercentage()); } if (getCriticalOffHeapPercentage() != other.getCriticalOffHeapPercentage()) { throw new RuntimeException("Resource Manager critical off-heap percentages differ: " + getCriticalOffHeapPercentage() + " != " + other.getCriticalOffHeapPercentage()); } if (hasEvictionHeap()) { // If we don't have it set don't compare since other may have been set to // a smart default. if (getEvictionHeapPercentage() != other.getEvictionHeapPercentage()) { throw new RuntimeException("Resource Manager eviction heap percentages differ: " + getEvictionHeapPercentage() + " != " + other.getEvictionHeapPercentage()); } } if (hasEvictionOffHeap()) { // If we don't have it set don't compare since other may have been set to // a smart default. if (getEvictionOffHeapPercentage() != other.getEvictionOffHeapPercentage()) { throw new RuntimeException("Resource Manager eviction off-heap percentages differ: " + getEvictionOffHeapPercentage() + " != " + other.getEvictionOffHeapPercentage()); } } }
public static RebalanceResults rebalanceRegion(Region region) throws CancellationException, InterruptedException { String regionName = region.getName(); // FilterByName only looks at name and not full path if (!PartitionRegionHelper.isPartitionedRegion(region)) { StringBuilder builder = new StringBuilder(); builder.append("Region ").append(regionName).append(" is not partitioned. Instead, it is ") .append(region.getAttributes().getDataPolicy()).append(". It can't be rebalanced."); throw new IllegalArgumentException(builder.toString()); } // Rebalance the region ResourceManager resourceManager = region.getCache().getResourceManager(); RebalanceFactory rebalanceFactory = resourceManager.createRebalanceFactory(); Set<String> regionsToRebalance = new HashSet<String>(); regionsToRebalance.add(regionName); rebalanceFactory.includeRegions(regionsToRebalance); RebalanceOperation rebalanceOperation = rebalanceFactory.start(); // Return the results return rebalanceOperation.getResults(); }
private CompositeResultData buildResultForRebalance(CompositeResultData rebalanceResultData, RebalanceResults results, int index, boolean simulate, InternalCache cache) { Set<PartitionRebalanceInfo> regions = results.getPartitionRebalanceDetails(); Iterator iterator = regions.iterator(); resultData.accumulate("Value", results.getTotalBucketCreateBytes()); resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATEBYTES).append(" = ") .append(results.getTotalBucketCreateBytes()).append(newLine); resultData.accumulate("Value", results.getTotalBucketCreateTime()); resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATETIM).append(" = ") .append(results.getTotalBucketCreateTime()).append(newLine); resultData.accumulate("Value", results.getTotalBucketCreatesCompleted()); resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATESCOMPLETED).append(" = ") .append(results.getTotalBucketCreatesCompleted()).append(newLine); resultData.accumulate("Value", results.getTotalBucketTransferBytes()); resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERBYTES).append(" = ") .append(results.getTotalBucketTransferBytes()).append(newLine); resultData.accumulate("Value", results.getTotalBucketTransferTime()); resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERTIME).append(" = ") .append(results.getTotalBucketTransferTime()).append(newLine); resultData.accumulate("Value", results.getTotalBucketTransfersCompleted()); resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERSCOMPLETED).append(" = ") .append(results.getTotalBucketTransfersCompleted()).append(newLine); resultData.accumulate("Value", results.getTotalPrimaryTransferTime());
private GeodeCacheFacade getFacadeForResourceManagerOps(final boolean simulate) throws Exception { final GemFireCacheImpl mockCache = mock(GemFireCacheImpl.class); final InternalResourceManager mockRM = mock(InternalResourceManager.class); final RebalanceFactory mockRebalanceFactory = mock(RebalanceFactory.class); final RebalanceOperation mockRebalanceOperation = mock(RebalanceOperation.class); final RebalanceResults mockRebalanceResults = mock(RebalanceResults.class); when(mockCache.isClosed()).thenReturn(false); when(mockCache.getResourceManager()).thenReturn(mockRM); when(mockRM.createRebalanceFactory()).thenReturn(mockRebalanceFactory); when(mockRebalanceFactory.start()).thenReturn(mockRebalanceOperation); when(mockRebalanceFactory.simulate()).thenReturn(mockRebalanceOperation); when(mockRebalanceOperation.getResults()).thenReturn(mockRebalanceResults); if (simulate) when(mockRebalanceResults.getTotalBucketTransferBytes()).thenReturn(12345L); return new GeodeCacheFacade(mockCache); }
rm.setCriticalHeapPercentage(val); rm.setEvictionHeapPercentage(val);
/** * Causes a rebalance operation to occur on the given Cache. * * @param cache the reference to the Cache to rebalance. * @see org.apache.geode.cache.control.ResourceManager#createRebalanceFactory() */ private void rebalance(final Cache cache) { if (isRebalancing()) { cache.getResourceManager().createRebalanceFactory().start(); } }
private static void verifyCMSInitiatingOccupancyFraction(GemFireCache cache, ResourceManager rm, String cmsIOF) { if (cmsIOF == null) { cache.getLogger().warning( "Setting the CMS initiating occupancy fraction (configured using -XX:CMSInitiatingOccupancyFraction=N) is recommended so that GemFire cache eviction is optimal"); } else { // Parse the CMSInitiatingOccupancyFraction. Verify it is less than both eviction and critical // thresholds. int cmsIOFVal = Integer.parseInt(cmsIOF.split("=")[1]); float currentEvictionHeapPercentage = rm.getEvictionHeapPercentage(); if (currentEvictionHeapPercentage != 0 && currentEvictionHeapPercentage < cmsIOFVal) { cache.getLogger() .warning("Setting the CMS initiating occupancy fraction (" + cmsIOFVal + ") less than the eviction heap percentage (" + currentEvictionHeapPercentage + ") is recommended so that GemFire cache eviction is optimal"); } float currentCriticalHeapPercentage = rm.getCriticalHeapPercentage(); if (currentCriticalHeapPercentage != 0 && currentCriticalHeapPercentage < cmsIOFVal) { cache.getLogger() .warning("Setting the CMS initiating occupancy fraction (" + cmsIOFVal + ") less than the critical heap percentage (" + currentCriticalHeapPercentage + ") is recommended so that GemFire cache eviction is optimal"); } } }
public static String getRebalanceResultsMessage(RebalanceResults results) { StringBuilder builder = new StringBuilder(); for (PartitionRebalanceInfo rebalanceInfo : results.getPartitionRebalanceDetails()) { // Log the overall results fillInRebalanceResultsSummary(builder, rebalanceInfo); // Log the 'Before' results fillInRebalanceResultsMemberDetails(builder, rebalanceInfo.getPartitionMemberDetailsBefore(), "Before"); // Log the 'After' results fillInRebalanceResultsMemberDetails(builder, rebalanceInfo.getPartitionMemberDetailsAfter(), "After"); } return builder.toString(); }
/** * Some tests run so quickly that the rebalance operation doesn't even have time to start before * regions are already being destroyed - GEDOE-4312. */ private static void waitForNoRebalancing() { if (cache != null && !cache.isClosed()) { await().until(() -> { return cache.getResourceManager().getRebalanceOperations().size() == 0; }); } }
cache.getResourceManager().setCriticalHeapPercentage(threshold); cache.getResourceManager().setEvictionHeapPercentage(threshold); getCriticalOffHeapPercent(options); if (threshold > 0.0f) { cache.getResourceManager().setCriticalOffHeapPercentage(threshold); cache.getResourceManager().setEvictionOffHeapPercentage(threshold);
private void executeWithLastResult(FunctionContext context) { RegionFunctionContext rfContext = (RegionFunctionContext) context; final PartitionedRegion pr = (PartitionedRegion) rfContext.getDataSet(); ResourceManager resMan = pr.getCache().getResourceManager(); RebalanceFactory factory = resMan.createRebalanceFactory(); RebalanceOperation rebalanceOp = factory.start(); try { rebalanceOp.getResults(); } catch (CancellationException | InterruptedException e) { e.printStackTrace(); } context.getResultSender().lastResult(context.getArguments()); }
int chp = (int) this.cache.getResourceManager().getCriticalHeapPercentage(); if (generateDefaults() || chp != MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE) int ehp = (int) this.cache.getResourceManager().getEvictionHeapPercentage(); if (generateDefaults() || ehp != MemoryThresholds.DEFAULT_EVICTION_PERCENTAGE) atts.addAttribute("", "", EVICTION_HEAP_PERCENTAGE, "", String.valueOf(ehp)); int chp = (int) this.cache.getResourceManager().getCriticalOffHeapPercentage(); if (generateDefaults() || chp != MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE) int ehp = (int) this.cache.getResourceManager().getEvictionOffHeapPercentage(); if (generateDefaults() || ehp != MemoryThresholds.DEFAULT_EVICTION_PERCENTAGE) atts.addAttribute("", "", EVICTION_OFF_HEAP_PERCENTAGE, "", String.valueOf(ehp));