Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
concurrency,kvserver: limited scans do optimistic latching
Latches for the full spans get inserted up front in the spanlatch.Manager, and the conflict checking happens after evaluation, only over the spans that were actually read. If there is a conflict, the existing inserted latches are waited on, and execution switches to pessimistic latching and locking. The existing cluster setting for optimistic locking is used to gate this behavior. Microbenchmark numbers: name old time/op new time/op delta OptimisticEvalForLocks/real-contention=false-16 28.8µs ± 6% 29.4µs ± 5% ~ (p=0.089 n=10+10) OptimisticEvalForLocks/real-contention=true-16 5.52ms ± 1% 5.54ms ± 1% ~ (p=0.123 n=10+10) OptimisticEvalForLatches/real-contention=false/num-writers=1-16 63.1µs ± 9% 32.7µs ± 4% -48.21% (p=0.000 n=10+10) OptimisticEvalForLatches/real-contention=false/num-writers=4-16 66.8µs ± 3% 34.4µs ± 5% -48.51% (p=0.000 n=10+10) OptimisticEvalForLatches/real-contention=false/num-writers=8-16 69.4µs ± 1% 35.7µs ± 2% -48.47% (p=0.000 n=10+10) OptimisticEvalForLatches/real-contention=true/num-writers=1-16 127µs ± 5% 112µs ± 2% -11.68% (p=0.000 n=10+10) OptimisticEvalForLatches/real-contention=true/num-writers=4-16 128µs ± 5% 112µs ± 2% -12.38% (p=0.000 n=9+10) OptimisticEvalForLatches/real-contention=true/num-writers=8-16 140µs ± 2% 115µs ± 2% -17.56% (p=0.000 n=9+7) name old alloc/op new alloc/op delta OptimisticEvalForLocks/real-contention=false-16 8.29kB ± 3% 8.38kB ± 5% ~ (p=0.367 n=9+10) OptimisticEvalForLocks/real-contention=true-16 32.2kB ±10% 42.2kB ±108% ~ (p=0.321 n=8+9) OptimisticEvalForLatches/real-contention=false/num-writers=1-16 16.6kB ± 4% 13.1kB ± 2% -21.07% (p=0.000 n=9+9) OptimisticEvalForLatches/real-contention=false/num-writers=4-16 16.6kB ± 7% 12.9kB ± 1% -22.23% (p=0.000 n=9+9) OptimisticEvalForLatches/real-contention=false/num-writers=8-16 16.3kB ± 0% 12.7kB ± 1% -22.20% (p=0.000 n=9+9) OptimisticEvalForLatches/real-contention=true/num-writers=1-16 26.8kB ± 0% 26.8kB ± 0% +0.14% (p=0.049 n=9+9) OptimisticEvalForLatches/real-contention=true/num-writers=4-16 26.8kB ± 0% 26.8kB ± 0% +0.12% (p=0.027 n=8+9) OptimisticEvalForLatches/real-contention=true/num-writers=8-16 26.8kB ± 0% 26.8kB ± 0% ~ (p=1.000 n=10+8) name old allocs/op new allocs/op delta OptimisticEvalForLocks/real-contention=false-16 68.6 ± 1% 70.0 ± 0% +2.04% (p=0.000 n=10+7) OptimisticEvalForLocks/real-contention=true-16 272 ± 3% 272 ± 2% ~ (p=0.777 n=8+8) OptimisticEvalForLatches/real-contention=false/num-writers=1-16 149 ± 0% 117 ± 1% -21.41% (p=0.000 n=8+10) OptimisticEvalForLatches/real-contention=false/num-writers=4-16 150 ± 0% 116 ± 2% -22.80% (p=0.000 n=7+10) OptimisticEvalForLatches/real-contention=false/num-writers=8-16 150 ± 0% 114 ± 1% -24.20% (p=0.000 n=9+10) OptimisticEvalForLatches/real-contention=true/num-writers=1-16 261 ± 0% 261 ± 0% ~ (all equal) OptimisticEvalForLatches/real-contention=true/num-writers=4-16 261 ± 0% 261 ± 0% ~ (p=0.471 n=9+9) OptimisticEvalForLatches/real-contention=true/num-writers=8-16 262 ± 0% 261 ± 0% -0.38% (p=0.000 n=8+8) Fixes #9521 Release note (performance improvement): A limited scan now checks for conflicting latches in an optimistic manner, which means it will not conflict with latches that were held in the scan's full spans, but were not in the spans that were scanned until the limit was reached. This behavior can be turned off (along with optimistic locking) by changing the value of the cluster setting kv.concurrency.optimistic_eval_limited_scans.enabled to false.
- Loading branch information