Skip to content

Commit

Permalink
Reduce memory step size to 32Mi
Browse files Browse the repository at this point in the history
This allows scaling down to 256Mi total reconciler Pod memory, not
just 512Mi. However, on non-bursting autopilot clusters, the
minimum is still 512Mi.
  • Loading branch information
karlkfi committed Apr 18, 2024
1 parent 49cc302 commit 7c937ca
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 30 deletions.
8 changes: 7 additions & 1 deletion e2e/testcases/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func TestStressManyRootSyncs(t *testing.T) {
nt.T.Logf("Adding test namespace: %s", ns)
nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns), fake.NamespaceObject(ns)))

syncCount := 20
syncCount := 5
deployCount := 200

for i := 1; i <= syncCount; i++ {
Expand All @@ -443,6 +443,12 @@ func TestStressManyRootSyncs(t *testing.T) {
syncPath := syncName
syncObj := nomostest.RootSyncObjectV1Beta1FromOtherRootRepo(nt, syncName, configsync.RootSyncName)
syncObj.Spec.Git.Dir = syncPath
syncObj.Spec.SafeOverride().LogLevels = []v1beta1.ContainerLogLevelOverride{
{
ContainerName: "reconciler",
LogLevel: 3,
},
}
// Manage the RootSyncs with the parent root-sync
nt.Must(nt.RootRepos[configsync.RootSyncName].Add(
fmt.Sprintf("%s/namespaces/%s/rootsync-%s.yaml", gitproviders.DefaultSyncDir, configsync.ControllerNamespace, syncName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func ReconcilerContainerResourceDefaultsForAutopilot() map[string]v1beta1.Contai
return map[string]v1beta1.ContainerResourcesSpec{
reconcilermanager.Reconciler: {
ContainerName: reconcilermanager.Reconciler,
CPURequest: resource.MustParse("250m"),
CPULimit: resource.MustParse("250m"),
MemoryRequest: resource.MustParse("256Mi"),
MemoryLimit: resource.MustParse("256Mi"),
CPURequest: resource.MustParse("125m"),
CPULimit: resource.MustParse("125m"),
MemoryRequest: resource.MustParse("128Mi"),
MemoryLimit: resource.MustParse("128Mi"),
},
reconcilermanager.HydrationController: {
ContainerName: reconcilermanager.HydrationController,
Expand Down
11 changes: 6 additions & 5 deletions pkg/reconcilermanager/controllers/reposync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,14 +1202,15 @@ func (r *RepoSyncReconciler) mutationsFor(ctx context.Context, rs *v1beta1.RepoS
}

memoryMinimum := float64(128)
memoryStepSize := float64(128)
memoryStepSize := float64(32)
memoryUsage := float64(objectCount)/10 + memoryMinimum
memoryLimit := math.Floor(memoryUsage/memoryStepSize)*memoryStepSize + memoryStepSize
memoryQuantity := resource.NewQuantity(int64(memoryLimit*bytes.MiB), resource.BinarySI)
memoryLimit := math.Max(math.Ceil(memoryUsage/memoryStepSize)*memoryStepSize, memoryMinimum)
memoryQuantity := resource.NewQuantity(int64(memoryLimit*float64(bytes.MiB)), resource.BinarySI)
klog.V(3).Infof("%s reconciler container memory: %s - %s", r.syncKind, memoryQuantity, memoryQuantity)

cpuStepSize := float64(125)
cpuLimit := math.Floor(memoryLimit/memoryStepSize) * cpuStepSize
cpuMinimum := float64(125)
cpuRatio := float64(bytes.KB) / float64(bytes.KiB)
cpuLimit := math.Max(math.Ceil(memoryLimit*cpuRatio), cpuMinimum)
cpuQuantity := resource.NewMilliQuantity(int64(cpuLimit), resource.DecimalSI)
klog.V(3).Infof("%s reconciler container cpu: %s - %s", r.syncKind, cpuQuantity, cpuQuantity)

Expand Down
11 changes: 6 additions & 5 deletions pkg/reconcilermanager/controllers/rootsync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1259,14 +1259,15 @@ func (r *RootSyncReconciler) mutationsFor(ctx context.Context, rs *v1beta1.RootS
}

memoryMinimum := float64(128)
memoryStepSize := float64(128)
memoryStepSize := float64(32)
memoryUsage := float64(objectCount)/10 + memoryMinimum
memoryLimit := math.Floor(memoryUsage/memoryStepSize)*memoryStepSize + memoryStepSize
memoryQuantity := resource.NewQuantity(int64(memoryLimit*bytes.MiB), resource.BinarySI)
memoryLimit := math.Max(math.Ceil(memoryUsage/memoryStepSize)*memoryStepSize, memoryMinimum)
memoryQuantity := resource.NewQuantity(int64(memoryLimit*float64(bytes.MiB)), resource.BinarySI)
klog.V(3).Infof("%s reconciler container memory: %s - %s", r.syncKind, memoryQuantity, memoryQuantity)

cpuStepSize := float64(125)
cpuLimit := math.Floor(memoryLimit/memoryStepSize) * cpuStepSize
cpuMinimum := float64(125)
cpuRatio := float64(bytes.KB) / float64(bytes.KiB)
cpuLimit := math.Max(math.Ceil(memoryLimit*cpuRatio), cpuMinimum)
cpuQuantity := resource.NewMilliQuantity(int64(cpuLimit), resource.DecimalSI)
klog.V(3).Infof("%s reconciler container cpu: %s - %s", r.syncKind, cpuQuantity, cpuQuantity)

Expand Down
40 changes: 25 additions & 15 deletions pkg/util/bytes/bytes.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package bytes

const (
BYTE = 1 << (10 * iota)
KB
MB
GB
TB
PB
EB
)
type Bit int

type Byte int

const (
KiB = 1024
MiB = 1024 * KiB
GiB = 1024 * MiB
TiB = 1024 * GiB
PiB = 1024 * TiB
EiB = 1024 * PiB
ByteSize Bit = 8

Kb Bit = 1000 // Kilobit
Mb Bit = 1000 * Kb // Megabit
Gb Bit = 1000 * Mb // Gigabit
Tb Bit = 1000 * Gb // Terabit
Pb Bit = 1000 * Tb // Petabit
Eb Bit = 1000 * Pb // Exabit

KB Byte = 1000 // Kilobyte
MB Byte = 1000 * KB // Megabyte
GB Byte = 1000 * MB // Gigabyte
TB Byte = 1000 * GB // Terabyte
PB Byte = 1000 * TB // Petabyte
EB Byte = 1000 * PB // Exabyte

KiB Byte = 1024 // Kibibyte
MiB Byte = 1024 * KiB // Mebibyte
GiB Byte = 1024 * MiB // Gibibyte
TiB Byte = 1024 * GiB // Tebibyte
PiB Byte = 1024 * TiB // Pebibyte
EiB Byte = 1024 * PiB // Exbibyte
)

0 comments on commit 7c937ca

Please sign in to comment.