[READ-ONLY] Mirror of https://github.com/FoxxMD/crowdsecBench. Benchmark Crowdsec CPU usage with concurrent requests
benchmark cpu-usage crowdsec docker k6 monitoring visualization
0

Configure Feed

Select the types of activity you want to include in your feed.

refactor: Remove env requirement

* default url in script so not env is necessary
* make env_file optional in compose
* Use defaults in script, or load env, for logging and generating goeffel graph subtitle

FoxxMD (Sep 24, 2025, 12:58 PM EDT) 5287a402 a6a71cd2

+30 -20
-1
.env.example
··· 1 - URL=http://traefik 2 1 TARGET=1 3 2 DURATION=10s 4 3 RANDOMIZE=true
+13 -14
README.md
··· 16 16 17 17 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 using [`goeffel`](https://github.com/jgehrcke/goeffel). 18 18 19 - # Usage 20 - 21 - ## Create .env 19 + ## Usage 22 20 23 - Use the sample [`.env.example`](/.env.example) to create an `.env` for your scenario. 24 - 25 - * `TARGET` = number of concurrent requests to make per second 26 - * `DURATION` = number of seconds to run load 27 - * `RANDOMIZE` = randomize url path 28 - * `URL` = leave as default unless modifying this project for your own use 21 + ### Run Load 29 22 30 - ## Run Load 31 - 32 - ### Using `bench.sh` 23 + #### Using `bench.sh` 33 24 34 25 ```shell 35 26 ./bench.sh ··· 39 30 40 31 Additional graphs can be plotted from the generated `hdf5` file using [`goeffel-analysis`](https://github.com/jgehrcke/goeffel?tab=readme-ov-file#goeffel-analysis-data-inspection-and-visualization). 41 32 42 - ### Manually 33 + #### Manually 43 34 44 35 1. Start docker services required to run the load 45 36 ··· 61 52 docker compose up k6 62 53 ``` 63 54 64 - # Benchmark Results 55 + ### (Optional) Customize Load with .env 56 + 57 + Use the sample [`.env.example`](/.env.example) to create an `.env` for your scenario. 58 + 59 + * `TARGET` = number of concurrent requests to make per second 60 + * `DURATION` = number of seconds to run load (the `s` at the end is important) 61 + * `RANDOMIZE` = randomize url path -- `true` or `false` 62 + 63 + ## Benchmark Results 65 64 66 65 See the [`bench-results`](/bench-results/) folder for some benchmarks run on my own hardware.
+12 -2
bench.sh
··· 2 2 3 3 trap 'exit 0;' SIGHUP SIGINT 4 4 5 + TARGET='50' 6 + DURATION='30s' 7 + 8 + if test -f ".env"; then 9 + printf 'Found .env\n' 10 + export $(cat .env | xargs) 11 + fi 12 + 13 + printf 'RUN => %s concurrent requests over %s\n' "$TARGET" "$DURATION" 14 + 5 15 printf 'Starting traefik and echo...\n' 6 16 docker compose up traefik echo -d 7 17 ··· 21 31 printf 'Starting goeffel capture of crowdsec PID %s \n' "$CS_PID" 22 32 docker compose run --rm --no-TTY goeffel goeffel --pid $CS_PID & 23 33 24 - printf 'Starting k6\n' 34 + printf 'Starting k6, will run for %s\n' "$DURATION" 25 35 docker compose up k6 -d 26 36 27 37 docker compose wait k6 ··· 44 54 --column proc_cpu_util_percent_total \ 45 55 'CPU util (total) / %' \ 46 56 "Crowdsec Web Traffic Load $timestamp" 5 \ 47 - --subtitle '50 concurrent requests, measured with Goeffel' \ 57 + --subtitle "$TARGET concurrent requests, measured with Goeffel" \ 48 58 --legend-loc 'upper right' \ 49 59 --mean-style solid \ 50 60 --custom-y-limit 0 100
+3 -1
compose.yaml
··· 6 6 command: 7 7 - 'run' 8 8 - '/app/script.ts' 9 - env_file: '.env' 9 + env_file: 10 + - path: ./.env 11 + required: false 10 12 traefik: 11 13 image: "traefik:v3.3" 12 14 # ports:
+2 -2
src/k6/script.ts
··· 12 12 import {generateRandomUserAgent} from './utils/agent.ts'; 13 13 14 14 const duration = __ENV.DURATION ?? '30s'; 15 - let target = __ENV.TARGET ?? 2; 15 + let target = __ENV.TARGET ?? 50; 16 16 if(typeof target === 'string') { 17 17 target = parseInt(target); 18 18 } ··· 32 32 } 33 33 }; 34 34 35 - const URL = __ENV.URL; 35 + const URL = __ENV.URL ?? 'http://traefik'; 36 36 37 37 const randomizeUrl = __ENV.RANDOMIZE === 'true'; 38 38