Commit 7538b4d
committed
Make APCng updateGauge with set command lock-free in critical path
When setting a value on a gauge, first apcu_store is called in
updateGauge and then apcu_add is called in storeMetadata. Both of
these operations takes a write lock in APCu which can cause contention.
- Change updateGauge to use a compare-and-swap algorithm instead of
apcu_store, unless we're adding something for the first time(s) in
which case we just set it with apcu_store.
- Don't call updateMetadata and storeLabelKeys unless it's the first
time we're setting a gauge (matches the behaviour of inc/dec).
- For extra safety, make a cheap rlock-only check in storeMetadata if
the key exists before calling apcu_add with a wlock.
Signed-off-by: Tobias Bengtsson <me@tobiasbengtsson.se>1 parent 735ace7 commit 7538b4d
1 file changed
+27
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| 172 | + | |
172 | 173 | | |
173 | | - | |
174 | | - | |
175 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
176 | 196 | | |
177 | 197 | | |
178 | 198 | | |
179 | 199 | | |
180 | | - | |
181 | | - | |
182 | 200 | | |
183 | 201 | | |
184 | 202 | | |
| |||
896 | 914 | | |
897 | 915 | | |
898 | 916 | | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
899 | 921 | | |
900 | 922 | | |
901 | 923 | | |
| |||
0 commit comments