Commit f962afe
committed
(improvement)Optimize RackAwareRoundRobinPolicy by caching some host distances
Refactor `RackAwareRoundRobinPolicy` to simplify distance calculations and memory usage.
Add self._remote_hosts to cache remote hosts distance, self._non_local_rack_hosts for non-local rack host distance.
- Only cache `_remote_hosts` to efficiently handle `used_hosts_per_remote_dc`.
- Optimize control plane operations (`on_up`, `on_down`) to only rebuild the remote cache when necessary (when remote hosts change or local DC changes).
- Snapshot `self._remote_hosts` to a local variable before reads for GIL-free Python 3.13+ safety.
Benchmark (100K queries, 45-node/5-DC topology, Python 3.14, median of 5 runs):
Policy | Kops/s | vs master | delta | Mem KB
-----------------------------------------------------------------
DCAware | 188 | +77% | | 1.5
RackAware | 146 | +115% | +115% | 2.0
TokenAware(DCAware) | 20 | +11% | | 1.7
TokenAware(RackAware) | 19 | +12% | +19% | 2.2
Default(DCAware) | 123 | +35% | | 1.6
HostFilter(DCAware) | 57 | +8% | | 1.7
RackAware more than doubles throughput (+115%), from 68 to 146 Kops/s.
TokenAware(RackAware) also benefits transitively (+12% cumulative).
Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>1 parent 888cd02 commit f962afe
2 files changed
Lines changed: 72 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| 373 | + | |
| 374 | + | |
373 | 375 | | |
374 | 376 | | |
375 | 377 | | |
| |||
380 | 382 | | |
381 | 383 | | |
382 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
383 | 403 | | |
384 | 404 | | |
385 | 405 | | |
| |||
393 | 413 | | |
394 | 414 | | |
395 | 415 | | |
| 416 | + | |
| 417 | + | |
396 | 418 | | |
397 | 419 | | |
398 | | - | |
399 | 420 | | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | 421 | | |
| 422 | + | |
| 423 | + | |
404 | 424 | | |
405 | 425 | | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
| 426 | + | |
| 427 | + | |
413 | 428 | | |
414 | | - | |
415 | | - | |
| 429 | + | |
416 | 430 | | |
417 | 431 | | |
418 | 432 | | |
419 | 433 | | |
420 | 434 | | |
421 | 435 | | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
427 | 441 | | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
436 | 448 | | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
| 449 | + | |
| 450 | + | |
442 | 451 | | |
443 | 452 | | |
444 | 453 | | |
445 | 454 | | |
446 | 455 | | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | 456 | | |
451 | 457 | | |
452 | 458 | | |
453 | 459 | | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
454 | 469 | | |
455 | 470 | | |
456 | 471 | | |
457 | 472 | | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | 473 | | |
466 | 474 | | |
467 | 475 | | |
| |||
470 | 478 | | |
471 | 479 | | |
472 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
473 | 494 | | |
474 | 495 | | |
475 | 496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
277 | 287 | | |
278 | 288 | | |
279 | 289 | | |
| |||
0 commit comments