Skip to content

Online mode

The back ends emit StreamingEvent objects of three kinds: change_point, verdict (provisional or final) and, from OnlineJitterbug with streaming.revise_change_points, revision (the last change point moved from revised_from to start_epoch). StateChangeTracker emits StateChangeEvent objects. See Online mode for the method and the measurements.

jitterbug.streaming.online_analyzer

Online (streaming) Jitterbug pipeline.

The sequential pipeline is retrospective twice over: the offline Bayesian detector sees the whole series, and the verdict for period i needs change point i + 1 to close the period. This module runs the same decision rule one RTT sample at a time:

  1. Minimum-RTT bins close when a sample from a later bin arrives (causal binning).
  2. Each closed bin feeds a Bayesian online change point detector (Adams & MacKay 2007, bayesian_changepoint_detection.streaming.OnlineChangepointDetector). A change point is declared when the MAP run length drops (default), or when the posterior that a segment started lag bins ago (lag) or within the last lag bins (window) exceeds a threshold. On the paper dataset the MAP rule recovers 14 of the 15 reference congestion periods with no spurious one, like the offline pipeline, and reports congestion onsets one bin (15 min) after they start. The fixed-delay rules recover 5 to 12 (lag) or 5 to 15 (window) of the 15 depending on the setting but always with 3 to 6 spurious congested periods, because the posterior mass of a change spreads over several run lengths (see docs/ONLINE_MODE.md).
  3. The stream start opens the baseline period. When a change point opens a new period, a provisional verdict is emitted as soon as the open period holds min_period_samples jitter samples. When the next change point closes the period, the final verdict is emitted with the full period, which is exactly what the sequential pipeline computes.

The MAP rule refines a boundary after first reporting it: a few bins later, the most probable segment start moves one to three bins later. Such a refinement is closer than streaming.min_time_elapsed to the change point it refines, so by default it is dropped. With streaming.revise_change_points it is reported as a revision event instead (start_epoch the new epoch, revised_from the old one): the open period starts at the revised epoch from then on, its provisional verdict is emitted again on the revised period, and its final verdict uses it. The stream start is never revised, and the final verdict of the period before, already emitted, keeps its end_epoch; consumers that want the period's revised end follow the revision.

Both jitter methods work online. The Kolmogorov-Smirnov test uses consecutive RTT differences and is causal as it stands. Jitter dispersion uses the trailing version of the offline filters (JitterAnalyzer.compute_causal_jitter_dispersion): same window lengths, each ending at the bin it describes, so its series is the offline one delayed by JitterAnalyzer.causal_dispersion_delay bins (6 bins, 1.5 h, by default). A dispersion value reflects the new period alone only after that delay, so a provisional verdict with dispersion waits until the open period holds delay + moving_average_order dispersion values (12 bins, 3 h, by default); with fewer, the provisional verdict is still dominated by the previous period's jitter (11 of 31 flipped on the paper dataset with 6, none with 12).

Settings live in JitterbugConfig.streaming (models.config.StreamingConfig); the bin width, latency jump threshold, significance level and device come from the shared sections of JitterbugConfig.

StreamingEvent dataclass

Something the online pipeline decided while consuming the stream.

change_point: a new period starts at start_epoch. verdict: a provisional or final verdict on the period that starts at start_epoch. revision: the last change point moved from revised_from to start_epoch (bocpd back end with streaming.revise_change_points); later events about that period use the new epoch.

emitted_at instance-attribute

Epoch of the sample whose arrival triggered the event.

start_epoch instance-attribute

Change point epoch, or start of the period a verdict is about.

jitter_method = None class-attribute instance-attribute

Jitter test behind has_jitter; the KS fields are set for ks_test only.

jitter_metric = None class-attribute instance-attribute

The jitter test's metric: the KS statistic, or the dispersion change.

revised_from = None class-attribute instance-attribute

For a revision: the epoch the change point had before it (start_epoch is the new one). None for every other kind.

delay property

