Skip to content

Sink & Counter

Built-in result collectors for tracking events and latency.

Common reusable entities for simulations.

Provides ready-made Sink and Counter entities that eliminate the need to write boilerplate event-collecting classes in every example or test.

Sink

Sink(name: str = 'Sink')

Bases: Entity

Event collector with latency tracking.

Computes per-event latency from context["created_at"]. When that key is missing the latency is recorded as 0.

Attributes:

Name Type Description
events_received int

Total number of events handled.

latencies_s list[float]

Per-event latency in seconds (same order as arrival).

completion_times list[Instant]

Simulation Instant when each event arrived.

average_latency

average_latency() -> float

Mean latency across all received events.

latency_time_series_seconds

latency_time_series_seconds() -> tuple[
    list[float], list[float]
]

Return (completion_times_s, latencies_s) for plotting.

latency_stats

latency_stats() -> dict

Summary statistics over all recorded latencies.

Returns a dict with keys: count, avg, min, max, p50, p99.

Counter

Counter(name: str = 'Counter')

Bases: Entity

Simple event counter that tallies events by type.

Attributes:

Name Type Description
total int

Total events received.

by_type dict[str, int]

Mapping from event_type string to count.