Skip to content

Commit 869e388

Browse files
committed
feat: improve memory request and limit calculations with rounding to nearest power of 2
1 parent 1d4315f commit 869e388

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/utilization/queries.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ func WorkloadResourceRecommendations(ctx context.Context, env string, teamSlug s
317317

318318
return &WorkloadUtilizationRecommendations{
319319
CPURequestCores: math.Max(cpuReq, minCPURequest),
320-
MemoryRequestBytes: int64(math.Ceil(math.Max(memReq, minMemoryRequestBytes))),
321-
MemoryLimitBytes: int64(math.Ceil(math.Max(memLimit, minMemoryRequestBytes))),
320+
MemoryRequestBytes: int64(math.Max(roundUpToPowerOf2(memReq), minMemoryRequestBytes)),
321+
MemoryLimitBytes: int64(math.Max(roundUpToPowerOf2(memLimit), minMemoryRequestBytes)),
322322
}, nil
323323
}
324324

@@ -353,3 +353,10 @@ func ensuredVal(v prom.Vector) float64 {
353353

354354
return float64(v[0].Value)
355355
}
356+
357+
func roundUpToPowerOf2(x float64) float64 {
358+
if x <= 0 {
359+
return 0
360+
}
361+
return math.Pow(2, math.Ceil(math.Log2(x)))
362+
}

0 commit comments

Comments
 (0)