Updating EndpointSliceCache sort function to be significantly faster.#83035
Conversation
The .IP() call that was previously used for sorting resulted in a call to netutil to parse an IP out of an IP:Port string. This was very slow and resulted in this sort taking up ~50% of total CPU util for kube-proxy.
|
/retest |
| } | ||
| func (e byIP) Less(i, j int) bool { | ||
| return e[i].IP() < e[j].IP() | ||
| return e[i].String() < e[j].String() |
There was a problem hiding this comment.
We could add CompareByIP(Endpoint* other) int to the Endpoint interface and implement with bytes.compare() to avoid allocating a string on each comparison.
There was a problem hiding this comment.
@bowei This actually is just returning an IP:Port string that happens to be the only string stored with this endpoint struct. Previously when using the .IP() method it was actually resulting in a netutil call to parse that out which was resulting in the slowness. Here it's just returning the string that is already stored as is.
There was a problem hiding this comment.
Ah right, I thought for some reason it was stored as an IP internally.
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bowei, robscott The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds 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:
The .IP() call that was previously used for sorting resulted in a call to netutil to parse an IP out of an IP:Port string. This was very slow and resulted in this sort taking up ~50% of total CPU util for kube-proxy.
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
/sig network
/priority important-soon
/cc @freehan @bowei