okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b65d593c
main
1"""bench-local/par.py - several requests at once against the running server: what each one gets and what they get 2together. The server's "parallel" setting is whatever the running config has (ab.py's v139-par* arms set it). 3 4python par.py 1 2 4 (requests at once, one round each; a line per round, results appended to par.jsonl) 5""" 6from __future__import annotations 7 8import json 9import sys 10import threading 11import time 12import uuid 13from pathlib import Path 14 15import requests 16 17HERE = Path (__file__ ).parent 18BASE = "http://127.0.0.1:8080" 19TOPICS = ["how a hash map works: hashing, collisions, resizing, complexity" , 20"how TCP establishes and closes a connection, and what each flag means" , 21"processes and threads: memory, scheduling, communication, failure isolation" , 22"how a B-tree index speeds up a database query, and what it costs on writes" , 23"how garbage collection works: reference counting, mark and sweep, generations" , 24"how TLS sets up an encrypted connection: certificates, key exchange, session keys" , 25"how virtual memory works: pages, page tables, the TLB, swapping" , 26"how a compiler turns source into machine code: parsing, IR, optimisation, codegen" ] 27 28 29def one (i ,out ,t0 ): 30"""One streamed request: the time to its first token and its own decode rate (the server's timings).""" 31body = {"model" :"strata" ,"max_tokens" :300 ,"temperature" :0 ,"reasoning_effort" :"none" ,"stream" :True , 32"stream_options" : {"include_usage" :True }, 33"messages" : [{"role" :"user" ,"content" :f"[ { uuid . uuid4 (). hex [: 8 ] } ] Explain in detail { TOPICS [ i % 8 ] } . " 34"About 220 words." }]} 35rec = {"i" :i } 36try : 37with requests .post (BASE + "/v1/chat/completions" ,json = body ,stream = True ,timeout = 1800 )as r : 38for raw in r .iter_lines (): 39if not raw .startswith (b"data: " )or raw == b"data: [DONE]" : 40continue 41ev = json .loads (raw [6 :]) 42delta = (ev .get ("choices" )or [{}])[0 ].get ("delta" )or {} 43if "first_s" not in rec and (delta .get ("content" )or delta .get ("reasoning_content" )): 44rec ["first_s" ]= round (time .time ()- t0 ,2 ) 45if ev .get ("timings" ): 46rec ["tok_s" ]= ev ["timings" ].get ("predicted_per_second" ) 47rec ["out_n" ]= ev ["timings" ].get ("predicted_n" ) 48if ev .get ("usage" )and "out_n" not in rec : 49rec ["out_n" ]= ev ["usage" ].get ("completion_tokens" ) 50except Exception as e : 51rec ["error" ]= f" { type ( e ). __name__ } : { e } " [:200 ] 52rec ["done_s" ]= round (time .time ()- t0 ,2 ) 53out [i ]= rec 54 55 56def main (): 57label = json .loads (requests .get (BASE + "/v1/status" ,timeout = 10 ).text ).get ("concurrency" , {}) 58for k in [int (x )for x in sys .argv [1 :]]: 59out ,t0 = [None ]* k ,time .time () 60threads = [threading .Thread (target = one ,args = (i ,out ,t0 ))for i in range (k )] 61for t in threads : 62t .start () 63for t in threads : 64t .join () 65wall = time .time ()- t0 66toks = sum (r .get ("out_n" )or 0 for r in out ) 67rec = {"time" :time .strftime ("%H:%M:%S" ),"requests" :k ,"server" :label ,"wall_s" :round (wall ,1 ), 68"total_tok_s" :round (toks / wall ,1 ),"runs" :out } 69firsts = sorted (r .get ("first_s" )or - 1 for r in out ) 70f"PAR { k } at once (server { label . get ( 'serving' , '?' ) } ): together { rec [ 'total_tok_s' ] } tok/s, all done in " 71f" { rec [ 'wall_s' ] } s | first token after { firsts } s | each " 72f" { [ r . get ( 'tok_s' ) for r in out ] } tok/s | errors { sum ( 1 for r in out if r . get ( 'error' )) } " ,flush = True ) 73with (HERE / "par.jsonl" ).open ("a" ,encoding = "utf-8" )as f : 74f .write (json .dumps (rec ,ensure_ascii = False )+ "\n" ) 75 76 77if __name__ == "__main__" : 78main ()