use of com.twitter.distributedlog.client.monitor.MonitorServiceClient in project distributedlog by twitter.
the class SimpleBalancer method balance.
@Override
public void balance(int rebalanceWaterMark, double rebalanceTolerancePercentage, int rebalanceConcurrency, Optional<RateLimiter> rebalanceRateLimiter) {
// get the ownership distributions from individual targets
Map<SocketAddress, Set<String>> distribution1 = targetMonitor1.getStreamOwnershipDistribution();
Map<SocketAddress, Set<String>> distribution2 = targetMonitor2.getStreamOwnershipDistribution();
// get stream counts
int proxyCount1 = distribution1.size();
int streamCount1 = countNumberStreams(distribution1);
int proxyCount2 = distribution2.size();
int streamCount2 = countNumberStreams(distribution2);
logger.info("'{}' has {} streams by {} proxies; while '{}' has {} streams by {} proxies.", new Object[] { target1, streamCount1, proxyCount1, target2, streamCount2, proxyCount2 });
String source, target;
Map<SocketAddress, Set<String>> srcDistribution;
DistributedLogClient srcClient, targetClient;
MonitorServiceClient srcMonitor, targetMonitor;
int srcStreamCount, targetStreamCount;
if (streamCount1 > streamCount2) {
source = target1;
srcStreamCount = streamCount1;
srcClient = targetClient1;
srcMonitor = targetMonitor1;
srcDistribution = distribution1;
target = target2;
targetStreamCount = streamCount2;
targetClient = targetClient2;
targetMonitor = targetMonitor2;
} else {
source = target2;
srcStreamCount = streamCount2;
srcClient = targetClient2;
srcMonitor = targetMonitor2;
srcDistribution = distribution2;
target = target1;
targetStreamCount = streamCount1;
targetClient = targetClient1;
targetMonitor = targetMonitor1;
}
Map<String, Integer> loadDistribution = new HashMap<String, Integer>();
loadDistribution.put(source, srcStreamCount);
loadDistribution.put(target, targetStreamCount);
// Calculate how many streams to be rebalanced from src region to target region
int numStreamsToRebalance = BalancerUtils.calculateNumStreamsToRebalance(source, loadDistribution, rebalanceWaterMark, rebalanceTolerancePercentage);
if (numStreamsToRebalance <= 0) {
logger.info("No streams need to be rebalanced from '{}' to '{}'.", source, target);
return;
}
StreamChooser streamChooser = LimitedStreamChooser.of(new CountBasedStreamChooser(srcDistribution), numStreamsToRebalance);
StreamMover streamMover = new StreamMoverImpl(source, srcClient, srcMonitor, target, targetClient, targetMonitor);
moveStreams(streamChooser, streamMover, rebalanceConcurrency, rebalanceRateLimiter);
}
use of com.twitter.distributedlog.client.monitor.MonitorServiceClient in project distributedlog by twitter.
the class SimpleBalancer method balanceAll.
@Override
public void balanceAll(String source, int rebalanceConcurrency, Optional<RateLimiter> rebalanceRateLimiter) {
String target;
DistributedLogClient sourceClient, targetClient;
MonitorServiceClient sourceMonitor, targetMonitor;
if (target1.equals(source)) {
sourceClient = targetClient1;
sourceMonitor = targetMonitor1;
target = target2;
targetClient = targetClient2;
targetMonitor = targetMonitor2;
} else if (target2.equals(source)) {
sourceClient = targetClient2;
sourceMonitor = targetMonitor2;
target = target1;
targetClient = targetClient1;
targetMonitor = targetMonitor1;
} else {
throw new IllegalArgumentException("Unknown target " + source);
}
// get the ownership distributions from individual targets
Map<SocketAddress, Set<String>> distribution = sourceMonitor.getStreamOwnershipDistribution();
if (distribution.isEmpty()) {
return;
}
StreamChooser streamChooser = new CountBasedStreamChooser(distribution);
StreamMover streamMover = new StreamMoverImpl(source, sourceClient, sourceMonitor, target, targetClient, targetMonitor);
moveStreams(streamChooser, streamMover, rebalanceConcurrency, rebalanceRateLimiter);
}
Aggregations