Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
44 lines
2.5 KiB
Python
44 lines
2.5 KiB
Python
# Trace-driven model of N agent sessions through the gateway's FIFO queue (docs/experiments/async-park-compression-and-orchestrator-bench.md,
|
|
# section B.4): every request of a recorded single-agent session keeps its recorded service time (t_done - t_start) and the recorded
|
|
# gap before the next one (agent think + tools); one engine serves one request at a time in arrival order; a session change costs a
|
|
# switch time. Prints the makespan of the sessions run concurrently against the sum of their solo walls. Offline, standard library,
|
|
# no GPU; run from the repository root: python scripts/memory/queue_gap_sim.py
|
|
import csv, itertools, heapq, statistics
|
|
F={'943b':'docs/e2e-data/943b-trace.csv','945':'docs/e2e-data/945-trace.csv','943d':'docs/e2e-data/943d-codex-ttt-trace.csv','945d':'docs/e2e-data/945d-codex-crm-trace.csv'}
|
|
def load(p):
|
|
rows=list(csv.DictReader(open(p)))
|
|
out=[]
|
|
for r in rows:
|
|
try: svc=(float(r['t_done_ms'])-float(r['t_start_ms']))/1000
|
|
except: continue
|
|
g=r.get('gap_before_ms') or '0'
|
|
out.append((svc, float(g)/1000 if g else 0.0))
|
|
return out
|
|
S={k:load(v) for k,v in F.items()}
|
|
for k,v in S.items():
|
|
svc=sum(x[0] for x in v); gap=sum(x[1] for x in v[1:]); print(k,len(v),'svc %.0f s gap %.1f s (%.1f%%)'%(svc,gap,100*gap/(svc+gap)))
|
|
def solo(v,scale):
|
|
return sum(x[0]*scale for x in v)+sum(x[1] for x in v[1:])
|
|
def fifo(sessions,scale,sw):
|
|
# each session: next request becomes ready after previous done + gap
|
|
ready=[0.0]*len(sessions); idx=[0]*len(sessions); t=0.0; last=None; done=[0.0]*len(sessions)
|
|
while any(idx[i]<len(sessions[i]) for i in range(len(sessions))):
|
|
cands=[(ready[i],i) for i in range(len(sessions)) if idx[i]<len(sessions[i])]
|
|
r,i=min(cands)
|
|
start=max(t,r)
|
|
s=sessions[i][idx[i]][0]*scale + (sw if (last is not None and last!=i) else 0)
|
|
t=start+s; last=i
|
|
idx[i]+=1
|
|
if idx[i]<len(sessions[i]): ready[i]=t+sessions[i][idx[i]][1]
|
|
else: done[i]=t
|
|
return t
|
|
for scale in (1.0,0.4):
|
|
for sw in (0.1,0.3):
|
|
print('--- service scale %.1f (1.0=as recorded era, 0.4~faster decode) switch %.1f s'%(scale,sw))
|
|
for a,b in itertools.combinations(S,2):
|
|
seq=solo(S[a],scale)+solo(S[b],scale)
|
|
con=fifo([S[a],S[b]],scale,sw)
|
|
print(a,b,'seq %.0f conc %.0f speedup %.3f'%(seq,con,seq/con))
|
|
seq=sum(solo(S[k],scale) for k in S); con=fifo(list(S.values()),scale,sw)
|
|
print('all4 seq %.0f conc %.0f speedup %.3f'%(seq,con,seq/con))
|