Seconds between the event's reference time and its emission.

to_dict()

Return the event as a plain dictionary (JSON-serializable).

OpenPeriodBins dataclass

Closed minimum-RTT bins of the open period and of the period before it.

start_epoch instance-attribute

Start of the open period (the last emitted change point).

previous instance-attribute

Minimum RTT per closed bin of the previous period (ms).

current instance-attribute

Minimum RTT per closed bin of the open period so far, oldest first (ms).

OnlineJitterbug

Streaming congestion inference: feed RTT samples, get events.

Samples must arrive in non-decreasing epoch order; a sample earlier than the last one accepted is dropped (logged at DEBUG), whatever bin it falls in. Bins are indexed by the samples that arrive, so a gap in the stream does not produce empty bins: the detector sees the bins before and after a gap as consecutive, as the offline pipeline does after dropna in RTTDataset.compute_minimum_intervals.

Parameters:

Name Type Description Default
config JitterbugConfig

Full configuration; config.streaming holds the online-specific settings.

None

push(epoch, rtt)

Consume one RTT sample and return the events it triggered.

Parameters:

Name Type Description Default
epoch float

Unix timestamp of the sample, seconds.

required
rtt float

Round-trip time in milliseconds.

required

flush()

Close the open bin at the end of a finite stream.

open_period_bins()

Closed bins of the open period and of the previous one.

Read-only; used by StateChangeTracker for its early latency-jump estimate.

Returns:

Type Description
OpenPeriodBins or None

None until two change points (the stream start and one more) exist.

verdict_event(verdict, stage, emitted_at, start_epoch, end_epoch)

Wrap a PeriodVerdict as a verdict event.

jitterbug.streaming.window_backend

Sliding-window back end: rerun the offline pipeline as the stream grows.

The baseline the incremental detector is measured against. Every rerun_every_bins closed minimum-RTT bins, the sequential pipeline (JitterbugAnalyzer, with the configured detector and jitter method) runs on the trailing window_hours of raw samples. A change point is emitted once the detector has placed one within TOLERANCE_BINS of the same bin in stable_runs consecutive reruns; change points are emitted in time order and never retracted. Final verdicts form a contiguous chain: the next one is emitted once the offline pipeline has judged the period at the last emitted boundary identically (same verdict, boundaries within the tolerance) in stable_runs consecutive reruns and the change point that closes it has been emitted; its boundaries are those emitted change points, so change points and verdicts never disagree. If the window moves past a period before it stabilizes, that period is skipped with a warning and the chain resumes at the next emitted change point. A change point that only stabilizes after a later one was emitted is dropped (time order is kept), which can leave the chain waiting for the next emitted boundary for up to a window length. The open period after the last emitted change point gets a provisional verdict from the shared two-period rule, with the configured jitter method (trailing filters for dispersion), once it holds min_period_samples jitter samples, as in the incremental back end.

The window start opens the baseline period, as the stream start does in the incremental back end: when the detector reports no change point within one bin of the first bin, one is inserted there, so the first period after the window start can be judged (the sequential pipeline needs three change points per verdict). Once the window has moved past the stream start, change points and periods touching its left edge are ignored: they are cut by the window and were emitted long before.

TOLERANCE_BINS = 2 module-attribute

Two boundaries this many bins apart or closer are the same boundary (30 min at 15-min bins).

The offline detector moves a change point by a bin or two as the window slides; the sequential pipeline keeps change points at least change_point_detection.min_time_elapsed apart (two bins by default), so a larger tolerance would merge real boundaries.

SlidingWindowJitterbug

Streaming congestion inference by rerunning the offline pipeline on a window.

Same interface as OnlineJitterbug: push(epoch, rtt) returns the events the sample triggered, flush() closes the open bin and reruns once, events holds everything emitted. Samples must arrive in non-decreasing epoch order.

Parameters:

Name Type Description Default
config JitterbugConfig

