Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Fix wrong calculation for queue deserved in proportion plugin #730

Merged
merged 1 commit into from
May 29, 2019

Conversation

zionwu
Copy link
Contributor

@zionwu zionwu commented Apr 10, 2019

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #729

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 10, 2019
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 10, 2019
@zionwu
Copy link
Contributor Author

zionwu commented Apr 10, 2019

@hex108 @k82cn Could you please review this PR? Thanks.

@k82cn
Copy link
Contributor

k82cn commented Apr 10, 2019

is it possible to add an e2e test for that?

@zionwu zionwu force-pushed the fix-proportion branch 5 times, most recently from 4f3280c to 6454cc7 Compare April 10, 2019 13:03
@zionwu
Copy link
Contributor Author

zionwu commented Apr 11, 2019

is it possible to add an e2e test for that?

Let me spend some time to see if it is possible to add e2e test.

@zionwu zionwu force-pushed the fix-proportion branch 3 times, most recently from ae41442 to 3153f5e Compare April 16, 2019 09:02
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 16, 2019
@zionwu zionwu force-pushed the fix-proportion branch 6 times, most recently from 52c3b9b to 3f3dc14 Compare April 17, 2019 01:53
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 17, 2019
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 27, 2019
@zionwu zionwu force-pushed the fix-proportion branch 2 times, most recently from 5b3e663 to 4a26249 Compare April 27, 2019 07:53
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 21, 2019
@zionwu zionwu force-pushed the fix-proportion branch 4 times, most recently from ed91b62 to f4a8ce0 Compare May 21, 2019 11:40
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 21, 2019
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 21, 2019
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 21, 2019
@zionwu zionwu force-pushed the fix-proportion branch 2 times, most recently from 7f28df9 to eb50461 Compare May 22, 2019 03:02
@zionwu
Copy link
Contributor Author

zionwu commented May 22, 2019

@k82cn, I have added the e2e test "Proportion".

Without my fix, the test will fail. You can verify at this CI Test: https://travis-ci.org/kubernetes-sigs/kube-batch/builds/535261793?utm_source=github_status&utm_medium=notification

With my fix, the test can pass, which you can check the latest CI result.

@@ -125,20 +129,26 @@ func (pp *proportionPlugin) OnSessionOpen(ssn *framework.Session) {

oldDeserved := attr.deserved.Clone()
attr.deserved.Add(remaining.Clone().Multi(float64(attr.weight) / float64(totalWeight)))
if !attr.deserved.LessEqual(attr.request) {

if attr.request.Less(attr.deserved) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There has already been some problems caused by Less and LessEqual. The problems will be solved If the type MilliCPU, Memory and values of ScalarResources change from float64 to resource.Quantity or int64.

@k82cn What is your option?

Copy link
Contributor

Choose a reason for hiding this comment

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

The problems will be solved If the type MilliCPU, Memory and values of ScalarResources change from float64 to resource.Quantity or int64.

Do you mean if we change to int64, this fix is not necessary?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, because it is caused by LessEqual is not <= actually.

Copy link
Contributor

Choose a reason for hiding this comment

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

LessEqual is not <= actually.

Can you share some case for that?

Copy link
Contributor Author

@zionwu zionwu May 27, 2019

Choose a reason for hiding this comment

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

In my opinion, this issue still exist even with resource.Quantity or int64.
The problem is that Resource is consist of MilliCPU, Memory and ScalarResources, and LessEqual requires all 3 members to be lessEqual:

func (r *Resource) LessEqual(rr *Resource) bool {
	isLess := (r.MilliCPU < rr.MilliCPU || math.Abs(rr.MilliCPU-r.MilliCPU) < minMilliCPU) &&
		(r.Memory < rr.Memory || math.Abs(rr.Memory-r.Memory) < minMemory)
	if !isLess {
		return false
	}

	if r.ScalarResources == nil {
		return true
	}

	for rName, rQuant := range r.ScalarResources {
		if rr.ScalarResources == nil {
			return false
		}

		rrQuant := rr.ScalarResources[rName]
		if !(rQuant < rrQuant || math.Abs(rrQuant-rQuant) < minMilliScalarResources) {
			return false
		}
	}

	return true
}

!attr.deserved.LessEqual(attr.request) is true when only one member of attr.deserved is larger than attr.request. But we need all 3 members of attr.deserved larger than attr.request. So we should always use attr.request.Less(attr.deserved) no matter what type of the 3 member is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @zionwu , the error is because we use attr.request.LessEqual(attr.deserved) but we should use attr.request.Less(attr.deserved).

if remaining.IsEmpty() {
glog.V(4).Infof("exiting when remaining is empty: <%v>", remaining)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/exiting/Exiting/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@k82cn
Copy link
Contributor

k82cn commented May 28, 2019

LGTM overall, thanks 👍

@hex108
Copy link
Contributor

hex108 commented May 28, 2019

/lgtm

for this PR.

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 28, 2019
@zionwu
Copy link
Contributor Author

zionwu commented May 29, 2019

@k82cn Could you approve this PR? Thanks.

@k82cn
Copy link
Contributor

k82cn commented May 29, 2019

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: k82cn, zionwu

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 May 29, 2019
@k8s-ci-robot k8s-ci-robot merged commit e5fbee3 into kubernetes-retired:master May 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deserved attr is not correctly calculated in proportion plugin
4 participants