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

Refine locking in API Priority and Fairness config controller #104833

Merged
merged 1 commit into from Sep 8, 2021

Conversation

MikeSpreitzer
Copy link
Member

What type of PR is this?

/kind flake

What this PR does / why we need it:

Instead of a plain Mutex, use an RWMutex so that the common operations can proceed in parallel.

Which issue(s) this PR fixes:

Fixes #104811

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.:


Instead of a plain `Mutex`, use an `RWMutex` so that the common
operations can proceed in parallel.
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/flake Categorizes issue or PR as related to a flaky test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 8, 2021
@MikeSpreitzer
Copy link
Member Author

@kubernetes/sig-api-machinery-bugs
/cc @tkashem
/cc @deads2k
@lavalamp
@wojtek-t

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. kind/bug Categorizes issue or PR as related to a bug. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 8, 2021
@MikeSpreitzer
Copy link
Member Author

@mborsz

@MikeSpreitzer
Copy link
Member Author

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 8, 2021
@wojtek-t
Copy link
Member

wojtek-t commented Sep 8, 2021

Thanks Mike - let's see how much this will help and if we need to improve it further.

/lgtm
/approve

@mborsz - FYI

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MikeSpreitzer, 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 merged commit 9f6a319 into kubernetes:master Sep 8, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Sep 8, 2021
@MikeSpreitzer MikeSpreitzer deleted the fix104811 branch September 8, 2021 13:02
@fedebongio
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Sep 9, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Sep 9, 2021
@shyamjvs
Copy link
Member

@MikeSpreitzer @wojtek-t What do you think about backporting this fix to all currently supported versions (>=1.20)?

@MikeSpreitzer
Copy link
Member Author

I think back-porting would be a good idea.

@shyamjvs
Copy link
Member

Thanks, I've opened above cherrypick PRs. PTAL if that sgty.

// call and will be locked upon return. For a configController, the
// suffix "ReadLocked" stipulates a read lock while just "Locked"
// stipulates a full lock. Absence of either suffix means that either
// (a) the lock must NOT be held at call time and will not be held
Copy link
Member

Choose a reason for hiding this comment

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

It is not good for that to mean either of these two options, since they are contradictory.

Copy link
Member Author

Choose a reason for hiding this comment

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

I look at it this way: using "Locked" gives some information. Not using "Locked" is the complement of that. Yes, it might be nice to distinguish cases in that complement. But do you really want to see more stuff added to more func names?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, this runs into trouble when implementing an interface. You do not want an implementation distinction (between "doesn't care about the implementation's lock" and "must not hold the implementation's lock") to appear in the func names in the interface.

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to describe the situation like this: "For functions without either suffix, look at the function comment for any locking requirements."

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's the obvious conclusion from the existing text, but would be fine with adding that explicit statement.

Copy link
Member Author

Choose a reason for hiding this comment

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

How would you recommend proceeding, from the current state of the codebase and PRs?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's worth changing this since it already merged, I was just (attempting to) note that the comment isn't very helpful, but is written in language that makes it seem like it should be helpful.

k8s-ci-robot added a commit that referenced this pull request Sep 17, 2021
…4833-upstream-release-1.21

Automated cherry pick of #104833 (1.21): Refine locking in API Priority and Fairness config controller
k8s-ci-robot added a commit that referenced this pull request Sep 17, 2021
…4833-upstream-release-1.22

Automated cherry pick of #104833 (1.22): Refine locking in API Priority and Fairness config controller
k8s-ci-robot added a commit that referenced this pull request Sep 17, 2021
…4833-upstream-release-1.20

Automated cherry pick of #104833 (1.20): Refine locking in API Priority and Fairness config controller
cfgCtlr.lock.Lock()
defer cfgCtlr.lock.Unlock()
cfgCtlr.lock.RLock()
defer cfgCtlr.lock.RUnlock()
for _, plc := range cfgCtlr.priorityLevelStates {
if plc.queues != nil {
plc.queues.UpdateObservations()
Copy link
Member

Choose a reason for hiding this comment

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

is it correct that we're calling UpdateObservations() under a read lock?

Copy link
Member Author

Choose a reason for hiding this comment

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

chenchun pushed a commit to chenchun/kubernetes that referenced this pull request Mar 20, 2024
…!770)

cherrypick PR104833: Refine locking in API Priority and Fairness config controller
cherrypick PR104833: Refine locking in API Priority and Fairness config controller

kubernetes#104833
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/bug Categorizes issue or PR as related to a bug. kind/flake Categorizes issue or PR as related to a flaky test. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ci-kubernetes-e2e-gce-scale-performance flakes with slow POST/PATCH jobs requests
7 participants