streaming.window_hours, streaming.rerun_every_bins and streaming.stable_runs drive the back end; the detector and jitter method are those of the sequential mode (analysis_mode is forced to sequential).

None

push(epoch, rtt)

Consume one RTT sample (seconds, milliseconds) and return the events it triggered.

flush()

Close the open bin and rerun once, whatever the cadence.

open_period_bins()

Closed bins of the open period and of the previous one, within the window.

Read-only; used by StateChangeTracker for its early latency-jump estimate. The open bin and samples already pruned from the window are left out.

Returns:

Type Description
OpenPeriodBins or None

None until two change points (the stream start and one more) exist.

jitterbug.streaming.verdict

The two-period decision rule shared by the online back ends.

Given the minimum-RTT bins and the jitter observations of a period and of the period before it, decide whether the period is congested the way the sequential pipeline does: a latency jump is a rise of the mean minimum RTT above latency_jump.threshold; a jitter change is, with jitter_analysis.method: ks_test, a significant Kolmogorov-Smirnov test on the raw jitter samples with a statistic of at least streaming.min_ks_statistic, and with jitter_dispersion a rise of the mean dispersion (trailing filters, see JitterAnalyzer.compute_causal_jitter_dispersion) above jitter_analysis.threshold; the congestion state carries over: both → congested, no jump → not congested, jump without jitter change → unchanged.

PeriodVerdict dataclass

Outcome of two_period_verdict.

two_period_verdict(prev_bins, cur_bins, prev_jitter, cur_jitter, previous_state, config)

Classify a period against the one before it.

Parameters:

Name Type Description Default
prev_bins ndarray

Minimum RTT per bin of the previous and the current period (ms).

required
cur_bins ndarray

Minimum RTT per bin of the previous and the current period (ms).

required
prev_jitter ndarray

Jitter observations of the previous and the current period: consecutive RTT differences (ms) for ks_test, causal dispersion values for jitter_dispersion.

required
cur_jitter ndarray

Jitter observations of the previous and the current period: consecutive RTT differences (ms) for ks_test, causal dispersion values for jitter_dispersion.

required
previous_state bool

Congestion state after the previous period's final verdict.

required
config JitterbugConfig

latency_jump.threshold, jitter_analysis.method, jitter_analysis.threshold, jitter_analysis.significance_level and streaming.min_ks_statistic are used.

required

Returns:

Type Description
PeriodVerdict

The decision and the statistics behind it. Tests that could not run (too few observations) leave their fields None and the state unchanged.

jitterbug.streaming.state_changes

State changes of the path, reported early and corrected later.

The online back ends judge a period twice: a provisional verdict once the open period holds enough jitter observations (100 samples for the KS test, about 45 min; 12 dispersion values, 3 h, for dispersion) and a final verdict when the next change point closes it. StateChangeTracker adds an earlier, weaker signal on top of those events, without changing them.

The path is in one of two states, baseline or congested; the stream's first period is the baseline. A state change is a transition between them at a change point, and it has a status:

suspected Raised from the latency jump alone, before the jitter test has enough observations: once the period a change point opens holds streaming.state_change_bins closed minimum-RTT bins, each of them is compared with the mean minimum RTT of the previous period. If every one is more than latency_jump.threshold above it and the path is in baseline, a change to congested is suspected. If none is above it and the path is congested, a return to baseline is suspected: the two-period rule declares a period without a latency jump not congested, so the early rule is the latency-jump half of that rule in both directions. Mixed bins raise nothing; the verdicts decide. confirmed A provisional or final verdict puts the period in the suspected state. A verdict can also confirm a change nobody suspected (the first event of that change is then confirmed). retracted A verdict leaves the path where it was. A final verdict that contradicts the provisional one corrects it: retracted after confirmed, or confirmed after retracted.

Each change has a stable id (period start and direction), so every event about it can be matched. The period start in the id is the epoch at which the change point was first reported: when the back end revises that change point (a revision event, streaming.revise_change_points), the change keeps its id, change_epoch moves to the revised epoch, and every change of that period that is not retracted gets an update with its current status and revised_from set to the epoch it had before.

