# Latency 4: Incidents

Source: https://obsvra.com/learn/simulation-101/simulation-lesson-latency-4

**Requires Pro** (Perturb)

### Problem statement

So far the service has been calm: every request is drawn from the same distribution, and the question was whether that distribution meets the SLO. A real service also has bad stretches. A bad deploy, a full disk or a failing dependency makes every request slow for a while, and then it is fixed. The team's alerting is supposed to notice. The questions in this lesson:

- How do you inject timed incidents into a model, and what do they do to the SLO?
- How do you read the incident state back out of the model?
- Does an alert rule notice the incidents, how late, and does it cry wolf?
- Does it matter whether an incident replaces the healthy latency or adds a delay to it?

The last question is a bridge back to testing. The model is a source of test data with known incidents in it, so anything that consumes a stream of latencies can be run against it. Here the thing under test is an alert rule, and the answer to "does it catch the incident?" is known for every row.

### The model

In the main model the incident is a second, slower latency that replaces the healthy one for a while. That is the default behavior of `Perturb`, which switches between the two; a later section shows the other mode, where the incident adds a delay to the healthy request. `Perturb` takes four inputs, each with a role:

- `normal`: the healthy branch.
- `disturbance`: the incident branch (here it replaces the healthy value; `mode="add"` adds it, see below).
- `wait`: how many requests pass between incidents.
- `duration`: how many requests an incident lasts.

`samples/pro/latency-incidents.xml` (seed 404):

```xml
<dataset columns="latency, inIncident" seed="404">
  <root node="Latency"/>
  <nodes>
    <Lognormal name="HealthyLatency" mu="3.4011973816621555" sigma="0.3" synchronous="true"/>
    <Lognormal name="DegradedLatency" mu="5.298317366548036" sigma="0.5" synchronous="true"/>
    <Constant name="Up" value="0" type="double"/>
    <Constant name="Down" value="1" type="double"/>
    <Append name="Healthy">
      <input name="HealthyLatency"/>
      <input name="Up"/>
    </Append>
    <Append name="Degraded">
      <input name="DegradedLatency"/>
      <input name="Down"/>
    </Append>
    <Exponential name="GapRaw" lambda="0.0002"/>
    <ToInteger name="Gap" mode="ceiling">
      <input name="GapRaw"/>
    </ToInteger>
    <Geometric name="IncidentLength" p="0.002"/>
    <Perturb name="Latency" repeat="true" synchronous="true">
      <input name="Healthy" role="normal"/>
      <input name="Degraded" role="disturbance"/>
      <input name="Gap" role="wait"/>
      <input name="IncidentLength" role="duration"/>
    </Perturb>
  </nodes>
</dataset>
```

- `HealthyLatency` is a lognormal with a median of 30 ms (`mu` is ln 30, the log-scale mean) and a narrow sigma of 0.3. Its mean is 31.4 ms and its exact p99 is 60.3 ms. The wide sigma of earlier lessons would have made the alert problem harder, and this lesson is about the incident, not the tail.
- `DegradedLatency` has a median of 200 ms and sigma 0.5: a mean of 226.6 ms, and 32.8% of its requests above the 250 ms line.
- `Gap` is the wait: an `Exponential` with rate 0.0002 (mean 5,000), rounded up to a whole number of requests by `ToInteger`. Rounding up makes the mean 5,000.5.
- `IncidentLength` is the duration: a `Geometric` with p = 0.002, which counts requests up from 1, so the mean is 500 and the shortest incident is one request.
- `Perturb` runs a cycle: wait, then incident, then wait, and so on (`repeat="true"`; with `repeat="false"` there would be a single incident and healthy requests after it). The wait counts requests that are healthy, and it starts again when an incident ends. So the gap between incidents is the wait itself, and a full cycle averages 5,000.5 + 500 = 5,500.5 requests. The first wait is read on the first row, not when the model loads, so the first incident can come at any time after the start. A duration is at least one request.
- The model has to report its own state. In its default mode `Perturb` outputs only the active branch, so the row would show a latency and nothing about which branch produced it. Each branch is therefore `Append`ed to a `Constant` flag, 0 for healthy and 1 for an incident. Column 0 is the latency in ms and column 1 is the flag. That is how any model reports its phase.

