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

Avoid creating more delete collection workers than items to delete #91544

Merged

Conversation

brianpursley
Copy link
Member

@brianpursley brianpursley commented May 28, 2020

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
Was investigating timeout flakes and saw this TODO comment. I don't think this is the cause of the timeout flakes, but it does seem like a good idea to limit the number of workers to the number of items being deleted.

Practically speaking this will have a limited effect since the default DeleteCollectionWorkers appears to be 1, but if you set it higher, it will avoid creating extra unnecessary workers.

Which issue(s) this PR fixes:
I could not find an issue for this, but there was a TODO comment in the code.

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. 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. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 28, 2020
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. release-note-none Denotes a PR that doesn't merit a release note. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. 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 May 28, 2020
@brianpursley
Copy link
Member Author

/retest

@brianpursley
Copy link
Member Author

/assign @liggitt

@cheftako
Copy link
Member

/assign @wojtek-t

// DeleteCollectionWorkers (it doesn't make much sense to spawn 16
// workers to delete 10 items).
workersNumber := e.DeleteCollectionWorkers
if workersNumber < 1 {
workersNumber = 1
} else if workersNumber > len(items) {
workersNumber = len(items)
Copy link
Member

Choose a reason for hiding this comment

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

what happens with zero items/workers?

Copy link
Member

Choose a reason for hiding this comment

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

it's probably fine, since there isn't anything to delete then

But I would probably feel safer maxing it with 1,
So basically:
max(1, min(len(items), e.DeleteCollectionWorkers)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, it will at least clarify the case... I'll make the change

Copy link
Member Author

Choose a reason for hiding this comment

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

ptal

I moved the if around to take care of the 0 items case.


Also, do you think it is a good idea to just return up front if there are no items in the collection (I don't know if this can even happen)?

I added a check to just return successfully if there are no items in the collection, instead of going through the WaitGroup and workers code which ultimately won't do anything.

@brianpursley
Copy link
Member Author

/retest

@wojtek-t
Copy link
Member

/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 May 29, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brianpursley, wojtek-t

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, 2020
@k8s-ci-robot k8s-ci-robot merged commit 106c3ef into kubernetes:master May 29, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone May 29, 2020
@brianpursley brianpursley deleted the DeleteCollectionWorkers branch February 2, 2023 01:20
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. area/apiserver 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. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants