(payload: dict[str, Any])
| 432 | daemon=True, |
| 433 | ) |
| 434 | monitor_thread.start() |
| 435 | |
| 436 | dispatched: dict[int, dict[str, Any]] = {} |
| 437 | completions: list[dict[str, Any]] = [] |
| 438 | |
| 439 | next_worker = 0 |
| 440 | |
| 441 | def _dispatch(payload: dict[str, Any]) -> None: |
| 442 | nonlocal next_worker, global_first_send_ts |
| 443 | req_metrics = payload.setdefault("request_metrics", {}) |
| 444 | request_id = int(req_metrics.get("request_id", len(dispatched))) |
| 445 | req_metrics["request_id"] = request_id |
| 446 | req_metrics.setdefault("client_send_ts", time.time()) |
| 447 | if global_first_send_ts is None: |
| 448 | global_first_send_ts = time.time() |
| 449 | req_metrics["global_first_send_ts"] = global_first_send_ts |
| 450 | |
| 451 | if cooperative_parallel: |
| 452 | dispatch_ts = time.time() |
| 453 | for worker_id in range(worker_count): |
| 454 | recv_port = args.worker_base_port + worker_id |
| 455 | req_mgr.send("127.0.0.1", recv_port, payload) |
| 456 | dispatched[request_id] = { |
| 457 | "worker_id": "cooperative_group", |
| 458 | "dispatch_ts": dispatch_ts, |
| 459 | "payload": payload, |
| 460 | } |
| 461 | logger.info("[dispatch] request_id={} -> cooperative workers [0..{}]", request_id, worker_count - 1) |
| 462 | return |
| 463 | |
| 464 | worker_id = next_worker % worker_count |
| 465 | next_worker += 1 |
| 466 | recv_port = args.worker_base_port + worker_id |
| 467 | |
| 468 | dispatch_ts = time.time() |
| 469 | req_mgr.send("127.0.0.1", recv_port, payload) |
| 470 | dispatched[request_id] = { |
| 471 | "worker_id": worker_id, |
no test coverage detected