The file has 10 nodes. A simulated day is a million requests, one row each:

```
grind --count 1000000 latency-incidents.xml
```

The first ten rows with the model's own seed, 404, are in `latency-incidents.csv`; all ten are healthy and the first five latencies are 27.69, 35.11, 19.10, 16.49 and 35.96 ms. The first incident of this day starts at request 5,205. Rows 5,203 to 5,209:

| Row | Latency (ms) | Incident flag |
|---|---|---|
| 5,203 | 40.335 | 0 |
| 5,204 | 41.308 | 0 |
| 5,205 | 163.316 | 1 |
| 5,206 | 185.865 | 1 |
| 5,207 | 317.517 | 1 |
| 5,208 | 154.611 | 1 |
| 5,209 | 201.847 | 1 |

That incident is 1,101 requests long; the next five are 396, 50, 703, 587 and 896. Over the whole day seed 404 has 170 incidents, with 9.78% of requests inside one.

### Keeping the healthy stream in step

Both lognormals carry `synchronous="true"`, and so does `Perturb`. Without it, in the default replace mode, a branch that is not chosen stands still: the healthy node would stop drawing during an incident and resume afterwards where it left off, so the healthy requests after an incident would be a different series from the ones that would have followed had there been no incident. With `synchronous`, `Perturb` also pulls the branch it did not choose on every row and throws the value away, so each branch stays in step with the row number. (In add mode, below, the healthy branch is pulled on every row whatever `synchronous` says, so there is nothing to keep in step for it; `synchronous` then only decides whether the incident branch advances during the healthy stretches.)

On the full day of seed 404, row i of the healthy stream is the i-th value of the `HealthyLatency` node on its own (run with `--node HealthyLatency`); that holds for **902,188 of 902,188** healthy rows. The same for the incident rows against `DegradedLatency`: **97,812 of 97,812**. Removing `synchronous` from the two lognormals (a throwaway copy, `Perturb` still marked) and running again: the incident flags are identical, as they come from the wait and duration draws, but the healthy values equal the healthy node's draws for only **5,204 of 902,188** rows: they match until the first incident starts at request 5,205, and from request 6,306, the first healthy row after it, every healthy value has been shifted. Same seed, same model shape, and yet a different healthy series. The stream pick-up is the difference between "the service came back" and "the service came back as a different sample".

### What a day of incidents does to the SLO

I ran `grind --count 1000000 --seed S` for the seeds 1 to 50: 50 days, 50,000,000 requests.

| Quantity (50 days of 1,000,000) | Measured | Exact |
|---|---|---|
| Share of requests above 250 ms | 0.0301 (SE 0.0004; sd across days 0.0025) | 0.0298 |
| Share of requests inside an incident | 0.0919 (SE 0.0011) | 0.0909 |
| Incidents per day | 182.3 (SE 1.8; sd 12.9; range 144 to 207) | 181.8 |
| Incident length, 9,109 complete incidents | mean 504.4 (SE 5.4), median 347, range 1 to 5,095 | mean 500 |
| Healthy requests between incidents, 9,064 gaps | mean 4,952 (SE 53) | 5,000.5 |

The exact values are from the cycle. An incident is 500 of every 5,500.5 requests, so 9.09% of requests are inside one and a day holds 1,000,000 / 5,500.5 = 181.8 of them. A healthy request is above 250 ms with probability 7.9e-13 (the log of 250/30, over 0.3, is 7.07 standard deviations), an incident request with probability 1 - Phi(ln(250/200) / 0.5) = 0.3277. So the share of the day's requests above 250 ms is 0.9091 x 7.9e-13 + 0.0909 x 0.3277 = 0.0298. All of it is incident traffic. The measurements are within a standard error of the exact values (z = 0.93 for the share above 250 ms).

