Video in progress

Staff 🧪 Testing

How do you add load tests to the pipeline to automatically catch performance regressions before a release?

Not on every PR; I run them on main or nightly in a stable, isolated environment with a fixed scenario (Gatling, k6 or JMeter), compare the result with the previous baseline, and alert if p95/p99 or throughput crosses a threshold. Small hot spots get JMH micro-benchmarks, separately.

📖 Answer

The main difficulty is noise. On a shared CI runner a load test varies ±20% every time, and you can't see a 5% regression in results like that.

So:

  • Environment. A separate one that's not shared with other jobs; resources proportional to prod; the same data volume (index problems aren't visible on an empty database).
  • Scenario. Close to the real traffic distribution: something like 70% catalog, 20% watching lessons, 10% payment. Shares taken from prod access logs are a good source.
  • Baseline and threshold. The result is compared with the median of the last N runs. Absolute thresholds (p99 < 300 ms) come from the SLO, while relative thresholds (p95 got 10%+ worse) catch a regression.
  • Decision. A relative regression doesn't block automatically; it raises a ticket with the range of suspect commits. An SLO violation stops the release.
// k6: thresholds in the pipeline
export const options = {
  scenarios: { browse: { executor: 'constant-arrival-rate', rate: 200, timeUnit: '1s', duration: '10m', preAllocatedVUs: 100 } },
  thresholds: { http_req_duration: ['p(95)<250', 'p(99)<600'], http_req_failed: ['rate<0.01'] },
};

constant-arrival-rate matters: a closed model (N virtual users) reduces the load by itself when the system slows down and hides the problem (coordinated omission).

For critical spots at the code level (serialization, calculation), JMH benchmarks; those too should run only on a stable machine.

And prod metrics are the best load test. If comparing latency by version after every release is automatic, many regressions get caught cheaply there.