Skip to content

enhancement(victim selection): improve same job-priority victim selection#5113

Open
hajnalmt wants to merge 3 commits intovolcano-sh:masterfrom
hajnalmt:fix/buildvictimspriorityqueue-task-ordering
Open

enhancement(victim selection): improve same job-priority victim selection#5113
hajnalmt wants to merge 3 commits intovolcano-sh:masterfrom
hajnalmt:fix/buildvictimspriorityqueue-task-ordering

Conversation

@hajnalmt
Copy link
Contributor

@hajnalmt hajnalmt commented Mar 16, 2026

What type of PR is this?

/kind rfe
/kind feature

What this PR does / why we need it:

This PR improves same job-priority victim selection in BuildVictimsPriorityQueue by applying plugin job compare first and using TaskOrderFn as tie-break when job ordering is equal.
The behavior is applied in both the preemptor-missing path and the same-queue path so creation timestamp is not the implicit final decision maker.

Which issue(s) this PR fixes:

Fixes #5112

Special notes for your reviewer:

  • Key logic change is in pkg/scheduler/framework/session_plugins.go.
  • Focused unit coverage is in pkg/scheduler/framework/session_plugins_victim_order_test.go.
  • The unit test is intentionally in framework_test package to avoid import cycle with real plugin wiring.
  • The victim selection process was quite controversial for these tie-break scenarios as:
    return lv.CreationTimestamp.Before(&rv.CreationTimestamp) means return true when lv is older than rv, so if two jobs have the same priority the order is asceding by timestamp, for the jobOrder resulting in oldest first job ordering. For the victims we have negated this via !ssn.JobOrderFn(...) resulting in youngest first victim selection, so we evicted younger jobs on the cluster instead of the older jobs in the reclaim and preempt actions.
  • AI usage disclosure: A little AI assistance was used in the creation of this PR, but the author thoroughly guided the implementation process and rewrote a good chunk of the generated parts.
  • AI rhyme:
    In volcano’s queue where victims flow,
    when job ranks tie, task rules shall show;
    no timestamp shall decide the fight,
    task-order keeps the choice set right.

Does this PR introduce a user-facing change?

Improve scheduler victim selection tie-break behavior for same job-priority scenarios by using task-order when job-order ties in BuildVictimsPriorityQueue.

…rder

Apply plugin job CompareFn first in BuildVictimsPriorityQueue and use
TaskOrderFn as the tie-breaker when job ordering is equal, including
preemptor-missing paths, so creation timestamp does not dominate
same-priority victim selection.

Signed-off-by: Hajnal Máté <hajnalmt@gmail.com>
Add BuildVictimsPriorityQueue unit coverage for job-order ties falling back
to task-order, including preemptor-found and preemptor-missing paths.

Place the test in package framework_test so it can use real plugin wiring
without creating an import cycle between framework and plugin packages.

Signed-off-by: Hajnal Máté <hajnalmt@gmail.com>
Copilot AI review requested due to automatic review settings March 16, 2026 15:34
@volcano-sh-bot volcano-sh-bot added kind/RFE Categorizes issue or PR as related to design. kind/feature Categorizes issue or PR as related to a new feature. labels Mar 16, 2026
@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign monokaix for approval. For more information see the Kubernetes Code Review Process.

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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 16, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the victim selection mechanism within the scheduler's BuildVictimsPriorityQueue. By introducing a dedicated JobOrderCompareFn and a new tie-breaking logic that prioritizes plugin-defined job comparison and then task ordering, it ensures a more deterministic and robust selection process. This change addresses scenarios where jobs have the same priority, preventing reliance on implicit factors like creation timestamps and leading to more predictable preemption decisions.

Highlights

  • Refactored Job Ordering Logic: Introduced JobOrderCompareFn to centralize plugin-based job comparison, returning an integer for clearer ordering, and updated JobOrderFn to utilize this new comparison function.
  • Enhanced Victim Selection Tie-breaking: Modified BuildVictimsPriorityQueue to use JobOrderCompareFn first, and then TaskOrderFn as a tie-breaker when job ordering is equal, ensuring a more deterministic selection.
  • Consistent Tie-breaking Application: Applied the new job-then-task ordering logic consistently across both preemptor-missing and same-queue victim selection paths within BuildVictimsPriorityQueue.
  • Added Unit Tests: Included new unit tests in session_plugins_victim_order_test.go to specifically cover the improved victim selection tie-break behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • release-note
    • Improve scheduler victim selection tie-break behavior for same job-priority scenarios by using task-order when job-order ties in BuildVictimsPriorityQueue.
Activity
  • The author provided special notes for reviewers, highlighting key logic changes and unit test locations.
  • The author disclosed the use of AI assistance in the creation of the PR, noting thorough guidance and significant rewrites.
  • The author included an AI-generated rhyme related to the PR's content.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively improves victim selection for jobs with the same priority by introducing a more robust tie-breaking mechanism. The refactoring of JobOrderFn into JobOrderCompareFn is a clean approach that enhances code reuse. The new logic in BuildVictimsPriorityQueue correctly uses TaskOrderFn as a tie-breaker, avoiding reliance on creation timestamps. The addition of a dedicated unit test is also a valuable contribution. I have one minor suggestion to improve comment clarity.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves victim selection ordering when multiple victims belong to jobs with the same job priority by using plugin job ordering first and TaskOrderFn as a deterministic tie-breaker (instead of implicitly falling back to timestamp/UID behavior).

Changes:

  • Introduce JobOrderCompareFn to expose plugin-only job ordering comparison results.
  • Update BuildVictimsPriorityQueue to apply job ordering first and task ordering when job ordering ties (including the “preemptor job missing” path).
  • Add focused unit tests for the updated victim ordering behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
pkg/scheduler/framework/session_plugins.go Adds plugin-only job compare and uses task-order as tie-break in victim PQ ordering.
pkg/scheduler/framework/session_plugins_victim_order_test.go Adds unit tests asserting the victim ordering outcome in both preemptor-job-present/missing paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Set deterministic PodGroup creation timestamps and assert
JobOrderCompareFn tie conditions so task-order fallback behavior is
validated consistently.

Update BuildVictimsPriorityQueue comments to match current ordering
paths, including orphaned jobs and queue-based handling.

Signed-off-by: Hajnal Máté <hajnalmt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. kind/RFE Categorizes issue or PR as related to design. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement request: use task-order tie-break for victim selection when job order ties

3 participants