sachaarbonel commited on
Commit
9a681c7
·
unverified ·
1 Parent(s): e789f73

server : Add k6 Load Testing Script (#3175)

Browse files

* add load testing script and update README for k6 integration

examples/server/README.md CHANGED
@@ -67,3 +67,35 @@ curl 127.0.0.1:8080/load \
67
  -H "Content-Type: multipart/form-data" \
68
  -F model="<path-to-model-file>"
69
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  -H "Content-Type: multipart/form-data" \
68
  -F model="<path-to-model-file>"
69
  ```
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 ADDED
@@ -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
+ }