From 16fa150182699db74d40b48178bd4cdc4ad0bdf0 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 11 Sep 2025 17:11:56 +0200 Subject: [PATCH] scheduler_perf: run garbage collection before measurement The startup phase may have allocated memory that can be garbage-collected. Forcing GC to run before measurements avoids noise if the garbage collection kicks in during the measurement and potentially reduces the heap size reported by metrics. The exact effect has not been measured, it just seems useful. --- test/integration/scheduler_perf/scheduler_perf.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/integration/scheduler_perf/scheduler_perf.go b/test/integration/scheduler_perf/scheduler_perf.go index 321acfada02..4eb5bed9e19 100644 --- a/test/integration/scheduler_perf/scheduler_perf.go +++ b/test/integration/scheduler_perf/scheduler_perf.go @@ -29,6 +29,7 @@ import ( "os" "path" "regexp" + "runtime" "slices" "strings" "sync" @@ -42,7 +43,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/version" "k8s.io/apimachinery/pkg/util/wait" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -130,7 +131,7 @@ type FeatureGateFlag interface { func init() { f := featuregate.NewFeatureGate() - runtime.Must(logsapi.AddFeatureGates(f)) + utilruntime.Must(logsapi.AddFeatureGates(f)) LoggingFeatureGate = f LoggingConfig = logsapi.NewLoggingConfiguration() @@ -1457,6 +1458,10 @@ func checkEmptyInFlightEvents() error { func startCollectingMetrics(tCtx ktesting.TContext, collectorWG *sync.WaitGroup, podInformer coreinformers.PodInformer, mcc *metricsCollectorConfig, throughputErrorMargin float64, opIndex int, name string, namespaces []string, labelSelector map[string]string) (ktesting.TContext, []testDataCollector, error) { collectorCtx := ktesting.WithCancel(tCtx) workloadName := tCtx.Name() + + // Clean up memory usage from the initial setup phase. + runtime.GC() + // The first part is the same for each workload, therefore we can strip it. workloadName = workloadName[strings.Index(name, "/")+1:] collectors := getTestDataCollectors(podInformer, fmt.Sprintf("%s/%s", workloadName, name), namespaces, labelSelector, mcc, throughputErrorMargin)