Commit 14cfa3c
committed
(improvement)TokenAware round robin policy and others - improved query planning.
Optimize TokenAwarePolicy query plan generation
This patch significantly improves the performance of TokenAwarePolicy by
reducing overhead in list materialization and distance calculation.
Key changes:
1. Introduced `make_query_plan_with_exclusion()` to the LoadBalancingPolicy
interface.
- This allows a parent policy (like TokenAware) to request a plan from
a child policy while efficiently skipping a set of already-yielded
hosts (replicas).
- Implemented optimized versions in `DCAwareRoundRobinPolicy` and
`RackAwareRoundRobinPolicy`. These implementations integrate the
exclusion check directly into their generation loops, avoiding the
need for inefficient external filtering or full list materialization.
2. Optimized `TokenAwarePolicy.make_query_plan`:
- Removed list materialization of the child query plan.
- Replaced multiple passes over replicas (checking `child.distance`
each time) with a single pass that buckets replicas into local/remote
lists.
- Utilizes `make_query_plan_with_exclusion` to yield the remainder
of the plan.
- Added `__slots__` to reduce memory overhead and attribute access cost.
Benchmark (100K queries, 45-node/5-DC topology, Python 3.14, median of 5 runs):
Policy | Kops/s | vs master | delta | Mem KB
-----------------------------------------------------------------
DCAware | 159 | +50% | | 1.5
RackAware | 128 | +88% | | 2.0
TokenAware(DCAware) | 81 | +350% | +305% | 2.9
TokenAware(RackAware) | 64 | +276% | +237% | 3.6
Default(DCAware) | 199 | +119% | +62% | 1.6
HostFilter(DCAware) | 56 | +6% | | 1.7
TokenAware throughput increases ~4x: DCAware-wrapped goes from 18 to 81 Kops/s
(+350%), RackAware-wrapped from 17 to 64 Kops/s (+276%).
DefaultPolicy also benefits strongly (+119%) from the new exclusion interface.
Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>1 parent f962afe commit 14cfa3c
2 files changed
Lines changed: 862 additions & 289 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
160 | 174 | | |
161 | 175 | | |
162 | 176 | | |
| |||
199 | 213 | | |
200 | 214 | | |
201 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
202 | 232 | | |
203 | 233 | | |
204 | 234 | | |
| |||
297 | 327 | | |
298 | 328 | | |
299 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
300 | 350 | | |
301 | 351 | | |
302 | 352 | | |
| |||
449 | 499 | | |
450 | 500 | | |
451 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
452 | 531 | | |
453 | 532 | | |
454 | 533 | | |
| |||
515 | 594 | | |
516 | 595 | | |
517 | 596 | | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
| 597 | + | |
524 | 598 | | |
525 | 599 | | |
526 | 600 | | |
527 | 601 | | |
| 602 | + | |
528 | 603 | | |
529 | 604 | | |
530 | 605 | | |
| |||
548 | 623 | | |
549 | 624 | | |
550 | 625 | | |
551 | | - | |
552 | | - | |
| 626 | + | |
553 | 627 | | |
554 | 628 | | |
| 629 | + | |
| 630 | + | |
555 | 631 | | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
565 | 638 | | |
566 | | - | |
567 | | - | |
568 | | - | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
569 | 661 | | |
570 | 662 | | |
571 | 663 | | |
572 | 664 | | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
593 | 699 | | |
594 | 700 | | |
595 | 701 | | |
| |||
0 commit comments