Skip to content

Conversation

@ivankatliarchuk
Copy link
Member

@ivankatliarchuk ivankatliarchuk commented Jun 17, 2025

What does it do ?

In this PR, I've added a benchmark tests, to showcase bottlenecks described here #5473 (comment)

  • benchmark tests
  • added more tests
  • found duplicate code and replaced with function

Motivation

When decided to have a look started

And this comment #5493 (comment)

One of the bottlenecks is in this lines

services, err := svcInformer.Lister().Services(namespace).List(labels.Everything())
if err != nil {
return nil, fmt.Errorf("failed to list labels for services in namespace %q: %w", namespace, err)
}
for _, service := range services {
if !MatchesServiceSelector(selector, service.Spec.Selector) {
continue
}
if len(service.Spec.ExternalIPs) > 0 {
targets = append(targets, service.Spec.ExternalIPs...)
continue
}
for _, lb := range service.Status.LoadBalancer.Ingress {
if lb.IP != "" {
targets = append(targets, lb.IP)
} else if lb.Hostname != "" {
targets = append(targets, lb.Hostname)
}
}
}
return targets, nil

Basically it does

  • retrive all services from the cache
  • iterate over each service
  • iterate over each label

On top of that, the function EndpointTargetsFromServices actually called from within the loop of all virtual services or any other kubernetes entity like here. This is quite inneficiate....

Benchmark results

BenchmarkEndpointTargetsFromServicesMedium-16                       	   11194	    105419 ns/op
BenchmarkEndpointTargetsFromServicesMediumIterateOverGateways
BenchmarkEndpointTargetsFromServicesMediumIterateOverGateways-16    	     290	   4070484 ns/op
BenchmarkEndpointTargetsFromServicesHigh
BenchmarkEndpointTargetsFromServicesHigh-16                         	      88	  12669344 ns/op
BenchmarkEndpointTargetsFromServicesHighIterateOverGateways
BenchmarkEndpointTargetsFromServicesHighIterateOverGateways-16      	       1	13425263466 ns/op

Just a hightlight from one of the issues

We are running on EKS with BatchSizeConfig of 1,000 (default), we have ~3K Isito virtualService objects & 1K Service objects.

So this means that there are 3000 * 1000 * (number of selectors), every time there is a reconcile.

Follo-up:

More

  • Yes, this PR title follows Conventional Commits
  • Yes, I added unit tests
  • Yes, I updated end user documentation accordingly

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 17, 2025
@ivankatliarchuk ivankatliarchuk marked this pull request as draft June 17, 2025 09:25
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 17, 2025
@ivankatliarchuk ivankatliarchuk marked this pull request as ready for review June 17, 2025 10:17
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 17, 2025
@k8s-ci-robot
Copy link
Contributor

@AndrewCharlesHay: changing LGTM is restricted to collaborators

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

@AndrewCharlesHay: changing LGTM is restricted to collaborators

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ivankatliarchuk
Copy link
Member Author

cc @mloiseleur

@mloiseleur mloiseleur changed the title chore(benchmarking): added benchmarks to EndpointTargetsFromServices perf(source): benchmarks on EndpointTargetsFromServices Jun 19, 2025
@mloiseleur
Copy link
Collaborator

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AndrewCharlesHay, mloiseleur

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 19, 2025
@mloiseleur
Copy link
Collaborator

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2025
@k8s-ci-robot k8s-ci-robot merged commit 36e3e53 into kubernetes-sigs:master Jun 19, 2025
14 checks passed
@ivankatliarchuk ivankatliarchuk deleted the chore-benchmark-functions-v0 branch June 20, 2025 05:13
@ivankatliarchuk ivankatliarchuk changed the title perf(source): benchmarks on EndpointTargetsFromServices chore(source): benchmarks on EndpointTargetsFromServices Jun 20, 2025
@ivankatliarchuk ivankatliarchuk changed the title chore(source): benchmarks on EndpointTargetsFromServices perf(source): benchmarks on EndpointTargetsFromServices Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants