-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Weighted work balancer: dynamic consumer weights adjustment (#1559)
* Weighted work balancer: scoring consumer nodes * don't use null as a special value of timestamp
- Loading branch information
1 parent
621f8b2
commit 7cd3b37
Showing
34 changed files
with
1,115 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...allegro/tech/hermes/consumers/supervisor/workload/weighted/AvgTargetWeightCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package pl.allegro.tech.hermes.consumers.supervisor.workload.weighted; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
public class AvgTargetWeightCalculator implements TargetWeightCalculator { | ||
|
||
private final WeightedWorkloadMetrics metrics; | ||
|
||
public AvgTargetWeightCalculator(WeightedWorkloadMetrics metrics) { | ||
this.metrics = metrics; | ||
} | ||
|
||
@Override | ||
public Map<String, Weight> calculate(Collection<ConsumerNode> consumers) { | ||
if (consumers.isEmpty()) { | ||
return Map.of(); | ||
} | ||
|
||
metrics.reportCurrentWeights(consumers); | ||
Weight sum = consumers.stream() | ||
.map(ConsumerNode::getWeight) | ||
.reduce(Weight.ZERO, Weight::add); | ||
Weight average = sum.divide(consumers.size()); | ||
|
||
Map<String, Weight> newWeights = consumers.stream() | ||
.collect(toMap(ConsumerNode::getConsumerId, ignore -> average)); | ||
metrics.reportProposedWeights(newWeights); | ||
return newWeights; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.