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

✨ Add a priority queue #3014

Merged
merged 19 commits into from
Dec 6, 2024
Merged

Conversation

alvaroaleman
Copy link
Member

@alvaroaleman alvaroaleman commented Nov 17, 2024

This change contains a priority workqueue that allows to prioritize events over one another. It is opt-in and will by default de-prioritize events originating from the initial listwatch and from periodic resyncs.

Ref #2374
Ref #3013
/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 17, 2024
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 17, 2024
@alvaroaleman alvaroaleman changed the title :sparkling: POC of a priority queue ✨ POC of a priority queue Nov 17, 2024
@alvaroaleman alvaroaleman force-pushed the controllerwq branch 5 times, most recently from 4c80ffb to 506d130 Compare November 21, 2024 00:09
@alvaroaleman alvaroaleman changed the title ✨ POC of a priority queue ✨ Add a priority queue Nov 24, 2024
@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 24, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2024
This change contains the POC of a priority workqueue that allows to
prioritize events over one another. It is opt-in and will by default
de-prioritize events originating from the initial listwatch and from
periodic resyncs.
```
$ benchstat slice.txt btree.txt
goos: darwin
goarch: arm64
pkg: sigs.k8s.io/controller-runtime/pkg/controllerworkqueue
cpu: Apple M2 Pro
              │  slice.txt  │              btree.txt              │
              │   sec/op    │   sec/op     vs base                │
AddGetDone-10   5.078m ± 0%   1.163m ± 0%  -77.09% (p=0.000 n=10)

              │  slice.txt   │              btree.txt               │
              │     B/op     │     B/op      vs base                │
AddGetDone-10   55.11Ki ± 0%   46.98Ki ± 0%  -14.75% (p=0.000 n=10)

              │  slice.txt  │              btree.txt              │
              │  allocs/op  │  allocs/op   vs base                │
AddGetDone-10   3.000k ± 0%   1.000k ± 0%  -66.67% (p=0.000 n=10)
```
This reverts commit ce23de5.

Speedup is tiny and at the expense of increased mem usage (which due to
increasing GC pressure is likely the explanation why its so small), so
doesn't seem worth it overall:
```
goos: darwin
goarch: arm64
pkg: sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue
cpu: Apple M2 Pro
                    │ blocking.txt │          non-blocking.txt          │
                    │    sec/op    │   sec/op     vs base               │
AddGetDone-10          1.320m ± 1%   1.410m ± 0%  +6.81% (p=0.000 n=10)
AddOnly-10             373.9µ ± 1%   343.2µ ± 1%  -8.22% (p=0.000 n=10)
AddLockContended-10    375.8µ ± 1%   342.8µ ± 1%  -8.78% (p=0.000 n=10)
geomean                570.3µ        549.4µ       -3.66%

                    │ blocking.txt │            non-blocking.txt             │
                    │     B/op     │     B/op      vs base                   │
AddGetDone-10         109.9Ki ± 0%   164.2Ki ± 0%     +49.42% (p=0.000 n=10)
AddOnly-10              553.0 ± 2%   56045.0 ± 0%  +10034.72% (p=0.000 n=10)
AddLockContended-10     569.0 ± 6%   56045.0 ± 0%   +9749.74% (p=0.000 n=10)
geomean               3.207Ki        78.94Ki        +2361.60%

                    │ blocking.txt │            non-blocking.txt             │
                    │  allocs/op   │  allocs/op    vs base                   │
AddGetDone-10          3.013k ± 0%    5.001k ± 0%     +65.98% (p=0.000 n=10)
AddOnly-10              16.00 ± 6%   2000.00 ± 0%  +12400.00% (p=0.000 n=10)
AddLockContended-10     16.00 ± 6%   2000.00 ± 0%  +12400.00% (p=0.000 n=10)
geomean                 91.71         2.715k        +2860.01%
```
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2024
go.mod Outdated Show resolved Hide resolved
pkg/config/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/priorityqueue/priorityqueue.go Show resolved Hide resolved
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

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

LGTM label has been added.

Git tree hash: b25ef6b7e50afc63336079f6a9eb6b6582091930

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, vincepri

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:
  • OWNERS [alvaroaleman,vincepri]

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 removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 6, 2024
@k8s-ci-robot k8s-ci-robot requested a review from vincepri December 6, 2024 18:05
@vincepri
Copy link
Member

vincepri commented Dec 6, 2024

/lgtm

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

LGTM label has been added.

Git tree hash: 4c1190390c83244fd75e957ce61387db2254ae91

@alvaroaleman
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 6, 2024
@k8s-ci-robot k8s-ci-robot merged commit aea2e32 into kubernetes-sigs:main Dec 6, 2024
9 checks passed
@alvaroaleman alvaroaleman deleted the controllerwq branch December 6, 2024 18:22
examples/priorityqueue/main.go Show resolved Hide resolved
pkg/controller/controller.go Show resolved Hide resolved
pkg/handler/eventhandler.go Show resolved Hide resolved
pkg/handler/eventhandler_test.go Show resolved Hide resolved
pkg/metrics/workqueue.go Show resolved Hide resolved
pkg/controller/priorityqueue/priorityqueue.go Show resolved Hide resolved
pkg/controller/priorityqueue/priorityqueue.go Show resolved Hide resolved
pkg/controller/priorityqueue/priorityqueue.go Show resolved Hide resolved
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants