···11+# Crowdsec Benchmark
22+33+This docker stack can be used to benchmark an out-of-the-box crowdsec installation. It contains:
44+55+* [Traefik](https://doc.traefik.io/traefik/getting-started/install-traefik/) reverse proxy
66+ * Configured with [Access Logs](https://doc.traefik.io/traefik/observe/logs-and-access-logs/#access-logs) that Crowdsec can consume
77+ * Wired to serve [mendhak/http-https-echo](https://github.com/mendhak/docker-http-https-echo), a simple web server that accepts any paths and echos back the request as JSON
88+* [Crowdsec](https://docs.crowdsec.net/)
99+ * Configured to consume Traefik logs
1010+ * With Collections required for parsing those logs and basic web traffic
1111+* [k6](https://grafana.com/docs/k6/latest/) load testing tool
1212+ * Configured to generate concurrent requests and duration of load using ENVs
1313+ * Randomized path (`RANDOMIZE=true`)
1414+ * Randomized User-Agent
1515+1616+Additionally, the bash script [`bench.sh`](/bench.sh) can be used to orchestrate the load call, monitor the crowdsec process, and create a .png plot of CPU/memory using [`psrecord`](https://github.com/astrofrog/psrecord), if it installed.
1717+1818+# Usage
1919+2020+## Create .env
2121+2222+Use the sample [`.env.example`](/.env.example) to create an `.env` for your scenario.
2323+2424+* `TARGET` = number of concurrent requests to make
2525+* `DURATION` = number of seconds to run load
2626+* `RANDOMIZE` = randomize url path
2727+* `URL` = leave as default unless modifying this project for your own use
2828+2929+## Run Load
3030+3131+### Using `bench.sh`
3232+3333+Install [`psrecord`](https://github.com/astrofrog/psrecord), if not present:
3434+3535+```shell
3636+pipx install psrecord[plot]
3737+```
3838+3939+Run `bench.sh` from the project directory, providing the duration the load will be run:
4040+4141+```shell
4242+# DURATION=12 from .env then...
4343+./bench.sh 12
4444+```
4545+4646+After the run has finished an image `plot_[unix_timestamp].png` will be generated in the project directory.
4747+4848+### Manually
4949+5050+1. Start docker services required to run the load
5151+5252+```shell
5353+docker compose up traefik echo crowdsec -d
5454+```
5555+5656+2. Start any monitoring/profiling software for crowdsec
5757+5858+3. Run load
5959+6060+```shell
6161+docker compose up k6
6262+```