@@ -133,6 +133,118 @@ make run-server
133133# Endpoints: /health, /api/users, /api/stats, /api/echo
134134```
135135
136+ ## Script Engine (Code-Based Load Testing)
137+
138+ Write load tests in your preferred language — like k6, but polyglot with chaos patterns built-in.
139+
140+ ``` bash
141+ kar script test.star # Starlark (Python-like)
142+ kar script test.js # JavaScript
143+ kar script test.py # Python
144+ kar script test.rb # Ruby
145+ kar script test.star --vus 50 --duration 5m # Override VUs and duration
146+ kar script test.star --dashboard # Enable real-time web dashboard
147+ ```
148+
149+ ### Starlark (.star)
150+
151+ ``` python
152+ scenario(
153+ name = " api-load-test" ,
154+ pattern = chaos(preset = " aggressive" , spike_factor = 3.0 ),
155+ vus = ramp([
156+ stage(" 30s" , 10 ), # Ramp to 10 VUs over 30s
157+ stage(" 2m" , 50 ), # Ramp to 50 VUs over 2m
158+ stage(" 30s" , 0 ), # Ramp down
159+ ]),
160+ thresholds = {
161+ " http_req_duration{p95} " : " < 500ms" ,
162+ " http_req_failed" : " < 0.05" ,
163+ },
164+ )
165+
166+ def setup ():
167+ resp = http.post(" http://api.example.com/auth" , json = {" user" : " test" })
168+ return {" token" : resp.json()[" token" ]}
169+
170+ def default (data ):
171+ headers = {" Authorization" : " Bearer " + data[" token" ]}
172+ resp = http.get(" http://api.example.com/products" , headers = headers)
173+ check(resp, {
174+ " status 200" : lambda r : r.status == 200 ,
175+ " has items" : lambda r : len (r.json()) > 0 ,
176+ })
177+ sleep(think_time(" 1s" , " 3s" ))
178+ ```
179+
180+ ### JavaScript (.js)
181+
182+ ``` javascript
183+ scenario ({
184+ name: " api-load-test" ,
185+ pattern: chaos ({ preset: " moderate" }),
186+ thresholds: {
187+ " http_req_duration{p95}" : " < 500ms" ,
188+ },
189+ });
190+
191+ function run (data ) {
192+ var resp = http .get (" http://api.example.com/health" );
193+ check (resp, {
194+ " status 200 " : function (r ) { return r .status === 200 ; },
195+ });
196+ }
197+ ```
198+
199+ ### Python (.py)
200+
201+ ``` python
202+ from kar98k import scenario, chaos, http, check, sleep, think_time
203+
204+ scenario(name = " api-load-test" , pattern = chaos(preset = " moderate" ))
205+
206+ def default (data ):
207+ resp = http.get(" http://api.example.com/health" )
208+ check(resp, {
209+ " status 200" : lambda r : r.status == 200 ,
210+ " has status" : lambda r : " status" in r.json(),
211+ })
212+ sleep(think_time(" 1s" , " 3s" ))
213+ ```
214+
215+ ### Ruby (.rb)
216+
217+ ``` ruby
218+ require_relative " ../sdk/ruby/kar98k"
219+
220+ scenario name: " api-load-test" , pattern: chaos(preset: " moderate" )
221+
222+ def default (data )
223+ resp = Http .get(" http://api.example.com/health" )
224+ check resp,
225+ " status 200" => -> (r) { r.status == 200 }
226+ sleep_dur think_time(" 1s" , " 3s" )
227+ end
228+ ```
229+
230+ ### Real-Time Dashboard
231+
232+ ![ kar98k Dashboard] ( ./assets/dashboard.png )
233+
234+ Enable with ` --dashboard ` :
235+
236+ ``` bash
237+ kar script test.star --vus 20 --duration 5m --dashboard
238+ # Dashboard: http://localhost:8888
239+ ```
240+
241+ Opens a web UI showing:
242+ - Live RPS and latency graphs
243+ - P95/P99 latency tracking
244+ - Error rate and status codes
245+ - Check pass/fail rates
246+ - VU count and iteration progress
247+
136248## Commands
137249
138250| Command | Description |
0 commit comments