Memory and the Retention Limit
What a Detector holds in memory follows from its Rules, not from how long it runs. Values of Channels that no Rule uses are ignored and leave no trace.
What a Detector retains
- A Channel used by a Rule: its latest value.
averageOverSamples(n): the lastnvalues.build()rejects annabove the Retention Limit.averageOverDuration(w): every value withinw, at most the Retention Limit.count(...).within(w): one timestamp per Confirmed Event withinw, at most the Retention Limit, History included.- Everything else: a constant amount per Rule. A running Event keeps Aggregates only for the Channels its Rule aggregates, so memory stays bounded however long an Event lasts.
detector.retainedValues() returns the number of entries held right now (Channel values, moving-average values and count timestamps). It is a plain counter read, cheap enough to poll as a metrics gauge.
The Retention Limit
The Retention Limit caps every averageOverDuration window and every count(...).within(...) list of confirmation timestamps. It is 1,000,000 entries by default, about 16 MB per window; set it with Detector.builder().retentionLimit(n).
When a full window gets a new value, its oldest entry is dropped as if it had left the window by time. Detection continues:
- the moving average is the mean of the entries that remain;
- a count becomes a lower bound: it is at most the limit, so a Condition with a threshold at or above the limit, such as
count(run).within(...).above(limit), can never hold.
The first drop logs one WARNING through System.Logger, naming the Rule and the limit. detector.droppedValues() returns how many entries were dropped because of the limit (not those that left a window by time), for example to alert on.
The Errors and validation page shows what build() and retentionLimit reject: an average over more Samples than the Retention Limit, and a limit below one.
Reference
- Memory and Performance in the README, the canonical text
- Detector and Detector.Builder in the Javadoc
Methods used: ChannelExpression.averageOverSamples, ChannelExpression.averageOverDuration, Conditions.count, EventCount.within, Detector.builder, Detector.Builder.retentionLimit, Detector.Builder.build, Detector.retainedValues, Detector.droppedValues.