The SLO is a p99 under 250 ms, which allows 1% of requests above the line, and the incidents put three times that there. The p99 of a whole day is 370.0 ms on average (theory 369.3, sd across days 9.5; the lowest of the 50 days is 338.6). Every one of the 50 days breaches the SLO, and the healthy traffic alone has a p99 of 60.3 ms. A service that is fast 91% of the time and slow 9% of the time fails a p99 target because of the 9%.

Days differ. The share above 250 ms runs from 0.0226 (seed 47, 158 incidents, 6.9% of requests inside one) to 0.0342 (seed 9, 193 incidents, 10.4% inside), a 50% swing between a good day and a bad one, from the same model. The share above 250 ms is the share inside an incident times 0.328 on every day (correlation 0.998 across the 50 days), so the day is bad when more of it was spent in incidents, and the incidents are long and uneven (their length has a standard deviation close to its mean, as for any geometric count).

### Testing an alert rule against the output

The data now has incidents in it, and the flag says where. Treat it as the feed for the alerting system and ask whether the system notices. Define two rules and evaluate them on the rows Grind prints. The rules are **not** part of the model; the model has no idea an alert exists. They are a few lines of code that read the output file, which is the point: any real checker could take their place.

- **Rule A**: alert while the mean latency of the last 100 requests is above 100 ms.
- **Rule B**: alert on any single request above 100 ms.

Rule A in Python, on a day written with `grind --count 1000000 latency-incidents.xml > day.csv`:

```python
from collections import deque

window, limit = 100, 100.0
recent, total, on = deque(), 0.0, False
for n, line in enumerate(open("day.csv"), start=1):
    latency = float(line.split(",")[0])
    recent.append(latency)
    total += latency
    if len(recent) > window:
        total -= recent.popleft()
    now_on = len(recent) == window and total / window > limit
    if now_on and not on:
        print("alert on at request", n)
    on = now_on
```

or in awk, with a ring of the last 100 values:

```
awk -F, '{ i = NR % 100; sum += $1 - q[i]; q[i] = $1; if (NR >= 100 && sum / 100 > 100) { if (!on) print "alert on at request", NR; on = 1 } else on = 0 }' day.csv
```

Both print the same alerts for seed 404 (the first three at requests 5,236, 15,386 and 28,698; 159 alert episodes on a day of 170 incidents). The scoring uses the flag column: an incident is **detected** if the rule is on at some request inside it, the **delay** is the number of requests from the incident's first request to the first request on, and a **false alarm** is the rule switching on when none of the requests in its window belongs to an incident. Incidents cut off by the end of the day are left out of the statistics, like any other run-length figure. Here is one incident, from the day of seed 404:

