ts_client/config.rs
1// Copyright (c) 2026 LightSeek Foundation
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21//! Client configuration. Every field selects behavior, so none has a default.
22
23use std::time::Duration;
24
25/// How requests are assigned to engines (one engine per attention-DP rank).
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub enum Routing {
28 /// Aggregated serving. A request's `data_parallel_rank` pins it to that
29 /// rank; other requests are placed by the policy.
30 Aggregated(LoadBalance),
31 /// Prefill/decode disaggregation: rank `bootstrap_room % num_engines`,
32 /// the rule both roles apply so a request's KV lands on the matching
33 /// rank. Every request must carry a `bootstrap_room`.
34 BootstrapRoom,
35}
36
37/// Placement policy for unpinned requests in aggregated serving.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum LoadBalance {
40 /// Cycle through the engines.
41 RoundRobin,
42 /// The engine with the fewest of this client's requests in flight.
43 LeastInFlight,
44 /// The engine whose latest reported load holds the fewest KV pages,
45 /// then the fewest of this client's requests in flight.
46 MinimumCacheUsage,
47}
48
49/// Where the client listens and which engines it expects.
50#[derive(Debug, Clone)]
51pub struct ClientConfig {
52 /// Handshake ROUTER address the engines dial: the engine's
53 /// `tcp://{--data-parallel-address}:{--data-parallel-rpc-port}`.
54 /// `tcp://<host>:0` binds a free port; see [`crate::ClientListener`].
55 pub handshake_address: String,
56 /// Input ROUTER address. `tcp://<host>:0` binds a free port; the bound
57 /// address is sent to the engines, so `<host>` must be reachable from
58 /// them.
59 pub input_address: String,
60 /// Output PULL address, bound like `input_address`.
61 pub output_address: String,
62 /// The first engine's index, the engine's `--zmq-engine-index`.
63 pub first_engine_index: u16,
64 /// Engines to wait for: indices `first_engine_index..+num_engines`, one
65 /// per attention-DP rank.
66 pub num_engines: u16,
67 /// Request placement.
68 pub routing: Routing,
69 /// Limit for the handshake, from the start of
70 /// [`crate::ClientListener::accept`] to the last registration.
71 pub handshake_timeout: Duration,
72 /// Limit for handing one message to an engine's socket. A stalled
73 /// engine fails the submission instead of blocking the caller.
74 pub send_timeout: Duration,
75}