cadet.roles¶
Generic multi-connection server runtime.
- What this is for:
Accepts many concurrent client connections, each with its own reader + delay line, all feeding ONE shared request queue in front of a single model. A scheduler (
fifodefault, orround_robinacross clients) picks the next request; the model processes it and the reply goes back on the originating connection (through that connection’s reverse delay line, if any).- What it contains:
Request,_FifoScheduler,_RoundRobinScheduler.ServerRuntime: accept loop + feeder-per-connection + scheduler loop; records per request the queue wait, inference time and queue depth at enqueue.
- How it fits into CADET:
cadet serve <config>; the server node’s
schedulerfield picks the policy. Per-request metrics are written tooutputs/<experiment>/<app>/server_metrics.csv(used by the concurrent-load experiments).System metrics. When
metrics.collectorsnames them, this runtime also runs the per-node collectors (cadet.metrics.collectors) for its own node, around the serving loop, writing<collector>_<node>.csvinto the run directory. If theenergycollector is among them, each per-request record additionally carries that inference’s own energy: the collector is asked for the average power over the window the request was being processed in, on the same monotonic clock the record’sinference_sis measured on, so the attribution needs no second alignment step. Default is no collectors, and then nothing here changes.
- class cadet.roles.server.Request(client_id, payload, transport)¶
Bases:
objectOne client request waiting for the model, tagged with its client id.
- client_id¶
- payload¶
- transport¶
- enqueue_time¶
- depth¶
- drops¶
- class cadet.roles.server.PeerModels(config, node_name, seed=None, log=None)¶
Bases:
objectThe network models for each connection into one node, by its peer.
A node can be the far end of several paths at once - N sensors into one gateway, an ego and a roadside feed into one server - and those paths are not the same link. The server used to resolve one path and hand the same hops to every connection, varying only the RNG stream, so a cell whose uplinks differed could not be expressed: the difference was configured and then ignored.
Call it as
(client_id, peer_ip)for a plain accept loop, or passfor_source()tocadet.core.transport.MultiConnectionEndpoint.serve()as itsmodel_for, which is the fan-in form. Each connection gets fresh models with their own RNG stream, seeded from the experiment seed so a run stays reproducible.Peers are told apart by address, which is what a connection carries. Two client nodes on one host therefore cannot be distinguished, and they share the first path declared into this node; that is logged rather than hidden, because the alternative - the client naming itself in band - is a wire change and this is not the place to make one.
- for_source(source_id)¶
model_forforMultiConnectionEndpoint:"ip:port"in.
- class cadet.roles.server.ServerRuntime(host, port, model_factory, app, logger, warmup=True, extra_processing_s=0.0, node=None, scheduler='fifo', metrics_path=None, inbound_max_pending=None, server_delay_mode='blocking', collectors=None, expect=1, protocol='tcp', mode='frame', inbound_block_at=None)¶
Bases:
objectMulti-connection server: concurrent readers -> scheduler -> one model.
- run()¶
- Return type:
None
- cadet.roles.server.build_server(config_path, overrides, run_index, model_dirs, logger=None, node_name=None, rep=0, bind_host=None)¶
Build a
ServerRuntimefor one run from a config file.node_nameselects which server node to bind (needed when a config has more than one server); it falls back to the first node with roleserver.repnames the repetition, because the per-request metrics and the per-node metrics CSVs are written into that repetition’s run directory and two reps of one config would otherwise write to one file.bind_hostoverrides the address this server listens on, leaving the config alone. It exists for a role whose container does not hold the address its peers use: a node on another machine is reached at that machine’s address and its container has to listen on one of its own. It cannot be a config override, because the config is hashed into the run id and the orchestrator and the role would then disagree about which run this is.- Parameters:
config_path (str)
overrides (List[str])
run_index (int)
model_dirs (List[str])
rep (int)
bind_host (str | None)
Generic client runtime (paper Fig. 1(b)).
- What this is for:
Drives one client run through the pipeline stages (source, frame processing, transport, action translation, metric collection), delegating the per-stage behaviour to an app plugin’s client hooks.
- What it contains:
RunContext: the shared handles (config, source, transport, output).ClientRuntime: the staged loop.build_client(): assemble context + app for a config/run from the CLI.
- How it fits into CADET:
cadet client <config> –node client [–run N] [–rep R] calls
build_client()thenClientRuntime.run(). The app (e.g.examples.braking.flat.app) supplies control/encoding/metrics; the source iscadet.sources.carla.CarlaSource.System metrics. When
metrics.collectorsnames them, the runtime also runs the per-node collectors (cadet.metrics.collectors) for this client’s node, around the loop, writing<collector>_<node>.csvinto the run directory. Default is no collectors, and then nothing here changes.
- cadet.roles.client.client_outcome_file(node_name)¶
Return the outcome file name for a client node.
- Return type:
str
- cadet.roles.client.scene_timeout_for(config)¶
Return how long this config’s client should wait for the scene.
- Return type:
float
- class cadet.roles.client.RunContext(config, source, transport, run_id, rep, out_dir, log)¶
Bases:
objectHandles shared between the runtime and the app for one run.
- class cadet.roles.client.ClientRuntime(ctx, app, server_host, server_port, node=None, server_label=None, client_start='after_scenario', scene_timeout_s=120.0, collectors=None)¶
Bases:
objectRuns the client loop until the app reports it is done.
- Parameters:
ctx (RunContext)
client_start (str)
scene_timeout_s (float)
- run()¶
- Return type:
None
- property node_name: str¶
This client’s node name, which its records are keyed by.
- cadet.roles.client.build_client(config_path, overrides, run_index, rep, logger=None, node_name=None)¶
Build a
ClientRuntimefor one run from a config file.node_nameselects which client node this process is, the waycadet.roles.server.build_server()already did for servers. Without it every client process in a run believed it was the first client node: the flag existed oncadet clientand was never passed through, so with N clients they shared one identity, one outcome file and one link report.- Parameters:
config_path (str)
overrides (List[str])
run_index (int)
rep (int)
Load generator role: N synthetic clients at a configured rate -> server(s).
- What this is for:
Drives concurrent-load experiments. A
loadnode describes N synthetic clients, a send rate, and an arrival process (constant or Poisson). Each client connects to everyservernode (fan-out) and sends frames in the reference-app wire format, recording round-trip latency. Combined with the server’s per-request metrics (queue wait vs load), this measures contention.- What it contains:
LoadRunner: spawn clients, send at rate, collect latencies.build_load(): construct from a config.
- How it fits into CADET:
cadet load <config> --app-module examples.reference.app. Targets allservernodes in the config:clients=10, servers=[s]is 10->1;clients=1, servers=[s1,s2]is 1->2.
- class cadet.roles.load.LoadRunner(config, csv_path, logger=None)¶
Bases:
objectRuns a fleet of synthetic clients against the config’s server nodes.
- run()¶
- Return type:
None
- cadet.roles.load.build_load(config_path, overrides, run_index, logger=None)¶
Construct a
LoadRunnerfrom a config file.- Parameters:
config_path (str)
overrides (List[str])
run_index (int)
Shared wiring for the client/server runtimes.
- What this is for:
Small helpers both role runtimes use: select one run config from a file (overrides + sweep run index), look up nodes/links, and prepare the output directory (creating it and saving the resolved config alongside results).
- What it contains:
select_run_config()-> (config, run_id_base)output_dir()(pure path),prepare_output_dir()(creates it)StopSignal: turn the orchestrator’s stop signal into a flag a role’s own loop can act on, so it reaches its own shutdown path, and then hand the process back to the signal so its exit status still says what happened to it
- How it fits into CADET:
Used by
cadet.roles.clientandcadet.roles.server. Output paths come only from the resolved config’soutputssection — never a curated results directory.
- class cadet.roles.common.StopSignal¶
Bases:
objectA role’s stop signal: first a flag its own loop acts on, then its exit.
The orchestrator stops a role with SIGTERM and escalates to SIGKILL after a grace. Python’s default action for SIGTERM ends the process at once, so a role that is stopped rather than finishing by itself never ran its own shutdown path: a server’s
finallydid not execute and its per-request metrics were never written. Measured: the braking app wroteserver_metrics_*.csvbecause its app stops the loop itself after the brake, while the reference app, whose server waits for work until it is stopped, produced none at all.install()makes the handler set a flag throughon_stop; the loop notices on its next turn and unwinds normally. Raising from the handler would skip the same shutdown path by another route, which is also why the loop’s wait has to be bounded rather than indefinite.finish()then hands the process back to the signal, so its exit status is the one a signalled process has. That is not cosmetic: the orchestrator reads a worker’s exit code during the active phase to tell a guard that finished its job (code 0 - the braking server is single-shot by design) from one that died under it (non-zero -node exited unexpectedly). A server that flushed its records and then exited 0 would make an operator’skilllook like a clean finish, which is exactly the failure the lifecycle matrix exists to catch.Signals can only be installed from the main thread, and a role process is one process per role, so this is used from the role’s own
run. Off the main thread (a test driving a runtime in-process)install()is a no-op rather than an error, andfinish()then has nothing to do.- install(on_stop, log=None)¶
Install the handler for SIGTERM and SIGINT.
- Return type:
None- Parameters:
on_stop (Callable[[], None])
- finish()¶
Exit as a signalled process, now that the records are written.
- Return type:
None
- cadet.roles.common.select_run_config(path, overrides, run_index)¶
Load + override + expand a config and return the
run_index-th run.Returns
(config, run_id_base)whererun_id_baseis the config hash (the per-repetition-r<rep>suffix is added by the caller).- Return type:
Tuple[Config,str]- Parameters:
path (str)
overrides (List[str])
run_index (int)
- cadet.roles.common.node_by_role(config, role)¶
Return the first node with
role(orNone).- Parameters:
config (Config)
role (str)
- cadet.roles.common.link_into_node(config, node_name)¶
Return the first link whose
toendpoint isnode_name(orNone).- Parameters:
config (Config)
node_name (str)
- cadet.roles.common.output_dir(config, run_id)¶
Return the output directory path for a run (does not create it).
Directory =
outputs.root/<outputs.naming formatted>. Kept pure so the orchestrator can locate a run’s outputs (e.g. for resume) without side effects.- Return type:
str- Parameters:
config (Config)
run_id (str)
- cadet.roles.common.prepare_output_dir(config, run_id)¶
Create the output directory for this run and save the resolved config.
Directory =
output_dir(). The resolved config is written asconfig.yamlnext to the results.- Return type:
str- Parameters:
config (Config)
run_id (str)