![640 consecutive requests with an incident of 140 requests. Healthy requests sit near 30 ms on a log scale; the incident's requests scatter between 65 and 641 ms. The mean of the last 100 requests climbs from 31 to 233 and crosses the 100 ms limit 39 requests into the incident, where rule A fires; rule B fires at the first request](https://obsvra.com/lesson-assets/figures/sim101-19-stretch.svg)

Rule B fires at the incident's first request. Rule A has to wait until enough slow requests are in its window: it fires at request 40 of this incident (the mean of the last 100 is then 101.7 ms), and stays on until 67 requests after the incident ended, because the slow requests are still in the window. That is the shape of the whole result. Over the 50 days:

| 50 days, 9,109 complete incidents | Rule A: mean of last 100 above 100 ms | Rule B: one request above 100 ms |
|---|---|---|
| Incidents detected | 8,530 (93.6%) | 9,109 (100%) |
| Median delay (95th percentile) | 35 requests (41) | 0 (1) |
| False alarms | 0 in 45,402,859 healthy requests | 1,319 = 29.1 per million healthy requests |

![Share of incidents detected by incident length, for the two rules. Rule B is at 100% in every length class. Rule A detects 0 to 3% of the incidents of up to 30 requests, 27% of those of 31 to 35, 70% of 36 to 40, and every incident of 41 requests or more; the dashed theory lines follow the measurements](https://obsvra.com/lesson-assets/figures/sim101-19-detection.svg)

Rule B catches everything and pages about 29 times per million healthy requests, which is some 26 times on a day of a million requests. Rule A never raised a false alarm in 45 million healthy requests, and its misses are all short incidents: it detects 1.1% of the incidents of 1 to 5 requests, 0% of 6 to 10, 2.5% of 11 to 20 and 1.9% of 21 to 30, then 27% of 31 to 35 and 70% of 36 to 40. None of the 8,435 incidents of 41 requests or more is missed.

### Check: do the numbers match the math?

Both rules can be checked against exact values.

Rule B's false alarms: a healthy request is above 100 ms with probability 1 - Phi(ln(100/30) / 0.3) = 2.99e-5, so 29.9 per million healthy requests if every excess were a separate alarm. Consecutive excesses count as one, which changes the figure by a part in 30,000. Measured: 29.1 (1,319 alarms; a count of 1,319 has a standard error of 36, or 0.8 per million, so the two agree within about one standard error). Rule B's detection: an incident request is above 100 ms with probability 0.917, so an incident of L requests escapes with probability 0.083^L. Over the geometric lengths that is 0.018% of incidents, 1.6 of the 9,109 expected; measured: none missed. (In the first length class, 1 to 5 requests, the theory is 98.2% detected and the measurement 100% of 90 incidents, where 1.6 misses were expected, so none is not surprising.)

Rule A's misses: with a window of 100 requests, k of them degraded, the mean is about 31.4 (100 - k) + 226.6 k, divided by 100, which passes 100 ms for k above 35.1, so a rule that waits for about 36 slow requests misses an incident shorter than that. The share of incidents under 36 requests is 6.8% (the geometric distribution's cumulative probability at 35). With the randomness of each request taken into account (a normal approximation to the window's sum, dashed in the figure) the expected share missed is 6.7%. Measured: 579 of 9,109 missed, 6.4%. The measured detection by class follows the dashed line within a few points (31 to 35: 26.8% against 28.7%, 36 to 40: 70.1% against 75.6%; the normal approximation is a little generous where the sum of 36 skewed lognormals is not yet normal). The delay agrees too: the first 36 requests of an incident are needed, and the median delay is 35 requests (mean 34.4), a delay of 35 meaning the 36th request of the incident.

The model's own bookkeeping holds: 50 days, 9,064 gaps with a mean of 4,952 (SE 53) against the 5,000.5 of the ceiling of the exponential, and 9,109 lengths with a mean of 504.4 (SE 5.4) against 500. The gaps are counted from the end of one incident to the start of the next, which is what the exponential is supposed to be: had the wait counted from the start of the previous incident, the cycle would be 5,000.5 requests and an incident would cover 10% of requests, not 9.1%.

### When the incident adds delay instead of replacing it

The main model replaces: during an incident a request is drawn from the degraded distribution, and the healthy value it would have had is thrown away. That fits an incident where requests take a different path, such as a failover to a slow replica. Many incidents are not like that. A slow dependency adds time to a request that otherwise runs as usual, so the request is the healthy latency plus a delay. `Perturb` has a `mode` attribute for this, `replace` (the default, and what the model above does) or `add`. In add mode the disturbance is added to the normal value, column by column, and the normal input is pulled on every row, whatever the phase. The disturbance needs the same number of columns as the normal input, or one column, which is added to every column, and both must be numeric. The wait, the duration and `repeat` work as before.

The flag column needs care, because `Perturb` adds every column, the flag included. The healthy branch has two columns, latency and flag, so the incident branch needs two as well: the extra delay and a constant 1. The flag then reads 0 + 1 = 1 during an incident. A one-column extra delay would be added to the flag column too, and the flag would read the size of the delay. These are the lines of `samples/pro/latency-incidents-additive.xml` (seed 404) that differ from the main model; the gap, the length and the lognormal `HealthyLatency` are the same nodes as before:

```xml
<Lognormal name="ExtraDelay" mu="5.135798437050262" sigma="0.5" synchronous="true"/>
<Constant name="Zero" value="0" type="double"/>
<Constant name="One" value="1" type="double"/>
<Append name="Healthy">
  <input name="HealthyLatency"/>
  <input name="Zero"/>
</Append>
<Append name="Incident">
  <input name="ExtraDelay"/>
  <input name="One"/>
</Append>
<Perturb name="Latency" repeat="true" synchronous="true" mode="add">
  <input name="Healthy" role="normal"/>
  <input name="Incident" role="disturbance"/>
  <input name="Gap" role="wait"/>
  <input name="IncidentLength" role="duration"/>
</Perturb>
```

The file has 10 nodes, like the main model.

The extra delay is a lognormal with a median of 170 ms and a sigma of 0.5. These are chosen values, not measurements of a service. The aim is an incident request about as slow as in the main model, so that the comparison is about how the delay arrives and not how large it is. The sigma is the one of the degraded latency. The median of 170 ms on top of a healthy median of 30 ms gives a request with a median of 201.6 ms (by numerical integration of the sum; 200 ms in the main model) and a mean of 31.4 + 192.6 = 224.0 ms, against 226.6 ms. The one difference in shape that remains is the spread: the sum has a standard deviation of 103.1 ms and the degraded latency of the main model 120.8 ms.

Both models can be run on the same footing because the nodes they share keep their names, and so keep their per-node streams (lesson 4.3). With the same seed the incidents are the same. For seed 404 the incident flag is equal on all 1,000,000 rows, the healthy rows are identical in the two models (902,188 of 902,188), and each of the 97,812 incident rows of the additive model equals the `HealthyLatency` draw of that row plus the `ExtraDelay` draw of that row (checked with `--node`). Over the 50 days of seeds 1 to 50, every incident starts and ends at the same request in both models. The first incident, rows 5,203 to 5,209 of seed 404:

| Row | Healthy draw (ms) | Replace (ms) | Add (ms) | Extra delay in add (ms) | Flag |
|---|---|---|---|---|---|
| 5,203 | 40.335 | 40.335 | 40.335 | 0 | 0 |
| 5,204 | 41.308 | 41.308 | 41.308 | 0 | 0 |
| 5,205 | 32.566 | 163.316 | 226.943 | 194.376 | 1 |
| 5,206 | 27.185 | 185.865 | 170.608 | 143.423 | 1 |
| 5,207 | 22.923 | 317.517 | 190.671 | 167.748 | 1 |
| 5,208 | 40.132 | 154.611 | 216.934 | 176.802 | 1 |
| 5,209 | 52.334 | 201.847 | 431.548 | 379.214 | 1 |

In the replace column the healthy draw plays no part during the incident. In the add column every incident request is its healthy draw plus the delay, so it cannot be faster than the healthy request it started from, and a slow healthy request stays slow.

![The same 640 requests and the same incident of 140 requests under the two modes, two panels on a log scale. The healthy requests are identical. In the replace panel the incident requests scatter between 65 and 641 ms; in the additive panel they scatter between 90 and 543 ms, each with a faint line down to its healthy value. The mean of the last 100 requests crosses 100 ms 39 requests into the incident in the replace panel and 34 requests into it in the additive panel](https://obsvra.com/lesson-assets/figures/sim101-19-additive.svg)

The exact share above a threshold x comes from the mixture, as in the main model, with the incident part now the sum of two independent lognormals. P(Healthy + Extra > x) is the average over the healthy value H of P(Extra > x - H), which has no closed form; it was integrated numerically on the standard-normal scale of ln H (trapezoid rule, step 0.001, from -8 to 8). A request inside an incident is above 250 ms with probability 0.3088 (0.3277 in the main model) and above 100 ms with probability 0.9614 (0.9172). The same 50 days, seeds 1 to 50, were run on both models:

| 50 days of 1,000,000 requests | Replace (main model) | Add |
|---|---|---|
| Share of requests above 250 ms | 0.0301 (SE 0.0004), exact 0.0298 | 0.0284 (SE 0.0003), exact 0.0281 |
| Incident requests above 250 ms | 32.8%, exact 32.8% | 30.9%, exact 30.9% |
| Incident requests above 100 ms | 91.7%, exact 91.7% | 96.2%, exact 96.1% |
| Day's p99, mean of 50 days | 370.0 ms (sd 9.5), exact 369.3 | 346.4 ms (sd 8.0), exact 345.8 |
| Days with p99 above 250 ms | 50 of 50 | 50 of 50 |
| Rule A detects (9,109 incidents) | 8,530 (93.6%) | 8,545 (93.8%) |
| Rule A delay: median (95th percentile) | 35 requests (41) | 35 requests (41) |
| Rule A false alarms | 0 in 45,402,859 healthy requests | 0 in 45,402,859 healthy requests |
| Rule B detects | 9,109 (100%) | 9,109 (100%) |
| Rule B delay: median (95th percentile) | 0 (1) | 0 (0) |
| Rule B false alarms | 1,319 = 29.1 per million | 1,319 = 29.1 per million |

The measured share above 250 ms for the additive model is 0.87 standard errors from the exact value. Paired by seed, the additive day has 0.00175 fewer requests above 250 ms than the replace day (SE 0.00004), 5.8% fewer, and a p99 lower by 23.6 ms (SE 0.3). Three things in the table are worth reading.

The SLO verdict does not depend on the mode. Every one of the 50 days breaches a p99 target of 250 ms in both models, with a p99 of 346 ms or 370 ms, and the share above the line is three times what the SLO allows in both. The size of the breach does depend on it, by 24 ms on the p99. The two incidents have about the same mean, but the additive one has the smaller spread, since its healthy part is tight and only the extra delay varies much, so fewer requests reach the far tail.

The false alarm counts are equal because they must be. A false alarm is a switch-on whose window holds no incident request, so it depends only on healthy requests, and those are the same rows in both models. The counts agree for all 24 rules of the grid in the next section, not just these two.

Detection moves only a little. The incident requests are above 100 ms more often in the additive model (96.2% against 91.7%), so a single request catches an incident slightly more reliably: an incident of L requests escapes rule B with probability 0.0386^L against 0.083^L, which is 0.008% of incidents (0.7 of the 9,109) against 0.018% (1.6), and none was missed in either model. For rule A, a window of 100 needs k incident requests with 224.0 k + 31.4 (100 - k) above 10,000, so k above 35.6 against 35.1, and it still misses every incident shorter than 36 requests. The expected share of incidents missed is 6.8% (normal approximation, as in the check above; 6.7% in the main model), and the measured shares are 564 of 9,109, 6.2%, against 579, 6.4%. The class counts are small. In the class of 31 to 35 requests the additive model detected 24 of 71 (33.8%) and in 36 to 40 requests 77 of 97 (79.4%). Simulating the rule on incidents of each length from the distributions alone (100 healthy requests, then the incident, 10,000 incidents per length, no Grind) gives expected shares of 21.3% and 73.6% (the normal approximation gives 22.1% and 74.3%; for the main model the simulation gives 27.4% and 74.9%, and the measurement was 26.8% and 70.1%). The 24 of 71 is 2.6 standard errors above 21.3%, which is a lot for one count, so the check was repeated on 50 more days (seeds 51 to 100, 8,988 complete incidents): 23 of 100 (23.0%) and 60 of 84 (71.4%), in line with the simulation. Over all 100 days, the incidents of 31 to 40 requests were detected in 184 of 352 cases (52.3%). The first 50 days were a high draw.

So for this alert question the choice between replace and add moves the numbers by a few percent, and none of the conclusions: rule B catches everything and pages about 29 times per million requests, rule A never cries wolf and misses the incidents shorter than about 36 requests. That tells you the lesson's conclusions do not rest on the replace shortcut. Choose the mode by what the incident does. If the work itself changes (a failover, a different code path), a request has nothing to do with the healthy value it displaces, and `replace` is right. If something is added to the work (a slow dependency, a retry, a queue in front of it), use `add`, and the healthy variation survives inside the incident. The same mode serves other disturbances that ride on a baseline: `samples/pro/perturb-additive.xml` adds bursts of interference to a sensor reading. The companion page has a switch for the mode and shows the detection, the delay and the false alarms of all 24 rules for both models.

### Tuning the window

The usual first thought after seeing rule A is to tune the window so that short incidents are caught without false alarms. The same 50 days can answer that, because the rules are only code. The grid below comes from running 24 rules, six windows by four limits, over the same rows. It shows the limit of 100 ms; the [companion page](https://obsvra.com/lesson-assets/companions/sim101-19.html) has all of them, for both incident modes.

| Window (requests) | Detected | Median delay | False alarms per million healthy requests |
|---|---|---|---|
| 1 (rule B) | 100.0% | 0 | 29.1 |
| 5 | 99.7% | 1 | 0 |
| 10 | 99.3% | 3 | 0 |
| 50 | 96.7% | 17 | 0 |
| 100 (rule A) | 93.6% | 35 | 0 |
| 200 | 87.3% | 70 | 0 |

A window of 10 requests at 100 ms catches all 9,019 incidents of 6 requests or more, and 30 of the 90 shorter ones (9,049 of 9,109, 99.3%), with a median delay of 3 requests, and it raised no false alarm in 45 million healthy requests. It misses most incidents of 1 to 5 requests, because it needs about four slow requests in the window (10 x (100 - 31.4) / 195 = 3.5). A window of 5 does better on those (68%), and so does a lower limit: window 5 at 60 ms catches 99.9% and starts to fire on healthy traffic (0.9 per million, 40 alarms in the 50 days). A window of 1 shows where the false alarms come from: a single healthy request above 60 ms is 1% of all healthy requests (10,333 alarms per million measured, 10,322 expected from the lognormal), above 80 ms it is 538 per million (538.5 expected), above 100 ms 29.1 (29.9) and above 120 ms 2.0 (1.9). So the answer from the grid is yes: shorten the window to about 10 and keep the limit near 100 ms.

That answer is only as good as the healthy model. The false alarms vanish at a window of 5 to 10 because the healthy traffic here is tight (sigma 0.3). The same rules were rerun on a throwaway copy of the model with the healthy sigma of lesson 4.2, 0.8 (same median, 20 days, 18,161,834 healthy requests, 3,702 incidents). A window of 1 at 100 ms then fires 61,807 times per million healthy requests, a window of 5 3,713 times, and **a window of 10 still 398 times**, about 400 pages per million requests where the tight model gave none. A window of 50 raised none and detected 96.9% of the incidents, and the lesson's window of 100 raised none and detected 93.9%. So with the noisier healthy traffic the right window is the longer one. The simulation tells you how the rule behaves on the traffic you described; it cannot tell you that the described traffic is right, and "no false alarms" (a count of zero in 45 million requests) is a statement about that traffic.

**What this gives you:** timed incidents with `Perturb` (wait, duration, repeat, and `synchronous` to keep the healthy stream in step), a choice between an incident that replaces the latency and one that adds a delay to it (`mode`), a model that reports its own state in a flag column, and a way to turn a simulation into test data for something outside it. In this model an incident is 9.1% of requests and 3% of requests above 250 ms, enough to break a p99 SLO on every one of 50 days, and the alert rule you had in mind (the mean of the last 100 requests above 100 ms) never cried wolf and missed 6.4% of incidents, all of them short ones. A window of 10 would have caught almost all of those with no false alarms on this healthy traffic, and 398 per million on a noisier healthy service: the right window depends on the healthy noise. Making the incident an added delay of the same average size (`mode="add"`) changed the p99 of the day by 24 ms and the detection by under a point, and nothing in the verdicts. The [companion page](https://obsvra.com/lesson-assets/companions/sim101-19.html) lets you pick the window (1, 5, 10, 50, 100 or 200 requests), the limit (60, 80, 100 or 120 ms) and the incident mode (replace or add), and shows the detection by incident length, the delay and the false alarms per million requests from the 50 simulated days.

Everything so far has been made-up traffic. The last question the SRE team has is what last month would have looked like under the new deploy, with the real traffic they recorded. The next lesson replays a trace of real request counts through the model.
