Skip to content
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

perf: Improve the performance of the provisioner #235

Merged
merged 1 commit into from
Mar 13, 2023
Merged
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
17 changes: 15 additions & 2 deletions pkg/controllers/provisioning/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,26 @@ func (p *Provisioner) NewScheduler(ctx context.Context, pods []*v1.Pod, stateNod
requirements.Add(instanceType.Requirements.Values()...)

for key, requirement := range requirements {
domains[key] = domains[key].Union(sets.NewString(requirement.Values()...))
//This code used to execute a Union between domains[key] and requirement.Values().
//The downside of this is that Union is immutable and takes a copy of the set it is executed upon.
//This resulted in a lot of memory pressure on the heap and poor performance
//https://github.com/aws/karpenter/issues/3565
if domains[key] == nil {
stijndehaes marked this conversation as resolved.
Show resolved Hide resolved
domains[key] = sets.NewString(requirement.Values()...)
} else {
domains[key].Insert(requirement.Values()...)
}
}
}

for key, requirement := range scheduling.NewNodeSelectorRequirements(provisioner.Spec.Requirements...) {
if requirement.Operator() == v1.NodeSelectorOpIn {
domains[key] = domains[key].Union(sets.NewString(requirement.Values()...))
//The following is a performance optimisation, for the explanation see the comment above
if domains[key] == nil {
domains[key] = sets.NewString(requirement.Values()...)
} else {
domains[key].Insert(requirement.Values()...)
}
}
}
}
Expand Down