Commit c488171
committed
Make APC updateGauge with set command lock-free in critical path
When setting a value on a gauge, apcu_store is always called two
times, taking a write lock each that can cause contention.
- Replace apcu_store with compare-and-swap algorithm unless we store
for the first time(s)
- Eagerly fetch old value instead of apcu_exists, since we will anyway
need it for the compare-and-swap algorithms that follows, saving one
call to APCu
- Make sure we never enter an infinite loop in the compare-and-swap
section by falling back to a first-time insert if $old === false. A
fix for the potential infinite loop below will be done in a separate
commit.
Signed-off-by: Tobias Bengtsson <me@tobiasbengtsson.se>1 parent 7538b4d commit c488171
1 file changed
+24
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | | - | |
128 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
129 | 150 | | |
130 | | - | |
| 151 | + | |
131 | 152 | | |
132 | 153 | | |
133 | 154 | | |
| |||
0 commit comments