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

enhancemanet: reduce calculation calls #117390

Conversation

lowang-bh
Copy link
Member

@lowang-bh lowang-bh commented Apr 16, 2023

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

  1. function is called when need, reduce calling times of function GetPodStartTime() or PodPriority();
  2. reuse the result of former function calling;

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

benchmark test result

go version go1.20.1
goos: darwin
goarch: arm64
pkg: k8s.io/kubernetes/pkg/scheduler/util

before:

Benchmark10kPods-8   	   67680	     16837 ns/op	       0 B/op	       0 allocs/op
Benchmark10kPods-8   	   69393	     16928 ns/op	       0 B/op	       0 allocs/op
Benchmark10kPods-8   	   68298	     16942 ns/op	       0 B/op	       0 allocs/op
Benchmark10kPods-8   	   70198	     16125 ns/op	       0 B/op	       0 allocs/op

Benchmark100kPods-8   	    2661	    444173 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    2674	    446439 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    2715	    454089 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    2665	    440868 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    2646	    452669 ns/op	       0 B/op	       0 allocs/op

after:

Benchmark10kPods-8   	   80383	     14392 ns/op	       0 B/op	       0 allocs/op
Benchmark10kPods-8   	   81895	     14073 ns/op	       0 B/op	       0 allocs/op
Benchmark10kPods-8   	   78211	     14602 ns/op	       0 B/op	       0 allocs/op
Benchmark10kPods-8   	   76614	     15110 ns/op	       0 B/op	       0 allocs/op

Benchmark100kPods-8   	    2736	    409138 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    2932	    414789 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    2908	    403114 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    2925	    394417 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    2958	    410171 ns/op	       0 B/op	       0 allocs/op

benchmark code

func Benchmark10kPods(b *testing.B) {
	num := 10000
	now := time.Now()
	pods := make([]*v1.Pod, 0, num)
	for i := 0; i < num; i++ {
		prio := rand.Int31n(int32(num))
		rndTime := now.Add(time.Second * time.Duration(rand.Int63n(int64(num))))
		pods = append(pods, newPriorityPodWithStartTime("pod"+strconv.Itoa(i), prio, rndTime))
	}

	victims := &extenderv1.Victims{Pods: pods}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		GetEarliestPodStartTime(victims)
	}
	b.StopTimer()
}

Does this PR introduce a user-facing change?

None

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 16, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @lowang-bh!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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/test-infra repository.

@k8s-ci-robot
Copy link
Contributor

Hi @lowang-bh. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 16, 2023
@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 16, 2023
@lowang-bh
Copy link
Member Author

/sig scheduling

Copy link
Member

@sanposhiho sanposhiho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 16, 2023
Copy link
Member

@sanposhiho sanposhiho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/release-note-none

@sanposhiho
Copy link
Member

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 16, 2023
@sanposhiho
Copy link
Member

@lowang-bh
Sorry, I've just realized this change is the same as #117208 which was submitted a bit earlier than this.

Signed-off-by: lowang_bh <lhui_wang@163.com>
@lowang-bh lowang-bh force-pushed the less-funcations-calls-for-schedule-util branch 2 times, most recently from a6e69f4 to eaba170 Compare April 18, 2023 14:37
@lowang-bh
Copy link
Member Author

@lowang-bh Sorry, I've just realized this change is the same as #117208 which was submitted a bit earlier than this.

Yeah, I see. I find my pr has less function calls than that one.
And, I take a benchmark on that modify, here is the result.

Benchmark10kPods-8   	   52952	     22429 ns/op	       0 B/op	       0 allocs/op
Benchmark10kPods-8   	   47960	     24871 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    1060	   1126838 ns/op	       0 B/op	       0 allocs/op
Benchmark100kPods-8   	    1044	   1187247 ns/op	       0 B/op	       0 allocs/op

@ahg-g
Copy link
Member

ahg-g commented Apr 23, 2023

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 23, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 95192bfd4540a7435e8d0b10280c439c54a619d4

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahg-g, lowang-bh

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 /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 Apr 23, 2023
@k8s-ci-robot k8s-ci-robot merged commit 5f22ab3 into kubernetes:master Apr 23, 2023
12 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Apr 23, 2023
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants