From d10f485acb836c2c3a39ca72df1477780907cad8 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sat, 1 Mar 2025 13:08:22 +1300 Subject: [PATCH] Add k6 benchmark example. --- examples/benchmark/readme.md | 18 ++++++++++++++++++ examples/benchmark/small.js | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 examples/benchmark/readme.md create mode 100644 examples/benchmark/small.js diff --git a/examples/benchmark/readme.md b/examples/benchmark/readme.md new file mode 100644 index 0000000..8ab2091 --- /dev/null +++ b/examples/benchmark/readme.md @@ -0,0 +1,18 @@ +# Benchmark Example + +## Usage + +First, ensure you have `k6` installed. Then, start the server: + +```bash +$ falcon serve --bind http://localhost:9292 +``` + +Then run `k6`: + +```bash +$ k6 run small.js +``` +## Comparison + +You could start the included `config.ru` with other servers and compare. diff --git a/examples/benchmark/small.js b/examples/benchmark/small.js new file mode 100644 index 0000000..38d70fe --- /dev/null +++ b/examples/benchmark/small.js @@ -0,0 +1,21 @@ +export const options = { + stages: [ + // Warmup: Gradually ramp up: + {duration: '10s', target: 64}, + + // Main test: Sustained load: + {duration: '1m', target: 64}, + ], +}; + +import http from 'k6/http'; +import { check, sleep } from 'k6'; + +export default function () { + const res = http.get('http://localhost:9292/small'); + + check(res, { + 'is status 200': (r) => r.status === 200, + 'response time < 200ms': (r) => r.timings.duration < 200, + }); +} \ No newline at end of file