New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store topology spread constraints in metadata with labels.Selector #85157
Store topology spread constraints in metadata with labels.Selector #85157
Conversation
a29cc5e
to
8764d9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alculquicondor ! Some comments below.
@@ -66,7 +66,7 @@ type criticalPath struct { | |||
// topologyValue denotes the topology value mapping to topology key. | |||
topologyValue string | |||
// matchNum denotes the number of matching pods. | |||
matchNum int32 | |||
matchNum int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to simplify types. Were you trying to optimize memory before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not particular for memory optimization. It was designed to be aligned with the type defined in API spec. If int32 is good enough, suggest to keep it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tpPairToMatchNum map[topologyPair]int | ||
} | ||
|
||
type topologySpreadConstraint struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To not confuse with v1.TopologySpreadConstraint, suggest to rename to internal TopologySpreadConstraint
or similar name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One is just the parsed version of the other. I don't see any harm on them having the same name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or, let's put a comment to emphasize that (1) it's an internal version which has a particular labels.Selector
field instead of metav1.Selector
, (2) it's for simplifying the matching logic and performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -581,57 +572,55 @@ func (m *topologyPairsMaps) clone() *topologyPairsMaps { | |||
return copy | |||
} | |||
|
|||
func (c *evenPodsSpreadMetadata) addPod(addedPod, preemptorPod *v1.Pod, node *v1.Node) error { | |||
return c.updatePod(addedPod, preemptorPod, node, 1) | |||
func (c *evenPodsSpreadMetadata) addPod(addedPod, preemptorPod *v1.Pod, node *v1.Node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename c
to epsMeta
or sth. similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you ok with just m
? one character for the instance variable seems like standard practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m
is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
var result []topologySpreadConstraint | ||
for _, c := range constraints { | ||
if c.WhenUnsatisfiable == v1.DoNotSchedule { | ||
selector, err := metav1.LabelSelectorAsSelector(c.LabelSelector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this is the key perf of the improvement - LabelSelectorAsSelector
doesn't sound like a cheap operation, and if we cache the result, we seem to get a lot of benefits.
A followup is to do a thorough check of "repeated usage of LabelSelectorAsSelector" and do similar refactoring. I do recall there was a PR using the same rationale improving the performance of PodAffinity, probably #79465. We should consolidate this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like suggestion. cc @liu-cong who is looking into performance in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should run some benchmarks first, but we could annotate the pods in the scheduler cache with already processed Selectors for affinity and spread constraints, and so we do this conversion per pod rather than per pod per cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SG:) I was discussing with ahg-g yesterday about what can be cached per pod and this seems to fall into that category.
/milestone v1.17 |
@ahg-g Code freeze for v1.17 is tomorrow at 5PM so this will need to be merged before then to make the milestone. |
Signed-off-by: Aldo Culquicondor <acondor@google.com>
8764d9e
to
e3bdb4b
Compare
/retest |
/test pull-kubernetes-node-e2e-containerd |
1 similar comment
/test pull-kubernetes-node-e2e-containerd |
/retest |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alculquicondor, Huang-Wei The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Stores topology spread constraints in predicates and priority metadata, also parsing
labels.Selector
. This allows:Additionally, this improves the performance of EvenPodsSpreadPriority, making it about 2x faster:
Ref #84936
Special notes for your reviewer:
Does this PR introduce a user-facing change?: