Commit df44847
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.976-0.986, no state drift, spread 0.2-0.3
usec against a 25 usec effect):
N=1000 flag-off 21.05 before 76.18 (+55.1) after 51.25 (+30.2)
N=10000 flag-off 21.08 before 77.91 (+56.8) after 53.20 (+32.1)
So it removes about 45% of the gated dequeue overhead, flat across cardinality.
A batched ZMSCORE reads the same information in one call and was tried first, but it
would have been the first thing in this file to require Redis 6.2, and the variadic
ZADD NX costs the same one call without that. Worth noting the saving per call here
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 df44847
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