Commit aea2e32
authored
✨ Add a priority queue (#3014)
* :sparkling: POC of a priority queue
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.
* Use a btree, it is faster
```
$ 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)
```
* Add fuzztest and fix bug it found
* Fix handler
* Move into package priorityqueue
* Metric: Adds are only counted if the object didn't exist yet
* Validate correct usage of btree and tick
* Add retry metrics
* Fix missing notification when item is added
* Add tests for handler
* Controller tests
* Add some benchmarks
* Make Add non-blocking
* Revert "Make Add non-blocking"
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%
```
* Remove unneccesarry timestamp
* Consolidate require directiv
* Godocs and simplification
* Fix priorityqueue defaulting
* Avoid unnecessary else when returning1 parent 203ef4e commit aea2e32
File tree
20 files changed
+1599
-106
lines changed- examples
- priorityqueue
- scratch-env
- pkg
- builder
- config
- controller
- priorityqueue
- handler
- internal/metrics
- metrics
20 files changed
+1599
-106
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
168 | 176 | | |
169 | 177 | | |
170 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
| 320 | + | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
344 | | - | |
| 344 | + | |
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
56 | 62 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
192 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
193 | 198 | | |
194 | 199 | | |
195 | 200 | | |
196 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
197 | 207 | | |
198 | 208 | | |
199 | 209 | | |
| |||
0 commit comments