Skip to content

Commit

Permalink
Tweak new rebalance scheduler
Browse files Browse the repository at this point in the history
Randomized the order of rebalance tasks in each stealer's list. This
will avoid biasing the rebalance based on the order tasks were
generated.
  • Loading branch information
jayjwylie committed Jun 28, 2013
1 parent 34e849e commit d7356df
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/java/voldemort/client/rebalance/RebalanceController.java
Expand Up @@ -696,7 +696,7 @@ public class Scheduler {
}

public void run(List<StealerBasedRebalanceTask> sbTaskList) {
// Setup for this run.
// Setup mapping of stealers to work for this run.
this.tasksByStealer = new HashMap<Integer, List<StealerBasedRebalanceTask>>();
for(StealerBasedRebalanceTask task: sbTaskList) {
if(task.getStealInfos().size() != 1) {
Expand All @@ -715,6 +715,14 @@ public void run(List<StealerBasedRebalanceTask> sbTaskList) {
return;
}

// Shuffle order of each stealer's work list. This randomization
// helps to get rid of any "patterns" in how rebalancing tasks were
// added to the task list passed in.
for(List<StealerBasedRebalanceTask> taskList: tasksByStealer.values()) {
Collections.shuffle(taskList);
}

// Prepare to execute the rebalance
this.numTasksExecuting = 0;
this.nodeIdsWithWork = new HashSet<Integer>();
doneSignal = new CountDownLatch(sbTaskList.size());
Expand Down Expand Up @@ -747,11 +755,9 @@ private synchronized StealerBasedRebalanceTask scheduleNextTask() {
return null;
}

// Should probably round-robin among stealerIds. But, its easier to
// randomly shuffle list of stealer IDs each time a new task to
// schedule needs to be found. In theory, either round-robin'ing or
// shuffling will avoid prioritizing one specific stealers work
// ahead of all others.
// Shuffle list of stealer IDs each time a new task to schedule
// needs to be found. Randomizing the order should avoid
// prioritizing one specific stealer's work ahead of all others.
List<Integer> stealerIds = new ArrayList<Integer>(tasksByStealer.keySet());
Collections.shuffle(stealerIds);
for(int stealerId: stealerIds) {
Expand Down

0 comments on commit d7356df

Please sign in to comment.