Prompt
How do I run continuous load tests in CI/CD
Latest observation
To run continuous load tests in CI/CD, treat load testing like any other automated quality gate: define a small, repeatable test suite, run it on a schedule or against key changes, publish results, and fail the pipeline when agreed thresholds are exceeded.
1) Decide what “continuous” means for you
Usually this is one or more of:
- Per pull request: lightweight performance smoke test
- Nightly: broader load test
- Pre-release / post-deploy: higher-volume validation
- Weekly: long-running soak test
Most teams do not run full-scale load tests on every commit because they’re expensive and noisy. Instead:
- PRs: short, low-cost checks
- Main branch/nightly: deeper coverage
- Release candidates: full regression
2) Pick clear performance SLOs and thresholds
Define pass/fail criteria such as:
- p95 latency < 300 ms
- error rate < 1%
- throughput >= 500 RPS
- CPU < 80% average under expected load
- no memory growth > X over Y minutes
Use:
- hard thresholds for build failures
- trend thresholds for warnings/regressions
3) Choose a load test tool
Common options:
- k6: great for CI, scriptable, easy to containerize
- Gatling: strong for JVM shops
- JMeter: widely used, heavier
- Locust: Python-based, flexible
- Artillery: simple JS-based option
- Cloud options: BlazeMeter, Grafana Cloud k6, Datadog Synthetic, LoadRunner Cloud
For CI/CD, tools that run well in containers and output machine-readable results are ideal.
4) Make the test environment production-like
Load tests are only useful if the target behaves similarly to production:
- same app version and config
- realistic dependencies (DB, cache, queue)
- representative data volume
- realistic autoscaling settings
- same network/security layers where possible
If production-like infra is too costly, use a smaller but consistent staging environment and compare trends over time, not absolute values.
5) Containerize the test runner
Run tests in a Docker container so CI can execute them consistently.
Example with k6:
docker run --rm -i grafana/k6 run - <script.js
Or in a pipeline:
- checkout code
- start test environment
- run load test container
- collect metrics
- evaluate thresholds
- publish reports
6) Store test scripts in version control
Keep load test code next to application code:
- easier review
- versioned with app changes
- reproducible across branches
Organize by test type:
smoke/stress/soak/regression/
7) Integrate into CI/CD stages
Typical pipeline design:
PR pipeline
- Unit tests
- Integration tests
- Load test smoke check
- Fail if basic performance thresholds regress
Main branch / nightly
- Deploy to staging
- Run medium load test
- Compare with baseline
- Save metrics and charts
- Alert on regression
Release pipeline
- Run full load test against release candidate
- Validate scaling behavior and recovery
- Gate promotion on pass
8) Publish and compare metrics
Send results to observability tools:
- Prometheus / Grafana
- InfluxDB
- Datadog
- New Relic
- CloudWatch
Track over time:
- latency percentiles
- error rates
- saturation metrics
- app-specific KPIs
- infra metrics
Use baseline comparison:
- current vs last successful build
- rolling median of recent runs
- anomaly detection
9) Automate regression detection
Set up rules like:
- p95 latency increased by > 10% vs baseline
- error rate > 0.5%
- throughput dropped by > 5%
- resource usage exceeded safe band
This is better than using only absolute numbers because environments drift.
10) Control cost and flakiness
To keep it sustainable:
- run short tests on PRs
- use seeded, repeatable data
- isolate test environments
- avoid shared dependencies where possible
- limit external API calls or mock them
- keep a cooldown between tests if environment needs it
Example CI pattern
A simple GitHub Actions flow:
- Build app
- Deploy to ephemeral staging
- Run
k6test - Parse thresholds
- Upload results
- Fail job if thresholds exceeded
Example conceptual steps:
- name: Run load test
run: docker run --rm -i grafana/k6 run --out json=results.json - < loadtest.js
- name: Check thresholds
run: python scripts/check_thresholds.py results.json
11) Add alerts and visibility
If a load test fails:
- notify Slack/Teams
- create a ticket automatically
- link to charts and logs
- include baseline comparison
This helps make performance issues actionable.
12) Recommended starting strategy
If you want a practical rollout:
- Start with one smoke load test in PRs
- Add nightly medium-load tests
- Compare against a baseline
- Add release-candidate full tests
- Alert on regressions, not just failures
If you want, I can also give you:
- a GitHub Actions example
- a GitLab CI example
- a Jenkins pipeline example
- a k6 sample script with thresholds