5757 * Scores run from 0 (idle) upwards and lower is better. Hosts are then chosen from among the best
5858 * rather than strictly in order - see {@link #applySelectionSpread}.
5959 */
60- public class WeightedHostScorer extends AdapterBase implements Configurable {
60+ public class WeightedHostScorer extends AdapterBase implements Configurable , HostScoringWeights {
6161
62- private static final String WEIGHT_DESCRIPTION_SUFFIX =
62+ private static final String ALLOCATOR_WEIGHT_DESCRIPTION_SUFFIX =
6363 " Relative weight, only meaningful compared with the other host.weighted.* weights. Zero disables the term." ;
6464
6565 public static final ConfigKey <Double > VmCountWeight = new ConfigKey <>(ConfigKey .CATEGORY_ADVANCED ,
6666 Double .class , "host.weighted.vm.count.weight" , "1.0" ,
6767 "How much the number of VMs already on a host counts against it, regardless of how busy they are."
68- + WEIGHT_DESCRIPTION_SUFFIX ,
68+ + ALLOCATOR_WEIGHT_DESCRIPTION_SUFFIX ,
6969 true , ConfigKey .Scope .Cluster );
7070
7171 public static final ConfigKey <Double > RecentStartWeight = new ConfigKey <>(ConfigKey .CATEGORY_ADVANCED ,
7272 Double .class , "host.weighted.recent.start.weight" , "2.0" ,
7373 "How much VMs started recently on a host count against it. Guards against sending a burst of new "
7474 + "VMs to one host, since neither allocation nor utilisation has caught up with them yet."
75- + WEIGHT_DESCRIPTION_SUFFIX ,
75+ + ALLOCATOR_WEIGHT_DESCRIPTION_SUFFIX ,
7676 true , ConfigKey .Scope .Cluster );
7777
7878 public static final ConfigKey <Double > DominantResourceWeight = new ConfigKey <>(ConfigKey .CATEGORY_ADVANCED ,
7979 Double .class , "host.weighted.dominant.resource.weight" , "1.0" ,
8080 "How much a host's single most stressed resource counts against it, on top of the average across "
8181 + "resources. Keeps a host that is fine on average but nearly out of one resource from ranking well."
82- + WEIGHT_DESCRIPTION_SUFFIX ,
82+ + ALLOCATOR_WEIGHT_DESCRIPTION_SUFFIX ,
8383 true , ConfigKey .Scope .Cluster );
8484
8585 public static final ConfigKey <Integer > RecentStartWindow = new ConfigKey <>(ConfigKey .CATEGORY_ADVANCED ,
@@ -436,7 +436,9 @@ protected void applySelectionSpread(Long clusterId, List<Host> ranked) {
436436 }
437437
438438 /**
439- * The weights for one ranking, read once rather than per host.
439+ * The weights for one ranking, read once rather than per host. Every host in a ranking is then
440+ * scored with the same values even if a setting changes part way through, and a bad value is
441+ * reported once per ranking rather than once per host.
440442 *
441443 * A negative weight would invert the ranking and make the most loaded host the best, so they
442444 * are floored at zero and the bad value is reported.
@@ -452,10 +454,10 @@ protected final class Weights {
452454 private final double vmScale ;
453455
454456 protected Weights (Long clusterId ) {
455- cpuAllocated = nonNegative (HostScoringWeights . CpuAllocatedWeight , clusterId );
456- cpuUsed = nonNegative (HostScoringWeights . CpuUsedWeight , clusterId );
457- memoryAllocated = nonNegative (HostScoringWeights . MemoryAllocatedWeight , clusterId );
458- memoryUsed = nonNegative (HostScoringWeights . MemoryUsedWeight , clusterId );
457+ cpuAllocated = nonNegative (CpuAllocatedWeight , clusterId );
458+ cpuUsed = nonNegative (CpuUsedWeight , clusterId );
459+ memoryAllocated = nonNegative (MemoryAllocatedWeight , clusterId );
460+ memoryUsed = nonNegative (MemoryUsedWeight , clusterId );
459461 vmCount = nonNegative (VmCountWeight , clusterId );
460462 recentStart = nonNegative (RecentStartWeight , clusterId );
461463 dominant = nonNegative (DominantResourceWeight , clusterId );
@@ -493,10 +495,10 @@ public String getConfigComponentName() {
493495 @ Override
494496 public ConfigKey <?>[] getConfigKeys () {
495497 return new ConfigKey <?>[] {
496- HostScoringWeights . CpuAllocatedWeight ,
497- HostScoringWeights . CpuUsedWeight ,
498- HostScoringWeights . MemoryAllocatedWeight ,
499- HostScoringWeights . MemoryUsedWeight ,
498+ CpuAllocatedWeight ,
499+ CpuUsedWeight ,
500+ MemoryAllocatedWeight ,
501+ MemoryUsedWeight ,
500502 VmCountWeight ,
501503 RecentStartWeight ,
502504 DominantResourceWeight ,
0 commit comments