"""Bounded closed-loop HTTP load, raw latency and Docker resource samples.""" from concurrent.futures import ThreadPoolExecutor import csv import json import math from pathlib import Path import subprocess import threading import time import uuid import httpx ROOT=Path(__file__).resolve().parents[1] def docker(*args): return subprocess.check_output(['docker',*args],cwd=ROOT,text=True,encoding='utf-8').strip() rows=[]; samples=[]; done=threading.Event() def sample(): while not done.is_set(): data=docker('stats','--no-stream','--format','{{json .}}',*docker('compose','ps','-q').splitlines()) samples.extend({'elapsed_s':round(time.perf_counter()-start,3),**json.loads(line)} for line in data.splitlines()) done.wait(1) with httpx.Client(base_url='http://127.0.0.1:8080',timeout=10) as c: body={'username':'load_'+uuid.uuid4().hex[:18],'display_name':'Load','password':'synthetic-password-123'} user=c.post('/api/v1/users',json=body).json() auth=c.post('/api/v1/auth/sessions',auth=(body['username'],body['password'])).json() headers={'Authorization':'Bearer '+auth['token']} chat=c.post('/api/v1/chats',headers=headers,json={'title':'load','member_ids':[user['id']]}).json() path='/api/v1/chats/'+chat['id']+'/messages' # Warm up the pool/cache for 2 seconds, outside measurement. deadline=time.perf_counter()+2 while time.perf_counter()