Commit 845c792
committed
perf(run-engine): stop re-registering ck variants already in the fair order
A concurrency-gated candidate cost two Redis calls: the SCARD that discovers it is
gated, and a ZADD NX to make sure it is in the fair order. For anything pass 1
selected the second is a guaranteed no-op, because pass 1 draws its candidates from
the ckVtime zset and being in that scan is what registration means. tryServe now
takes a knownRegistered flag, so a gated visit from pass 1 costs only the SCARD,
the same as the flag-off command.
Pass 2 candidates can genuinely be unregistered, and ones outside pass 1's scanned
prefix are indistinguishable from those, so both are collected and settled after
pass 2 by a single variadic ZADD NX. Its return value is the count it inserted, so
the idle-tag correction that stops a drained variant reclaiming full credit only
runs when something actually registered. In the steady state nothing does and the
whole batch costs that one call.
Measured on the fully-gated shape, saturated (generator co-located with Redis, 1M
invocations per arm, Redis CPU/wall 0.978-0.987, no state drift):
N=1000 flag-off 21.05 before 76.63 (+55.6) after 54.56 (+33.5) -22.1us, 40%
N=10000 flag-off 21.09 before 77.99 (+56.9) after 57.52 (+36.4) -20.5us, 36%
A batched ZMSCORE reads the same information and measured better, -24.9us and
-24.7us for 45% and 43%. It was rejected anyway: it would have been the first thing
in this file to require Redis 6.2, and about 3 to 4 usec is a fair price for not
raising the floor. The variadic ZADD NX is one call either way; it costs more
because thirty skiplist lookups on the write path are dearer than thirty reads.
Worth noting the saving per call removed is nearer 0.4 usec than the 0.33 usec
measured previously on small keys, because the call being removed is a write
against a zset holding thousands of members.
Fully gated is the worst case by construction: a dequeue that serves exits earlier.
Per-key concurrency limits are ordinary on ck queues, so it is worth having.1 parent 1d96b41 commit 845c792
1 file changed
Lines changed: 41 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5403 | 5403 | | |
5404 | 5404 | | |
5405 | 5405 | | |
| 5406 | + | |
5406 | 5407 | | |
5407 | 5408 | | |
5408 | | - | |
5409 | | - | |
| 5409 | + | |
| 5410 | + | |
| 5411 | + | |
| 5412 | + | |
| 5413 | + | |
5410 | 5414 | | |
5411 | 5415 | | |
5412 | 5416 | | |
| |||
5528 | 5532 | | |
5529 | 5533 | | |
5530 | 5534 | | |
5531 | | - | |
5532 | | - | |
5533 | | - | |
5534 | | - | |
5535 | | - | |
5536 | | - | |
5537 | | - | |
5538 | | - | |
5539 | | - | |
5540 | | - | |
5541 | | - | |
5542 | | - | |
5543 | | - | |
| 5535 | + | |
| 5536 | + | |
| 5537 | + | |
| 5538 | + | |
| 5539 | + | |
| 5540 | + | |
| 5541 | + | |
| 5542 | + | |
| 5543 | + | |
5544 | 5544 | | |
5545 | 5545 | | |
5546 | 5546 | | |
| |||
5564 | 5564 | | |
5565 | 5565 | | |
5566 | 5566 | | |
5567 | | - | |
| 5567 | + | |
5568 | 5568 | | |
5569 | 5569 | | |
5570 | 5570 | | |
| |||
5584 | 5584 | | |
5585 | 5585 | | |
5586 | 5586 | | |
5587 | | - | |
| 5587 | + | |
5588 | 5588 | | |
5589 | 5589 | | |
5590 | 5590 | | |
| |||
5600 | 5600 | | |
5601 | 5601 | | |
5602 | 5602 | | |
| 5603 | + | |
| 5604 | + | |
| 5605 | + | |
| 5606 | + | |
| 5607 | + | |
| 5608 | + | |
| 5609 | + | |
| 5610 | + | |
| 5611 | + | |
| 5612 | + | |
| 5613 | + | |
| 5614 | + | |
| 5615 | + | |
| 5616 | + | |
| 5617 | + | |
| 5618 | + | |
| 5619 | + | |
| 5620 | + | |
| 5621 | + | |
| 5622 | + | |
| 5623 | + | |
| 5624 | + | |
| 5625 | + | |
| 5626 | + | |
5603 | 5627 | | |
5604 | 5628 | | |
5605 | 5629 | | |
| |||
0 commit comments