Commit 1757460
committed
[KVCache][Feature] implement storage prefetch ZMQ pipeline in Scheduler and Worker
Storage prefetch (Storage → CPU) previously had no runtime execution path in
Scheduler/Worker: the Scheduler prepared host-block metadata but the actual
data transfer was never triggered. Workers also had no mechanism to receive
prefetch commands or report completion, leaving LOADING_FROM_STORAGE blocks
permanently stuck and never promoted to HOST.
- Add `_prefetch_node_map: Dict[int, BlockNode]` to track in-flight blocks by
host_block_id for O(1) status lookup.
- `prepare_prefetch_metadata`: register returned nodes into `_prefetch_node_map`.
- New `update_storage_blocks_to_host(host_block_ids)`: transition
LOADING_FROM_STORAGE → HOST after all TP workers confirm transfer done.
- New `abort_prefetch_blocks(host_block_ids)`: remove nodes from RadixTree and
release host pool blocks on transfer failure.
- Add per-worker ZMQ PUSH/PULL servers (`_prefetch_cmd_servers`,
`_prefetch_done_servers`), one pair per TP worker, keyed by local_rank.
- `_init_prefetch_zmq_servers()`: initialize servers at startup when storage
backend is configured.
- `_prefetch_storage_cache()`: after inserting host blocks, serialize
`StorageMetadata` and broadcast to all TP workers via ZMQ PUSH; then poll
PULL done sockets until all workers reply, call
`update_storage_blocks_to_host` on success or `abort_prefetch_blocks` on
failure.
- Add `receive_pyobj_once(block=False)`: non-blocking (or blocking) receive
helper returning `(error, data)` tuple; used by Scheduler to poll done
messages and by Worker in the prefetch loop.
- Add `init_prefetch_zmq_clients()`: connect ZMQ PULL/PUSH clients to
Scheduler servers for this worker's local_rank; start daemon
`_prefetch_loop` thread.
- `_prefetch_loop()`: background thread receiving `StorageMetadata` commands,
calling `cache_controller.prefetch_from_storage`, waiting for
`AsyncTaskHandler.wait`, and replying with ok/error status.
- Add `TestUpdateStorageBlocksToHost` with 6 test cases covering:
status transition, multi-block, unknown id, empty list, wrong status,
and initial-empty-map assertions.
No additional build steps. Enable storage prefetch via existing config:
```bash
python -m fastdeploy.entrypoints.openai.api_server \
--kvcache-storage-backend <backend> \
--enable-prefix-caching \
...
```1 parent ed97063 commit 1757460
5 files changed
Lines changed: 412 additions & 10 deletions
File tree
- fastdeploy
- cache_manager/v1
- engine/sched
- inter_communicator
- worker
- tests/cache_manager/v1
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
110 | 114 | | |
111 | 115 | | |
112 | 116 | | |
| |||
1004 | 1008 | | |
1005 | 1009 | | |
1006 | 1010 | | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
1007 | 1015 | | |
1008 | 1016 | | |
1009 | 1017 | | |
1010 | 1018 | | |
1011 | 1019 | | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
1012 | 1084 | | |
1013 | 1085 | | |
1014 | 1086 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
252 | 254 | | |
253 | 255 | | |
254 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
255 | 267 | | |
256 | 268 | | |
257 | 269 | | |
| |||
1264 | 1276 | | |
1265 | 1277 | | |
1266 | 1278 | | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
1267 | 1302 | | |
1268 | 1303 | | |
1269 | 1304 | | |
| |||
1274 | 1309 | | |
1275 | 1310 | | |
1276 | 1311 | | |
1277 | | - | |
1278 | | - | |
| 1312 | + | |
| 1313 | + | |
1279 | 1314 | | |
1280 | 1315 | | |
1281 | 1316 | | |
1282 | 1317 | | |
| 1318 | + | |
1283 | 1319 | | |
1284 | 1320 | | |
1285 | 1321 | | |
1286 | 1322 | | |
1287 | 1323 | | |
1288 | 1324 | | |
1289 | | - | |
1290 | | - | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
1291 | 1328 | | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
1295 | 1410 | | |
1296 | | - | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1297 | 1420 | | |
1298 | 1421 | | |
1299 | 1422 | | |
| 1423 | + | |
1300 | 1424 | | |
1301 | 1425 | | |
1302 | 1426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
146 | 168 | | |
147 | 169 | | |
148 | 170 | | |
| |||
0 commit comments