← Back to Pull requests

perf: introduce stopChurn opcode in scheduler_perf framework #139441

Closed
GFilipek closed this pull request without merging on Oct 12, 2026 07:28 UTC
View on GitHub
GFilipek GFilipek commented on Jun 02, 2026 12:10 UTC
Author

<!-- Thanks for sending a pull request! Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide/first-contribution.md#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/sig-testing/testing.md
4. If you want faster PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
5. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR introduces a new stopChurn opcode to the scheduler_perf integration testing framework with support for tracking and stopping multiple concurrent churn generators.

Currently, the churn opcode starts a background churn generator (creating/deleting pods) that runs for the entire remaining lifetime of the workload run. There is no mechanism to stop a background churn loop in the middle of a workload template sequence, nor is there support for managing multiple concurrent/overlapping churn generators without resource leaks.

To resolve this, this PR:
1. Adds an optional Name field to both the churn and stopChurn opcodes.
2. Updates WorkloadExecutor to track background churn cancellation functions in a map (churnCancels) indexed by their name.
3. Implements named and multi-cancellation logic in runStopChurnOp:
- Named Cancellation: If a Name is specified, it cancels and cleans up only that specific background churn generator.
- Bulk Cancellation: If no Name is specified, it cancels and cleans up all currently active background churn generators.
4. Includes comprehensive unit tests (TestStopChurnOpCancellation) verifying correct cancellation and map state tracking for both scenarios.

Which issue(s) this PR is related to:

N/A

Special notes for your reviewer:

This is a prerequisite framework change needed for subsequent scheduler performance/starvation benchmark tests that utilize the stopChurn opcode. The starvation performance tests themselves are introduced in #139421.

Does this PR introduce a user-facing change?

``release-note
NONE


#### Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

docs
NONE
``

Diff: 225 lines (+221 / -4) across 4 files Reviewer: iomarsayed Review duration: 189797m
All Vouch review confidence checks passed
Residual risk 0.07 = Change Risk (0.40) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 225 lines diff across 4 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.70 · 5 substantive comment(s)
0.70
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.324
Real PR Conversation Timeline
28 items
k8s-ci-robot k8s-ci-robot commented on Jun 02, 2026 12:10 UTC
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

<details>

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
</details>

k8s-ci-robot k8s-ci-robot commented on Jun 02, 2026 12:10 UTC
Contributor

Hi @GFilipek. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

>[!TIP]
>We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

<details>

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
</details>

GFilipek GFilipek commented on Jun 02, 2026 12:29 UTC
Author

/assign iomarsayed

iomarsayed iomarsayed commented on Jun 02, 2026 13:03 UTC
Contributor

/ok-to-test

iomarsayed iomarsayed commented on code on Jun 03, 2026 02:12 UTC
Code Review
test/integration/scheduler_perf/executor.go:1
@@ -448,6 +465,27 @@ func (e *WorkloadExecutor) runChurnOp(tCtx ktesting.TContext, opIndex int, op *c
 	return nil
 }
 
