Source:
<code>public GridDhtPartitionDemander(CacheGroupContext grp) { assert grp != null; this.grp = grp; ctx = grp.shared(); log = ctx.logger(getClass()); boolean enabled = grp.rebalanceEnabled() && !ctx.kernalContext().clientNode(); rebalanceFut = new RebalanceFuture(); if (!enabled) { rebalanceFut.onDone(true); syncFut.onDone(); } Map<Integer, Object> tops = new HashMap<>(); rebalanceTopic = GridCachePartitionExchangeManager.rebalanceTopic(0); String metricGroupName = metricName(CACHE_GROUP_METRICS_PREFIX, grp.cacheOrGroupName()); MetricRegistry mreg = grp.shared().kernalContext().metric().registry(metricGroupName); <START> mreg.register("RebalancingPartitionsLeft", () -> rebalanceFut.remaining.values().stream() <END> .map(IgniteDhtDemandedPartitionsMap::fullSet) .mapToInt(Collection::size) .sum(), "Number of rebalanced partitions left."); mreg.register("RebalancingReceivedKeys", () -> rebalanceFut.rebalancingReceivedKeys.get(), "Number of already rebalanced keys."); mreg.register("RebalancingReceivedBytes", () -> rebalanceFut.rebalancingReceivedBytes.get(), "Number of already rebalanced bytes."); mreg.register("RebalancingStartTime", () -> rebalanceFut.rebalancingStartTime, "Rebalancing start time."); mreg.register("RebalancingFinishTime", () -> rebalanceFut.rebalancingFinishTime, "Rebalancing finish time."); }</code><technical_language>I pre-calculate partition future creation time decrement demand. Seeking thought map for metrics expensive</technical_language>

Target:
public GridDhtPartitionDemander(CacheGroupContext grp) { assert grp != null; this.grp = grp; ctx = grp.shared(); log = ctx.logger(getClass()); boolean enabled = grp.rebalanceEnabled() && !ctx.kernalContext().clientNode(); rebalanceFut = new RebalanceFuture(); if (!enabled) { rebalanceFut.onDone(true); syncFut.onDone(); } Map<Integer, Object> tops = new HashMap<>(); rebalanceTopic = GridCachePartitionExchangeManager.rebalanceTopic(0); String metricGroupName = metricName(CACHE_GROUP_METRICS_PREFIX, grp.cacheOrGroupName()); MetricRegistry mreg = grp.shared().kernalContext().metric().registry(metricGroupName); mreg.register("RebalancingPartitionsLeft", () -> rebalanceFut.partitionsLeft.get(), "The number of cache group partitions left to be rebalanced."); mreg.register("RebalancingReceivedKeys", () -> rebalanceFut.receivedKeys.get(), "The number of currently rebalanced keys for the whole cache group."); mreg.register("RebalancingReceivedBytes", () -> rebalanceFut.receivedBytes.get(), "The number of currently rebalanced bytes of this cache group."); mreg.register("RebalancingStartTime", () -> rebalanceFut.startTime, "The time the first partition " + "demand message was sent. If there are no messages to send, the rebalancing time will be undefined."); mreg.register("RebalancingEndTime", () -> rebalanceFut.endTime, "The time the rebalancing was " + "completed. If the rebalancing completed with an error, was cancelled, or the start time was undefined, " + "the rebalancing end time will be undefined."); mreg.register("RebalancingLastCancelledTime", () -> lastCancelledTime.get(), "The time the " + "rebalancing was completed with an error or was cancelled. If there were several such cases, the metric " + "stores the last time. The metric displays the value even if there is no rebalancing process."); }