The state before a period is the latest evidence on the period before it (final verdict, else provisional verdict, else a suspected change, else the state before that); when that evidence changes, the changes after it are re-derived, so a change whose direction no longer holds is retracted.

Agreement with the verdicts is not ground truth: the verdicts are themselves the offline method's rule applied online. Users who want notifications can build them on these events; CommandHook runs a command per event, as jitterbug stream --on-state-change does.

MAX_TRACKED_PERIODS = 256 module-attribute

Periods kept for reconciliation; older ones are frozen (their changes can no longer move).

StateChangeEvent dataclass

One status update of a state change of the path.

id instance-attribute

Stable identifier of the change: <period start epoch>:<from>-><to>.

change_epoch instance-attribute

Start of the period the change opens (its change point).

emitted_at instance-attribute

Epoch of the sample whose arrival triggered this update.

suspected_at instance-attribute

When the change was first suspected; None if it never was.

confirmed_at instance-attribute

When a verdict first confirmed the change; None if none has.

stage instance-attribute

Evidence behind this update: the early latency jump or a verdict stage.

jump_magnitude instance-attribute

Mean minimum RTT of the bins used minus that of the previous period (ms).

jitter_metric = None class-attribute instance-attribute

The verdict's KS statistic or dispersion change; None for the early stage.

n_prev = 0 class-attribute instance-attribute

Observations of the previous period behind the evidence: minimum-RTT bins for the latency_jump stage, jitter observations for a verdict.

n_curr = 0 class-attribute instance-attribute

Same for the period the change opens.

revised_from = None class-attribute instance-attribute

On the update a change point revision caused: the change_epoch before it.

delay property

Seconds between the change point and this update.

to_dict()

Return the event as a plain dictionary (JSON-serializable).

StateChangeTracker

Follow an online back end and report state changes of the path.

Wraps OnlineJitterbug or SlidingWindowJitterbug: push and flush feed the back end and return its events together with the state-change events they caused. The back end's events are passed through unchanged.

Parameters:

Name Type Description Default
analyzer OnlineAnalyzer

The back end to follow; it must expose open_period_bins().

required
config JitterbugConfig

streaming.state_change_bins, latency_jump.threshold, jitter_analysis.method and data_processing.minimum_interval_minutes are used. Defaults to the back end's own configuration.

None

state property

Current state of the path, including suspected changes.

push(epoch, rtt)

Feed one sample to the back end.

Parameters:

Name Type Description Default
epoch float

Unix timestamp of the sample, seconds.

required
rtt float

Round-trip time in milliseconds.

required

Returns:

Type Description
tuple[list[StreamingEvent], list[StateChangeEvent]]

The back end's events for this sample and the state changes they caused.

flush()

Close the back end's open bin and report what that changed.

observe(events, now, check_early=True)

Update the state from a batch of back-end events.

Parameters:

Name Type Description Default
events list[StreamingEvent]

Events the back end emitted for one sample (or flush).

required
now float

Epoch of that sample; the emitted_at of the resulting updates.

required
check_early bool

Whether to evaluate the early rule on the open period (push does so when a bin closes, since the rule only looks at closed bins).

True

Returns:

Type Description
list[StateChangeEvent]

The state-change updates, in order.

CommandHook

Run a command once per state-change event, with the event as JSON on its stdin.

The command line is split with shlex.split and run without a shell, so nothing in the event can be interpreted by one. Commands run in the background: the stream does not wait for them. A command that cannot start or exits with a non-zero status is logged as a warning; one still running after timeout seconds is killed when poll (called before each new command, and by the CLI once per sample) or close next runs. Its standard output is discarded, since the stream's own standard output carries JSON; its standard error is inherited.

Parameters:

Name Type Description Default
command str

Command line, for example "notify-send-wrapper --path A".

required
timeout float

Seconds a command may run before it is killed.

60.0

poll()

