Skip to content

Commit 4a81787

Browse files
committed
refactor: adjust memory request calculation to use 32 MiB rounding
1 parent 869e388 commit 4a81787

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

internal/utilization/queries.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const (
5858
)`
5959

6060
minCPURequest = 0.01 // 10m
61-
minMemoryRequestBytes = 64 * 1024 * 1024 // 64 MiB
61+
minMemoryRequestBytes = 32 * 1024 * 1024 // 64 MiB
6262
)
6363

6464
var (
@@ -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.Max(roundUpToPowerOf2(memReq), minMemoryRequestBytes)),
321-
MemoryLimitBytes: int64(math.Max(roundUpToPowerOf2(memLimit), minMemoryRequestBytes)),
320+
MemoryRequestBytes: int64(math.Max(roundUpToNearest32MiB(memReq), minMemoryRequestBytes)),
321+
MemoryLimitBytes: int64(math.Max(roundUpToNearest32MiB(memLimit), minMemoryRequestBytes)),
322322
}, nil
323323
}
324324

@@ -354,9 +354,7 @@ func ensuredVal(v prom.Vector) float64 {
354354
return float64(v[0].Value)
355355
}
356356

357-
func roundUpToPowerOf2(x float64) float64 {
358-
if x <= 0 {
359-
return 0
360-
}
361-
return math.Pow(2, math.Ceil(math.Log2(x)))
357+
func roundUpToNearest32MiB(bytes float64) float64 {
358+
const chunk float64 = 32 * 1024 * 1024 // 32 MiB in bytes
359+
return math.Ceil(bytes/chunk) * chunk
362360
}

0 commit comments

Comments
 (0)