Skip to content

Commit 9a450a1

Browse files
committed
feat: added consumedCounters into pool util calculation
Signed-off-by: MenD32 <[email protected]>
1 parent 9dc8e0f commit 9a450a1

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

cluster-autoscaler/simulator/dynamicresources/utils/utilization.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,29 @@ func calculatePoolUtil(unallocated, allocated []resourceapi.Device) float64 {
7474
TotalConsumedCounters := calculateConsumedCounters(append(allocated, unallocated...))
7575
allocatedConsumedCounters := calculateConsumedCounters(allocated)
7676

77-
// we want to find the counter that is most utilized, since it is the "bottleneck"
78-
maxUtilization := 0.0
77+
// not all devices are partitionable, so fallback to the ratio of non-partionable devices
78+
allocatedDevicesWithoutCounters := 0
79+
devicesWithoutCounters := 0
80+
81+
for _, device := range allocated {
82+
if device.Basic.ConsumesCounters == nil {
83+
devicesWithoutCounters++
84+
allocatedDevicesWithoutCounters++
85+
}
86+
}
87+
for _, device := range unallocated {
88+
if device.Basic.ConsumesCounters == nil {
89+
devicesWithoutCounters++
90+
}
91+
}
92+
93+
// we want to find the counter that is most utilized, since it is the "bottleneck" of the pool
94+
maxUtilization := float64(allocatedDevicesWithoutCounters) / (float64(allocatedDevicesWithoutCounters) + float64(devicesWithoutCounters))
7995
for counterSet, counters := range TotalConsumedCounters {
8096
for counterName, totalValue := range counters {
8197
if allocatedSet, exists := allocatedConsumedCounters[counterSet]; exists {
8298
if allocatedValue, exists := allocatedSet[counterName]; exists && !totalValue.IsZero() {
83-
utilization := float64(allocatedValue.MilliValue()) / float64(totalValue.MilliValue())
99+
utilization := float64(allocatedValue.Value()) / float64(totalValue.Value())
84100
if utilization > maxUtilization {
85101
maxUtilization = utilization
86102
}
@@ -95,6 +111,9 @@ func calculatePoolUtil(unallocated, allocated []resourceapi.Device) float64 {
95111
func calculateConsumedCounters(devices []resourceapi.Device) map[string]map[string]resource.Quantity {
96112
countersConsumed := map[string]map[string]resource.Quantity{}
97113
for _, device := range devices {
114+
if device.Basic.ConsumesCounters == nil {
115+
continue
116+
}
98117
for _, consumedCounter := range device.Basic.ConsumesCounters {
99118
if _, ok := countersConsumed[consumedCounter.CounterSet]; !ok {
100119
countersConsumed[consumedCounter.CounterSet] = map[string]resource.Quantity{}
@@ -110,7 +129,6 @@ func calculateConsumedCounters(devices []resourceapi.Device) map[string]map[stri
110129
}
111130
}
112131
return countersConsumed
113-
114132
}
115133

116134
func splitDevicesByAllocation(devices []resourceapi.Device, allocatedNames []string) (unallocated, allocated []resourceapi.Device) {

0 commit comments

Comments
 (0)