Commit fd2aa3f
authored
[Performance][PD] Parallelize KV cache receive via ThreadPoolExecutor (vllm-project#10548)
### What this PR does / why we need it?
## Summary
This PR improves KV cache receive throughput in PD disaggregation by
running independent receive work concurrently while preserving FIFO
ordering for the same remote peer.
The original `KVCacheRecvingThread` processed every transfer task
sequentially:
```python
request_data = self.request_queue.get()
self._handle_request(request_data)
```
That makes unrelated transfers block behind each other. Under concurrent
PD traffic, tasks from different prefill ranks can queue behind a slow
transfer even though they target independent remote peers and can safely
progress in parallel.
The final implementation dispatches through a per-peer FIFO scheduler:
- requests for the same `(remote_host, remote_handshake_port)` are
serialized;
- requests for different peers can run concurrently in the existing
`ThreadPoolExecutor(max_workers=32)`;
- a busy peer yields after a small batch so it cannot monopolize
executor workers;
- request completion accounting waits for all submitted transfer tasks
before marking the request done.
## Main changes
1. **Parallel KV receive with per-peer FIFO**
`KVCacheRecvingThread.run()` now records a request as submitted and
queues it by remote peer. Each active peer has at most one handler
running, so REQ/REP ordering for that peer is preserved while
independent peers can transfer concurrently.
2. **Bounded peer handler batch**
`MAX_REQUESTS_PER_PEER_HANDLER = 5` prevents one busy peer from holding
an executor worker forever when other peers are already waiting.
3. **Thread-safe shared state**
- removes the shared `zmq.Poller` receive path and uses per-socket
`RCVTIMEO`;
- protects `proc_not_transfer_request` with a lock;
- closes and discards failed REQ sockets instead of returning invalid
sockets to the pool;
- protects remote metadata cache population/readout with
`remote_metadata_lock`;
- tracks pending transfer tasks per request before calling
`task_tracker.update_done_task_count()`.
## Latest E2E validation
Test date: 2026-06-29.
Setup:
- 4-node DeepSeek V4 PD deployment, 32 NPUs total
- Prefill: DP4TP8
- Decode: TP4DP8
- Requests sent from `dev0` to `localhost:9000`; proxy forwards to
prefill/decode
- Workload: 500 requests, max concurrency 48, input length 256
- Baseline: PR changes fully reverted to merge-base for comparison
- Current: this PR head
- Timing data was collected with temporary measurement scaffolding
during validation; that scaffolding is not included in the final patch.
### Request-level result
| Metric | Baseline | Current | Change |
|---|---:|---:|---:|
| OK | 500/500 | 500/500 | no errors |
| Total time | 12.6s | 12.5s | -0.8% |
| Request p50 | 0.96s | 0.97s | roughly flat |
| Request p99 | 3.44s | 3.10s | -9.9% |
### KV receive timing
Aggregate across decode nodes, 2000 KV receive tasks per run:
| Metric | Baseline | Current | Change |
|---|---:|---:|---:|
| queue p50 | 18.14ms | 0.70ms | improved |
| queue p90 | 237.79ms | 1.87ms | improved |
| queue p99 | 603.63ms | 2.64ms | -99.56% |
| lifecycle p99 | 735.16ms | 512.80ms | -30.25% |
| active handler max | 1 | 7 | parallel receive active |
Per-node queue p99:
| Decode node | Baseline | Current | Change |
|---|---:|---:|---:|
| dev2 | 602.23ms | 4.11ms | -99.32% |
| dev3 | 595.88ms | 2.41ms | -99.60% |
The queue tail result is consistent with the earlier validation data:
queue p99 drops from hundreds of milliseconds to single-digit
milliseconds, showing that the tail was caused by serialized receive
handling.
## How was this patch tested?
- `pre-commit run ruff-check --all-files`
- `pre-commit run ruff-format --all-files`
- `git diff --check`
- `python3 -m py_compile
vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_connector.py
vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_hybrid_connector.py`
- `python3 -m pytest tests/ut/kv_offload/test_mooncake_connector.py
tests/ut/kv_offload/test_mooncake_hybrid_connector.py -q`
- Result: 86 passed, 16 warnings
- Full 4-node E2E restart and proxy benchmark:
- baseline: 500/500 OK
- current: 500/500 OK
- Log scan after E2E found no `ZMQError`, `EFSM`, `Traceback`, duplicate
done signal, request loss, or address conflict errors.
### Does this PR introduce any user-facing change?
No. This changes internal KV receive scheduling and synchronization
only.
- vLLM version: v0.23.0
- vLLM main:
vllm-project/vllm@dc68bd8
---------
Signed-off-by: Zheng Shoujian <zheng.shoujian@outlook.com>1 parent 2a0b0b3 commit fd2aa3f
4 files changed
Lines changed: 480 additions & 94 deletions
File tree
- tests/ut/kv_offload
- vllm_ascend/distributed/kv_transfer/kv_p2p
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
510 | 511 | | |
511 | 512 | | |
512 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
513 | 607 | | |
514 | 608 | | |
515 | 609 | | |
| |||
534 | 628 | | |
535 | 629 | | |
536 | 630 | | |
537 | | - | |
538 | 631 | | |
539 | 632 | | |
540 | 633 | | |
| |||
552 | 645 | | |
553 | 646 | | |
554 | 647 | | |
555 | | - | |
| 648 | + | |
| 649 | + | |
556 | 650 | | |
557 | 651 | | |
558 | 652 | | |
| |||
564 | 658 | | |
565 | 659 | | |
566 | 660 | | |
567 | | - | |
568 | 661 | | |
569 | 662 | | |
570 | 663 | | |
| |||
798 | 891 | | |
799 | 892 | | |
800 | 893 | | |
801 | | - | |
| 894 | + | |
802 | 895 | | |
803 | 896 | | |
804 | 897 | | |
805 | 898 | | |
806 | 899 | | |
807 | 900 | | |
808 | 901 | | |
809 | | - | |
| 902 | + | |
810 | 903 | | |
811 | 904 | | |
812 | 905 | | |
| |||
820 | 913 | | |
821 | 914 | | |
822 | 915 | | |
823 | | - | |
| 916 | + | |
824 | 917 | | |
825 | 918 | | |
826 | 919 | | |
827 | 920 | | |
828 | 921 | | |
829 | 922 | | |
830 | | - | |
| 923 | + | |
| 924 | + | |
831 | 925 | | |
832 | 926 | | |
833 | 927 | | |
| |||
1335 | 1429 | | |
1336 | 1430 | | |
1337 | 1431 | | |
1338 | | - | |
| 1432 | + | |
1339 | 1433 | | |
1340 | 1434 | | |
1341 | 1435 | | |
| |||
1348 | 1442 | | |
1349 | 1443 | | |
1350 | 1444 | | |
1351 | | - | |
| 1445 | + | |
1352 | 1446 | | |
1353 | 1447 | | |
1354 | 1448 | | |
| |||
1361 | 1455 | | |
1362 | 1456 | | |
1363 | 1457 | | |
1364 | | - | |
| 1458 | + | |
1365 | 1459 | | |
1366 | 1460 | | |
1367 | 1461 | | |
| |||
1374 | 1468 | | |
1375 | 1469 | | |
1376 | 1470 | | |
1377 | | - | |
| 1471 | + | |
1378 | 1472 | | |
1379 | 1473 | | |
1380 | 1474 | | |
| |||
1387 | 1481 | | |
1388 | 1482 | | |
1389 | 1483 | | |
1390 | | - | |
| 1484 | + | |
1391 | 1485 | | |
1392 | 1486 | | |
1393 | 1487 | | |
| |||
1400 | 1494 | | |
1401 | 1495 | | |
1402 | 1496 | | |
1403 | | - | |
| 1497 | + | |
1404 | 1498 | | |
1405 | 1499 | | |
1406 | 1500 | | |
| |||
1413 | 1507 | | |
1414 | 1508 | | |
1415 | 1509 | | |
1416 | | - | |
| 1510 | + | |
1417 | 1511 | | |
1418 | 1512 | | |
1419 | 1513 | | |
| |||
1578 | 1672 | | |
1579 | 1673 | | |
1580 | 1674 | | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
1585 | | - | |
| 1675 | + | |
1586 | 1676 | | |
1587 | 1677 | | |
1588 | 1678 | | |
1589 | 1679 | | |
1590 | 1680 | | |
1591 | | - | |
1592 | | - | |
| 1681 | + | |
1593 | 1682 | | |
1594 | | - | |
| 1683 | + | |
1595 | 1684 | | |
1596 | 1685 | | |
1597 | 1686 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
| |||
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
| |||
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
36 | 151 | | |
37 | 152 | | |
38 | 153 | | |
| |||
0 commit comments