perf: Improve SimulateScheduling performance by reusing TopologyDomainGroups and InstanceTypes - #3271
perf: Improve SimulateScheduling performance by reusing TopologyDomainGroups and InstanceTypes#3271RafalSumislawski wants to merge 4 commits into
SimulateScheduling performance by reusing TopologyDomainGroups and InstanceTypes#3271Conversation
|
Welcome @RafalSumislawski! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: RafalSumislawski The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Description
Consolidation generally performs multiple consolidation simulations per cycle. Most significantly
SingleNodeConsolidationperforms one simulation per node. In my production clusters a call toSimulateSchedulingtakes ~900ms, meaning thatSingleNodeConsolidationneeds 18 minutes to scan 1000 nodes (of course there is a timeout before that, but that's not the point).Below is an example trace of a
SimulateSchedulingcall:As you can see the scheduling simulation took 930ms, but very little of that computational cost belongs to the actual scheduling simulation. Most of it is the setup, which in principle could be done once and then reused across many simulations (with some challenges). In this PR I'm specifically tackling the
getInstanceTypes(65ms) andbuildDomainGroups(304ms) calls. The PR puts results of these two operations in aShedulerFactorywhich then reuses the data across manySimulateSchedulingwithin a single consolidation cycle.This is an example
SimulateSchedulingtrace after the change:Both
getInstanceTypesandbuildDomainGroupsare gone from the trace as they now happen outside ofSimulateScheduling. TheSimulateSchedulingtime is reduced from 930ms to 512ms. A 45% reduction.I think there's more that could be done to reduce that time. But I'd prefere doing it in separate PRs rather than bloating this one.
Note on the test setup:
I run a fork of karpenter 1.9.0 with extra tracing, metrics and other stuff. So I've done the changes and the assessment on a fork of 1.9.0, and then rebased onto
main. I haven't seen any differences between the two versions that would meaningfully affect performance ofgetInstanceTypesorbuildDomainGroups, which made me conclude thatmainneeds these improvements as much as 1.9.0 does.Behaviour changes:
While this PR is meant as a pure performance optimisation, it still leads to subtle behaviour changes:
GetInstanceTypeswas called before each simulation, meaning that within a single consolidation cycle different instance types could have been used by different simulations. The call is now done once for each consolidation method so all simulation that consolidation does use the same instance types info even if it changes at the source while the consolidation cycle is in progress. I'd say that's better, but it is a potential behaviour change.consolidateAfter, karpenter's consolidation doesn't have an explicit pacing mechanism. Computational throughput is the effective consolidation pace regulator. Making the computation faster will make karpenter run more consolidations per unit of time under certain scenarios. This is the whole point of this change, but it may be seen as a regression in cluster stability.How was this change tested?
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.