Ordered Insertion Optimization in OrioleDB
When many sessions try to insert into the same B-tree leaf page, classic exclusive page locking serializes progress and wastes time on sleep/wake cycles. We’re introducing a batch page insertion path that lets the session holding the page lock insert for itself and its neighbors. The result: dramatically reduced lock waits, and big gains at high client counts (2X throughput boost starting from 64 clients in our benchmark).
The problem: hot leaves and lock convoys
In OrioleDB beta12, inserts into a B-tree leaf are performed under an exclusive page lock. If several backends target the same leaf page, they queue, sleep, and wake up in turn.
That’s correct and simple — but not cheap:
- Every process waiting for the lock pays the cost of sleep → wake → re-check just to insert a tiny tuple.
- If the leaf is hot (e.g., time-ordered keys, skew, or tight key ranges), we get a huge queue on that single page.
- The lock hand-off cadence, not raw CPU, becomes the bottleneck.