Reap finished commands, log failures, kill the ones past the timeout.

close()

Wait for running commands (up to the timeout overall), killing the stragglers.

jitterbug.streaming.replay

Replay a finite RTT dataset through the online pipeline and score the result.

replay feeds every sample of an RTTDataset to the configured online back end in timestamp order and returns the events. score summarizes them: change points, periods, detection delays, provisional-to-final agreement and, when a reference file is given, agreement with it using the metric of tests/test_paper_regression.py (a reference congested period counts as recovered when one of ours overlaps more than half of it) and how many reference period boundaries have a change point within 30 min.

Delays are measured from the change point to the sample that reported it. Onset is the change point that opens a congested final period, return the one that closes it. With streaming.revise_change_points, revision events move change points; the scores use each change point's latest epoch and count the revisions.

replay_state_changes runs the same replay through StateChangeTracker and score_state_changes summarizes the state changes: how many were suspected, confirmed and retracted, how far ahead of the first verdict the suspicion came, and, with a reference, how many reference congested periods got a suspected onset.

replay(dataset, config=None)

Feed dataset sample by sample to the online pipeline.

Parameters:

Name Type Description Default
dataset RTTDataset

Samples to replay; they are sorted by epoch (stable) before being fed.

required
config JitterbugConfig

Configuration; config.streaming holds the online-specific settings, including which back end runs (backend).

None

Returns:

Type Description
list[StreamingEvent]

Every change point and verdict the pipeline emitted, in order, after flush.

replay_state_changes(dataset, config=None)

Feed dataset to the online pipeline through a StateChangeTracker.

Parameters:

Name Type Description Default
dataset RTTDataset

Samples to replay; they are sorted by epoch (stable) before being fed.

required
config JitterbugConfig

Configuration, as for replay; streaming.state_change_bins sets the early rule.

None

Returns:

Type Description
tuple[list[StreamingEvent], list[StateChangeEvent]]

The back end's events (identical to what replay returns) and every state-change update, in order, after flush.

load_reference(path)

Congested periods (start, end) of a reference CSV with starts,ends,congestion.

score(events, reference=None)

Summarize replay events.

Parameters:

Name Type Description Default
events list[StreamingEvent]

Output of replay.

required
reference Path

CSV with starts,ends,congestion columns (the paper's expected_results). Adds recovered, reference_congested, spurious and boundary placement: reference boundaries with a change point within 30 min and within 5 min (the same bin), and the median and mean distance from a reference boundary to the nearest change point (boundary_offset_min_*).

None

Returns:

Type Description
dict

Counts, delays in minutes and provisional-to-final agreement. Change point revisions are applied before scoring: boundaries, period ends and delays use the latest epoch of each change point. A boundary's delay is that of its first report (emitted_at minus the epoch first reported). revisions counts the revision events, revised_change_points the change points they moved, revision_shift_min_* how far (minutes, later in time), revision_lag_min_* how long after the change point was first reported. provisional_superseded counts provisional verdicts judged on a boundary that was revised afterward and provisional_superseded_changed those the provisional verdict on the revised boundary contradicted.

score_state_changes(events, state_changes, reference=None)

Summarize the state changes of a replay.

A change counts once per id; its outcome is its last status. Lead is the time from the first suspected update to the first verdict on the same period (the provisional one when there is one, else the final one); delay is the time from the change point to the suspicion.

Parameters:

Name Type Description Default
events list[StreamingEvent]

The back end's events from replay_state_changes.

required
state_changes list[StateChangeEvent]

The state-change updates from replay_state_changes.

required
reference Path

CSV with starts,ends,congestion columns. Adds reference_congested_suspected: reference congested periods with a suspected onset (baseline to congested) at most 30 min before their start or inside them, and suspected_onsets_outside_reference: suspected onsets that fall in none.

None

Returns:

Type Description
dict

Counts and times in minutes, keys prefixed state_changes_ or suspected_.

events_to_json(events, path)

Write events as a JSON array of plain dictionaries.