Skip to content

Commit 78b31ca

Browse files
authored
server : Add k6 Load Testing Script (#3175)
* add load testing script and update README for k6 integration
1 parent cbe557f commit 78b31ca

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

examples/server/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,35 @@ curl 127.0.0.1:8080/load \
6767
-H "Content-Type: multipart/form-data" \
6868
-F model="<path-to-model-file>"
6969
```
70+
71+
## Load testing with k6
72+
73+
> **Note:** Install [k6](https://k6.io/docs/get-started/installation/) before running the benchmark script.
74+
75+
You can benchmark the Whisper server using the provided bench.js script with [k6](https://k6.io/). This script sends concurrent multipart requests to the /inference endpoint and is fully configurable via environment variables.
76+
77+
**Example usage:**
78+
79+
```
80+
k6 run bench.js \
81+
--env FILE_PATH=/absolute/path/to/samples/jfk.wav \
82+
--env BASE_URL=http://127.0.0.1:8080 \
83+
--env ENDPOINT=/inference \
84+
--env CONCURRENCY=4 \
85+
--env TEMPERATURE=0.0 \
86+
--env TEMPERATURE_INC=0.2 \
87+
--env RESPONSE_FORMAT=json
88+
```
89+
90+
**Environment variables:**
91+
- `FILE_PATH`: Path to the audio file to send (must be absolute or relative to the k6 working directory)
92+
- `BASE_URL`: Server base URL (default: `http://127.0.0.1:8080`)
93+
- `ENDPOINT`: API endpoint (default: `/inference`)
94+
- `CONCURRENCY`: Number of concurrent requests (default: 4)
95+
- `TEMPERATURE`: Decoding temperature (default: 0.0)
96+
- `TEMPERATURE_INC`: Temperature increment (default: 0.2)
97+
- `RESPONSE_FORMAT`: Response format (default: `json`)
98+
99+
**Note:**
100+
- The server must be running and accessible at the specified `BASE_URL` and `ENDPOINT`.
101+
- The script is located in the same directory as this README: `bench.js`.

examples/server/bench.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import http from 'k6/http'
2+
import { check } from 'k6'
3+
4+
export let options = {
5+
vus: parseInt(__ENV.CONCURRENCY) || 4,
6+
iterations: parseInt(__ENV.CONCURRENCY) || 4,
7+
}
8+
9+
const filePath = __ENV.FILE_PATH
10+
const baseURL = __ENV.BASE_URL || 'http://127.0.0.1:8080'
11+
const endpoint = __ENV.ENDPOINT || '/inference'
12+
const temperature = __ENV.TEMPERATURE || '0.0'
13+
const temperatureInc = __ENV.TEMPERATURE_INC || '0.2'
14+
const responseFormat = __ENV.RESPONSE_FORMAT || 'json'
15+
16+
// Read the file ONCE at init time
17+
const fileBin = open(filePath, 'b')
18+
19+
export default function () {
20+
const payload = {
21+
file: http.file(fileBin, filePath),
22+
temperature: temperature,
23+
temperature_inc: temperatureInc,
24+
response_format: responseFormat,
25+
}
26+
27+
const res = http.post(`${baseURL}${endpoint}`, payload)
28+
check(res, { 'status is 200': r => r.status === 200 })
29+
}

0 commit comments

Comments
 (0)