Server¶
The high-level server. Handles pytree flattening on submit(), unflattening
on sample(), and owns the underlying Rust _Server.
The example pytree passed to Server defines the shape and dtype of every
leaf, and the server will only accept samples that match it exactly. The
matching client must be constructed with a pytree of the same structure
and per-leaf shape/dtype, and every client.send(...) call must pass a
pytree with those exact shapes too. Mismatches are rejected at handshake
(by the client) or produce a hard size error inside send().
Server ¶
Server that handles pytree flattening/unflattening on top of the Rust core.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
example
|
Any
|
Example pytree with numpy arrays (used to infer structure) |
required |
batch_size
|
int
|
Number of samples per emitted batch |
required |
transport
|
TcpTransport | None
|
Optional TcpTransport. Omit for in-process use; call
|
None
|
num_buffers
|
int
|
Number of ring buffer batches (min 2, default 3) |
3
|
num_drainers
|
int
|
Number of threads draining from producer queues |
8
|
producer_queue_size
|
int
|
Per-connection queue size |
8
|
Lifetime: the numpy arrays returned by sample() are views into
Rust-owned ring-buffer memory. They are invalidated as soon as the next
batch reuses those slots, and the memory is freed when this Server is
garbage-collected. Don't keep references to a batch beyond the next
sample() call without np.copy, and don't drop the Server while you
still hold sample arrays.
Source code in python/echo/server.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 | |
start ¶
sample ¶
Block until a batch is ready. Returns None on shutdown.
Each leaf of Sample.batch is a zero-copy view into Rust-owned
memory and is invalidated on the next sample() call. Use
np.copy (or dataset_iter(copy=True)) if you need to retain a
batch beyond the next call.
Source code in python/echo/server.py
dataset_iter ¶
Yield Samples as batches become ready; returns on shutdown.
Pass copy=True to deep-copy each batch and free the underlying
ring slots for reuse on the next iteration.
Source code in python/echo/server.py
submit ¶
Submit a single sample directly to the store (in-process / tests).
close ¶
reset_histograms ¶
Reset the histogram fields on subsequent SampleInfo snapshots. Counters and gauges are unchanged.