+func (e *WorkloadExecutor) runStopChurnOp(tCtx ktesting.TContext, op *stopChurnOp) error {
+	if len(e.churnCancels) == 0 {
+		return nil
+	}
+	if op.Name != "" {
+		if cancel, ok := e.churnCancels[op.Name]; ok {
+			tCtx.Logf("Stopping background churn generator: %q", op.Name)
+			cancel()
+			delete(e.churnCancels, op.Name)
+		}
+		return nil

What if a test author specifies a non-empty name in stopChurn, but no active churn exists with that name? I think this case silently fails and returns nil. Is that expected?
Wouldn't it be probably better to fail the test, telling the author about that?

iomarsayed iomarsayed commented on code on Jun 03, 2026 02:24 UTC
Code Review
test/integration/scheduler_perf/operations.go:1
@@ -885,3 +887,22 @@ func divideFloat(i, j any) float64 {
 func mod(a, b any) int {
 	return int(toFloat64(a)) % int(toFloat64(b))
 }
+
+// stopChurnOp defines an op that cancels any running background churn operation.
+type stopChurnOp struct {
+	Opcode operationCode
+	// Name of the churn operation to stop. Optional.

Maybe?

	// Name of the churn operation to stop. Optional.
	// If empty, stopChurnOp stops all background churns.

iomarsayed iomarsayed commented on Jun 03, 2026 03:07 UTC
Reviewer

I have only a couple of comments.

GFilipek GFilipek commented on code on Jun 03, 2026 11:04 UTC
Code Review
test/integration/scheduler_perf/operations.go:1
@@ -885,3 +887,22 @@ func divideFloat(i, j any) float64 {
 func mod(a, b any) int {
 	return int(toFloat64(a)) % int(toFloat64(b))
 }
+
+// stopChurnOp defines an op that cancels any running background churn operation.
+type stopChurnOp struct {
+	Opcode operationCode
+	// Name of the churn operation to stop. Optional.

done.

GFilipek GFilipek commented on code on Jun 03, 2026 11:05 UTC
Code Review
test/integration/scheduler_perf/executor.go:1
@@ -448,6 +465,27 @@ func (e *WorkloadExecutor) runChurnOp(tCtx ktesting.TContext, opIndex int, op *c
 	return nil
 }
 
+func (e *WorkloadExecutor) runStopChurnOp(tCtx ktesting.TContext, op *stopChurnOp) error {
+	if len(e.churnCancels) == 0 {
+		return nil
+	}
+	if op.Name != "" {
+		if cancel, ok := e.churnCancels[op.Name]; ok {
+			tCtx.Logf("Stopping background churn generator: %q", op.Name)
+			cancel()
+			delete(e.churnCancels, op.Name)
+		}
+		return nil

done.

iomarsayed iomarsayed commented on Jun 03, 2026 11:31 UTC
Contributor

/lgtm

k8s-ci-robot k8s-ci-robot commented on Jun 03, 2026 11:31 UTC
Contributor

LGTM label has been added. <details>Git tree hash: 37ab6efd730ee4413444bbd9135432cc9127622d</details>

GFilipek GFilipek commented on Jun 03, 2026 11:46 UTC
Author

/assign dom4ha

utam0k utam0k commented on Jun 03, 2026 12:05 UTC
Contributor

The code itself looks generally good, but is there an issue or similar where the introduction of this opcode is being discussed?

GFilipek GFilipek commented on Jun 03, 2026 12:21 UTC
Author

The code itself looks generally good, but is there an issue or similar where the introduction of this opcode is being discussed?

This is related to gang scheduling testing and reproducing the problem described in #138249 We need this op to reproduce high churn scenario with unschedulable pods - working on it in #139421
These tests aim to 1. show that podgroups are less likely to starve scheduler queue and 2. verify if we do not have any regressions in scheduling both individual pods and podgoups in high churn scenarios that would cause this problem manifesting more often

macsko macsko commented on Jun 05, 2026 07:05 UTC
Contributor

> The code itself looks generally good, but is there an issue or similar where the introduction of this opcode is being discussed?

> This is related to gang scheduling testing and reproducing the problem described in #138249 We need this op to reproduce high churn scenario with unschedulable pods - working on it in #139421 These tests aim to 1. show that podgroups are less likely to starve scheduler queue and 2. verify if we do not have any regressions in scheduling both individual pods and podgoups in high churn scenarios that would cause this problem manifesting more often

Is it a good example? In those tests, the stopChurn is executed at the end of the test case. How does the stopChurn operation help there?

GFilipek GFilipek commented on Jun 05, 2026 08:47 UTC
Author

Is it a good example? In those tests, the stopChurn is executed at the end of the test case. How does the stopChurn operation help there?

Without the stop churn, test may fail on check if there are inflight events in the queue here - unchedulable pods are still processed while the measured pods are done and test wants to exit.

macsko macsko commented on Jun 05, 2026 08:54 UTC
Contributor

> Is it a good example? In those tests, the stopChurn is executed at the end of the test case. How does the stopChurn operation help there?

> Without the stop churn, test may fail on check if there are inflight events in the queue here - unchedulable pods are still processed while the measured pods are done and test wants to exit.

So, shouldn't the churn operation be auto-stopped on the test teardown instead?

k8s-ci-robot k8s-ci-robot commented on Jun 08, 2026 08:10 UTC
Contributor

New changes are detected. LGTM label has been removed.

k8s-ci-robot k8s-ci-robot commented on Jun 08, 2026 08:11 UTC
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: <a href="https://github.com/kubernetes/kubernetes/pull/139441#" title="Author self-approved">GFilipek</a>
Once this PR has been reviewed and has the lgtm label, please ask for approval from dom4ha. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

<details open>
Needs approval from an approver in each of these files:

  • test/integration/scheduler_perf/OWNERS
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":["dom4ha"]} -->

    GFilipek GFilipek commented on Jun 08, 2026 08:13 UTC
    Author

    So, shouldn't the churn operation be auto-stopped on the test teardown instead?

    Yes, for now this would be sufficient. I've split the PR into 2 commits - stopping churn and adding new opcode - I can revert the second one if you think stop opcode is not useful.

    GFilipek GFilipek commented on Jun 08, 2026 08:48 UTC
    Author

    /test pull-kubernetes-e2e-gce

    GFilipek GFilipek commented on Jun 08, 2026 08:48 UTC
    Author

    /test pull-kubernetes-node-e2e-containerd

    macsko macsko commented on Jun 08, 2026 10:53 UTC
    Contributor

    > So, shouldn't the churn operation be auto-stopped on the test teardown instead?

    > Yes, for now this would be sufficient. I've split the PR into 2 commits - stopping churn and adding new opcode - I can revert the second one if you think stop opcode is not useful.

    If you see any immediate use case for stopChurn op, I'm okay to merge it. If you think it will be useful in the future, but won't be needed soon, let's add it later.

    dom4ha dom4ha commented on code on Jun 09, 2026 09:11 UTC
    Code Review
    test/integration/scheduler_perf/scheduler_perf.go:1
    @@ -1135,6 +1135,9 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *Workload, topicName st
     		return nil, fmt.Errorf("the parameters %v are defined on workload %s, but unused.\nPlease make sure there are no typos", unusedParams, w.Name)
     	}
     
    +	// Stopping all churn generators to avoid adding inflight events after the workload is done.
    +	executor.stopAllBackgroundChurns(tCtx)

    Shouldn't we use defer to cover all exit scenarios?

    Once we do that, don't we need to add mutex around churnCancels?

    dom4ha dom4ha commented on Jun 09, 2026 09:15 UTC
    Reviewer

    +1 to @macsko, let's skip the new op if it's not needed now.

    GFilipek GFilipek commented on Jun 09, 2026 11:12 UTC
    Author

    I will park this PR for now, the background churn is already properly closed by context cancelation here on workflow exit so no need to add separate context if we do not want to cancel them on demand.
    The errors I was seeing were probably artifacts of bad scheduler cancelation which was fixed in #139323

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Jun 25, 2026 06:19 UTC
    Bot

    PR needs rebase.

    <details>

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
    </details>

    Reviewers
    Assignees
    GFilipek GFilipek
    Labels
    risk: low confidence: 83.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.2% · Lower = rushed or shallow review
    83.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.7% · Safe to merge
    6.7%