Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions test/e2e/performanceprofile/functests/4_latency/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
defaultTestRuntime = "300"
defaultMaxLatency = -1
defaultTestCpus = -1
defaultTestMemory = "1Gi"
dynamicMemory = "dynamic"
minCpuAmountForOslat = 2
)

Expand All @@ -51,13 +53,14 @@ var (
latencyTestRuntime = defaultTestRuntime
maximumLatency = defaultMaxLatency
latencyTestCpus = defaultTestCpus
latencyTestMemory = defaultTestMemory
)

// LATENCY_TEST_DELAY delay the run of the binary, can be useful to give time to the CPU manager reconcile loop
// to update the default CPU pool
// LATENCY_TEST_RUNTIME: the amount of time in seconds that the latency test should run
// LATENCY_TEST_CPUS: the amount of CPUs the pod which run the latency test should request

// LATENCY_TEST_MEMORY: the amount of memory the pod which run the latency test should request
var _ = Describe("[performance] Latency Test", Ordered, func() {
var workerRTNode *corev1.Node
var profile *performancev2.PerformanceProfile
Expand Down Expand Up @@ -278,6 +281,29 @@ func getLatencyTestCpus() (int, error) {
return defaultTestCpus, nil
}

func getLatencyTestMemory(cpus int) (string, error) {
if val, ok := os.LookupEnv("LATENCY_TEST_MEMORY"); ok {
if val == dynamicMemory {
// Defensive check: fall back to default memory if the cpus was not normalized
if cpus == defaultTestCpus {
return defaultTestMemory, nil
}
Comment thread
shajmakh marked this conversation as resolved.
// 32Mi per requested CPU should be reasonable for the test; if needed more, it can
Comment thread
shajmakh marked this conversation as resolved.
// be overridden by explicitly setting the environment variable
memoryFactor := 32
memory := memoryFactor * cpus
return fmt.Sprintf("%dMi", memory), nil
}

_, err := resource.ParseQuantity(val)
if err != nil {
return val, fmt.Errorf("the environment variable LATENCY_TEST_MEMORY has incorrect value %q, it must be a valid quantity: %w", val, err)
}
return val, nil
}
return defaultTestMemory, nil
}

// getMaximumLatency should look for one of the following environment variables:
// OSLAT_MAXIMUM_LATENCY: the expected maximum latency for all buckets in us
// CYCLICTEST_MAXIMUM_LATENCY: the expected maximum latency for all buckets in us
Expand Down Expand Up @@ -325,6 +351,10 @@ func getLatencyTestPod(profile *performancev2.PerformanceProfile, node *corev1.N
latencyTestCpus = cpus.Size() - 1
}

var err error
latencyTestMemory, err = getLatencyTestMemory(latencyTestCpus)
Expect(err).ToNot(HaveOccurred())

latencyTestRunnerArgs := []string{
"-logtostderr=false",
"-alsologtostderr=true",
Expand Down Expand Up @@ -361,7 +391,7 @@ func getLatencyTestPod(profile *performancev2.PerformanceProfile, node *corev1.N
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(strconv.Itoa(latencyTestCpus)),
corev1.ResourceMemory: resource.MustParse("1Gi"),
corev1.ResourceMemory: resource.MustParse(latencyTestMemory),
},
},
SecurityContext: &corev1.SecurityContext{
Expand Down