Commit 4520036
committed
fix(dispatch): reduce locking contention
Reduce the amount of time spent holding locks in the dispatcher by using
the new data structures:
- doMaintenance() snapshots empty groups and deletes them afterwards
- Groups() snapshots routes and queries groups per route on demand
- processAlert() only locks the group it is processing an alert for
None of the above 3 methods hold any locks directly.
This results in -68% maintenance overhead or +12991% alert processing rate improvement:
```
goos: darwin
goarch: arm64
pkg: github.com/prometheus/alertmanager/dispatch
cpu: Apple M3 Pro
│ bench-dispatch-main.txt │ bench-dispatch-nested-map-locks.txt │
│ sec/op │ sec/op vs base │
Dispatch_100k_AggregationGroups_10k_Empty-12 1.242µ ± 1% 1.193µ ± 5% -3.91% (p=0.037 n=10)
Dispatch_100k_AggregationGroups_20k_Empty-12 1.329µ ± 2% 1.188µ ± 3% -10.65% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_30k_Empty-12 1.437µ ± 3% 1.288µ ± 7% -10.37% (p=0.001 n=10)
Dispatch_100k_AggregationGroups_40k_Empty-12 1.695µ ± 8% 1.236µ ± 6% -27.06% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_50k_Empty-12 2.185µ ± 11% 1.286µ ± 11% -41.17% (p=0.000 n=10)
Dispatch_20k_AggregationGroups_Groups_Impact-12 189007.708µ ± 6% 1.143µ ± 18% -100.00% (p=0.000 n=10)
Dispatch_50k_AggregationGroups_Groups_Impact-12 602.17m ± 69% 28.09m ± 605% -95.33% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_Groups_Impact-12 1.543 ± 29% 1.272 ± 96% ~ (p=0.247 n=10)
geomean 187.7µ 24.22µ -87.10%
│ bench-dispatch-main.txt │ bench-dispatch-nested-map-locks.txt │
│ alerts/sec │ alerts/sec vs base │
Dispatch_100k_AggregationGroups_10k_Empty-12 1.616M ± 1% 1.767M ± 3% +9.36% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_20k_Empty-12 1.412M ± 2% 1.715M ± 1% +21.45% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_30k_Empty-12 1.235M ± 4% 1.637M ± 4% +32.58% (p=0.002 n=10)
Dispatch_100k_AggregationGroups_40k_Empty-12 950.9k ± 14% 1614.0k ± 8% +69.73% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_50k_Empty-12 693.5k ± 18% 1370.7k ± 17% +97.65% (p=0.000 n=10)
Dispatch_20k_AggregationGroups_Groups_Impact-12 5.586 ± 14% 2027690.000 ± 5% +36299398.75% (p=0.000 n=10)
Dispatch_50k_AggregationGroups_Groups_Impact-12 3.277 ± 40% 742918.500 ± 167% +22667131.12% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_Groups_Impact-12 1.424 ± 4255939% 252756.500 ± 73% +17749654.21% (p=0.000 n=10)
geomean 9.134k 1.196M +12991.42%
│ bench-dispatch-main.txt │ bench-dispatch-nested-map-locks.txt │
│ maintenance_overhead_% │ maintenance_overhead_% vs base │
Dispatch_100k_AggregationGroups_10k_Empty-12 17.185 ± 7% 5.905 ± ? -65.64% (p=0.002 n=10)
Dispatch_100k_AggregationGroups_20k_Empty-12 36.50 ± 11% 13.66 ± 26% -62.58% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_30k_Empty-12 55.44 ± 13% 17.45 ± 26% -68.52% (p=0.002 n=10)
Dispatch_100k_AggregationGroups_40k_Empty-12 125.65 ± 27% 27.03 ± 34% -78.49% (p=0.000 n=10)
Dispatch_100k_AggregationGroups_50k_Empty-12 172.40 ± 36% 64.64 ± 60% -62.51% (p=0.000 n=10)
geomean 59.62 18.97 -68.17%
```
Signed-off-by: Siavash Safi <[email protected]>1 parent 689b82a commit 4520036
File tree
3 files changed
+490
-58
lines changed- dispatch
3 files changed
+490
-58
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
45 | | - | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
88 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
134 | 137 | | |
135 | 138 | | |
136 | 139 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
141 | 151 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 152 | + | |
147 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
148 | 167 | | |
149 | 168 | | |
150 | 169 | | |
151 | 170 | | |
152 | 171 | | |
153 | 172 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
158 | 180 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 181 | + | |
| 182 | + | |
162 | 183 | | |
163 | | - | |
164 | 184 | | |
165 | | - | |
| 185 | + | |
166 | 186 | | |
167 | | - | |
| 187 | + | |
168 | 188 | | |
169 | 189 | | |
170 | | - | |
| 190 | + | |
| 191 | + | |
171 | 192 | | |
172 | 193 | | |
173 | 194 | | |
| |||
197 | 218 | | |
198 | 219 | | |
199 | 220 | | |
200 | | - | |
| 221 | + | |
201 | 222 | | |
202 | 223 | | |
203 | 224 | | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
210 | 233 | | |
211 | 234 | | |
212 | 235 | | |
213 | 236 | | |
214 | 237 | | |
215 | | - | |
| 238 | + | |
216 | 239 | | |
217 | 240 | | |
218 | 241 | | |
| |||
236 | 259 | | |
237 | 260 | | |
238 | 261 | | |
239 | | - | |
240 | 262 | | |
241 | 263 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
254 | 268 | | |
255 | 269 | | |
256 | 270 | | |
257 | | - | |
258 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
259 | 275 | | |
260 | | - | |
| 276 | + | |
261 | 277 | | |
262 | 278 | | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | 279 | | |
268 | 280 | | |
269 | 281 | | |
270 | 282 | | |
271 | 283 | | |
272 | | - | |
| 284 | + | |
273 | 285 | | |
274 | | - | |
| 286 | + | |
275 | 287 | | |
276 | 288 | | |
277 | 289 | | |
| |||
0 commit comments