forked from mtusi2026/mtusi2026lab3
Lab3 - оценка 5
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import statistics as st
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
OUT = ROOT / 'evidence' / 'track1'
|
||||
RAW = OUT / 'raw'
|
||||
|
||||
ORDER = ['f1x2.0', 'f2x1.0', 'f4x0.5', 'g1', 'g2', 'g4', 'g8']
|
||||
|
||||
|
||||
def load():
|
||||
runs = [json.loads(p.read_text(encoding='utf-8')) for p in sorted(RAW.glob('*.json'))
|
||||
if not p.name.endswith('.k6.json')]
|
||||
groups = {}
|
||||
for r in runs:
|
||||
groups.setdefault(r['config'], []).append(r)
|
||||
return groups
|
||||
|
||||
|
||||
def summarize(runs):
|
||||
def agg(vals):
|
||||
return {'mean': round(st.mean(vals), 1), 'min': round(min(vals), 1), 'max': round(max(vals), 1)}
|
||||
first = runs[0]
|
||||
svc = lambda name, key: [r['docker_stats'].get(name, {}).get(key, 0) for r in runs]
|
||||
return {
|
||||
'replicas': first['replicas'], 'cpus_per_replica': first['cpus_per_replica'],
|
||||
'mem_per_replica': first['mem_per_replica'], 'db_pool_per_replica': first['db_pool_per_replica'],
|
||||
'extra_env': first.get('extra_env', {}), 'repeats': len(runs), 'vus': first['vus'],
|
||||
'duration': first['duration'],
|
||||
'rps': agg([r['rps'] for r in runs]),
|
||||
'p50_ms': agg([r['latency_ms']['p(50)'] for r in runs]),
|
||||
'p95_ms': agg([r['latency_ms']['p(95)'] for r in runs]),
|
||||
'p99_ms': agg([r['latency_ms']['p(99)'] for r in runs]),
|
||||
'error_ratio_max': max(r['error_ratio'] for r in runs),
|
||||
'cpu_pct': {s: round(st.mean(svc(s, 'cpu_pct_mean')), 1) for s in ('api', 'postgres', 'lb', 'valkey')},
|
||||
'api_cpu_max_one_replica_pct': round(max(svc('api', 'cpu_pct_max_one_container')), 1),
|
||||
'mem_mib': {s: round(st.mean(svc(s, 'mem_mib_mean')), 1) for s in ('api', 'postgres', 'lb', 'valkey')},
|
||||
'pg_active_backends': round(st.mean(r['postgres']['active_backends_mean'] for r in runs), 1),
|
||||
'pg_top_waits': top_waits(runs),
|
||||
}
|
||||
|
||||
|
||||
def top_waits(runs):
|
||||
acc = {}
|
||||
for r in runs:
|
||||
for k, v in r['postgres']['wait_events_mean'].items():
|
||||
acc[k] = acc.get(k, 0) + v / len(runs)
|
||||
return {k: round(v, 2) for k, v in sorted(acc.items(), key=lambda x: -x[1])[:4]}
|
||||
|
||||
|
||||
FONT = 'font-family="system-ui,Segoe UI,Arial" font-size="12"'
|
||||
C1, C2, C3, C4 = '#2563eb', '#dc2626', '#16a34a', '#9333ea'
|
||||
|
||||
|
||||
def svg_wrap(w, h, body, title):
|
||||
return ('<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" viewBox="0 0 %d %d" %s>'
|
||||
'<rect width="100%%" height="100%%" fill="#fff"/>'
|
||||
'<text x="%d" y="20" text-anchor="middle" font-size="14" font-weight="600">%s</text>%s</svg>\n'
|
||||
% (w, h, w, h, FONT, w // 2, title, body))
|
||||
|
||||
|
||||
def axis(x0, y0, x1, y1, ymax, ylabel, ticks=5, right=False, color='#333'):
|
||||
b = ''
|
||||
xa = x1 if right else x0
|
||||
for i in range(ticks + 1):
|
||||
v = ymax * i / ticks
|
||||
y = y1 - (y1 - y0) * i / ticks
|
||||
if not right:
|
||||
b += '<line x1="%d" y1="%.1f" x2="%d" y2="%.1f" stroke="#e5e7eb"/>' % (x0, y, x1, y)
|
||||
b += '<text x="%d" y="%.1f" text-anchor="%s" fill="%s">%g</text>' % (
|
||||
xa + (6 if right else -6), y + 4, 'start' if right else 'end', color, round(v, 1))
|
||||
b += '<text transform="translate(%d,%d) rotate(-90)" text-anchor="middle" fill="%s">%s</text>' % (
|
||||
xa + (48 if right else -48), (y0 + y1) // 2, color, ylabel)
|
||||
return b
|
||||
|
||||
|
||||
def nice(v):
|
||||
for e in range(0, 7):
|
||||
for m in (1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8):
|
||||
c = m * 10 ** e
|
||||
if c >= v:
|
||||
return c
|
||||
return v
|
||||
|
||||
|
||||
def bar_chart(names, series, title, ylabel, path):
|
||||
w, h, x0, y0, x1, y1 = 640, 380, 70, 40, 610, 300
|
||||
ymax = nice(max(v[2] for _, _, vals in series for v in vals) * 1.1)
|
||||
b = axis(x0, y0, x1, y1, ymax, ylabel)
|
||||
gw = (x1 - x0) / len(names)
|
||||
bw = gw * 0.7 / len(series)
|
||||
for i, n in enumerate(names):
|
||||
b += '<text x="%.1f" y="%d" text-anchor="middle">%s</text>' % (x0 + gw * (i + .5), y1 + 18, n)
|
||||
for j, (lab, col, vals) in enumerate(series):
|
||||
mean, lo, hi = vals[i]
|
||||
x = x0 + gw * i + gw * 0.15 + bw * j
|
||||
y = y1 - (y1 - y0) * mean / ymax
|
||||
b += '<rect x="%.1f" y="%.1f" width="%.1f" height="%.1f" fill="%s"/>' % (x, y, bw - 2, y1 - y, col)
|
||||
ylo, yhi = (y1 - (y1 - y0) * v / ymax for v in (lo, hi))
|
||||
cx = x + (bw - 2) / 2
|
||||
b += '<line x1="%.1f" y1="%.1f" x2="%.1f" y2="%.1f" stroke="#111"/>' % (cx, ylo, cx, yhi)
|
||||
b += '<text x="%.1f" y="%.1f" text-anchor="middle" font-size="11">%g</text>' % (cx, y - 6 if yhi > y - 4 else yhi - 4, round(mean))
|
||||
lx = x0
|
||||
for lab, col, _ in series:
|
||||
b += '<rect x="%d" y="%d" width="12" height="12" fill="%s"/><text x="%d" y="%d">%s</text>' % (lx, y1 + 32, col, lx + 16, y1 + 42, lab)
|
||||
lx += 20 + 8 * len(lab)
|
||||
b += '<text x="%d" y="%d" fill="#666" font-size="11">столбец = среднее, отрезок = min..max по повторам</text>' % (x0, h - 8)
|
||||
path.write_text(svg_wrap(w, h, b, title), encoding='utf-8')
|
||||
|
||||
|
||||
def line_chart(xs, left, right, title, xlabel, ylabel_l, ylabel_r, path, rmax=None):
|
||||
w, h, x0, y0, x1, y1 = 680, 380, 80, 40, 600, 300
|
||||
lmax = nice(max(v for _, _, vals, _ in left for v in vals) * 1.1)
|
||||
rmax = rmax or nice(max(v for _, _, vals, _ in right for v in vals) * 1.1)
|
||||
b = axis(x0, y0, x1, y1, lmax, ylabel_l) + axis(x0, y0, x1, y1, rmax, ylabel_r, right=True, color='#555')
|
||||
px = lambda i: x0 + (x1 - x0) * i / (len(xs) - 1)
|
||||
for i, x in enumerate(xs):
|
||||
b += '<text x="%.1f" y="%d" text-anchor="middle">%s</text>' % (px(i), y1 + 18, x)
|
||||
b += '<text x="%d" y="%d" text-anchor="middle">%s</text>' % ((x0 + x1) // 2, y1 + 36, xlabel)
|
||||
for group, ymax in ((left, lmax), (right, rmax)):
|
||||
for lab, col, vals, dashed in group:
|
||||
pts = ' '.join('%.1f,%.1f' % (px(i), y1 - (y1 - y0) * v / ymax) for i, v in enumerate(vals))
|
||||
b += '<polyline points="%s" fill="none" stroke="%s" stroke-width="2.5"%s/>' % (
|
||||
pts, col, ' stroke-dasharray="6 4"' if dashed else '')
|
||||
for i, v in enumerate(vals):
|
||||
b += '<circle cx="%.1f" cy="%.1f" r="3.5" fill="%s"/>' % (px(i), y1 - (y1 - y0) * v / ymax, col)
|
||||
lx = x0
|
||||
for lab, col, _, dashed in left + right:
|
||||
b += '<line x1="%d" y1="%d" x2="%d" y2="%d" stroke="%s" stroke-width="2.5"%s/><text x="%d" y="%d">%s</text>' % (
|
||||
lx, y1 + 56, lx + 18, y1 + 56, col, ' stroke-dasharray="6 4"' if dashed else '', lx + 22, y1 + 60, lab)
|
||||
lx += 34 + 7 * len(lab)
|
||||
path.write_text(svg_wrap(w, h, b, title), encoding='utf-8')
|
||||
|
||||
|
||||
def main():
|
||||
groups = load()
|
||||
res = {k: summarize(v) for k, v in groups.items()}
|
||||
keys = [k for k in ORDER if k in res] + sorted(k for k in res if k not in ORDER)
|
||||
(OUT / 'results.json').write_text(json.dumps({k: res[k] for k in keys}, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
||||
|
||||
lines = ['| Конфигурация | Реплики × CPU / RAM, пул | RPS mean (min–max) | p50 / p95 / p99, мс | ошибки | CPU% api / pg / lb | PG active, топ ожиданий |',
|
||||
'| --- | --- | --- | --- | --- | --- | --- |']
|
||||
for k in keys:
|
||||
r = res[k]
|
||||
lines.append('| %s | %d × %s / %s, %d | %g (%g–%g) | %g / %g / %g | %g | %g / %g / %g | %g; %s |' % (
|
||||
k, r['replicas'], r['cpus_per_replica'], r['mem_per_replica'], r['db_pool_per_replica'],
|
||||
r['rps']['mean'], r['rps']['min'], r['rps']['max'], r['p50_ms']['mean'], r['p95_ms']['mean'],
|
||||
r['p99_ms']['mean'], r['error_ratio_max'], r['cpu_pct']['api'], r['cpu_pct']['postgres'],
|
||||
r['cpu_pct']['lb'], r['pg_active_backends'],
|
||||
', '.join('%s %g' % kv for kv in list(r['pg_top_waits'].items())[:2])))
|
||||
(OUT / 'summary.md').write_text('\n'.join(lines) + '\n', encoding='utf-8')
|
||||
print('\n'.join(lines))
|
||||
|
||||
fixed = [k for k in ('f1x2.0', 'f2x1.0', 'f4x0.5') if k in res]
|
||||
if fixed:
|
||||
g = lambda key: [(res[k][key]['mean'], res[k][key]['min'], res[k][key]['max']) for k in fixed]
|
||||
bar_chart(['1 × 2.0 CPU', '2 × 1.0 CPU', '4 × 0.5 CPU'][:len(fixed)], [('RPS', C1, g('rps'))],
|
||||
'Фиксированный бюджет API (2 CPU, 512 MiB, 20 соединений): RPS', 'успешные запросы/с', OUT / 'fixed-rps.svg')
|
||||
bar_chart(['1 × 2.0 CPU', '2 × 1.0 CPU', '4 × 0.5 CPU'][:len(fixed)],
|
||||
[('p50', C3, g('p50_ms')), ('p95', C1, g('p95_ms')), ('p99', C2, g('p99_ms'))],
|
||||
'Фиксированный бюджет API: задержка', 'мс', OUT / 'fixed-latency.svg')
|
||||
growth = [k for k in ('g1', 'g2', 'g4', 'g8') if k in res]
|
||||
if len(growth) >= 2:
|
||||
xs = [res[k]['replicas'] for k in growth]
|
||||
line_chart(xs, [('RPS', C1, [res[k]['rps']['mean'] for k in growth], False)],
|
||||
[('CPU API (сумма)', C3, [res[k]['cpu_pct']['api'] for k in growth], True),
|
||||
('CPU PostgreSQL', C2, [res[k]['cpu_pct']['postgres'] for k in growth], True),
|
||||
('CPU HAProxy', C4, [res[k]['cpu_pct']['lb'] for k in growth], True)],
|
||||
'Рост числа реплик (по 1 CPU), PostgreSQL 2 CPU', 'API-реплик',
|
||||
'успешные запросы/с', 'CPU, % ядра', OUT / 'growth.svg')
|
||||
line_chart(xs, [('p95, мс', C1, [res[k]['p95_ms']['mean'] for k in growth], False),
|
||||
('p99, мс', C2, [res[k]['p99_ms']['mean'] for k in growth], False)],
|
||||
[('активных backend PG', C3, [res[k]['pg_active_backends'] for k in growth], True)],
|
||||
'Рост числа реплик: задержка и очередь в PostgreSQL', 'API-реплик', 'мс',
|
||||
'активные сессии PG', OUT / 'growth-latency.svg')
|
||||
ab = [('g2-tx', 'g2-oneshot'), ('g4-tx', 'g4-oneshot')]
|
||||
if all(k in res for pair in ab for k in pair):
|
||||
g = lambda keys, m: [(res[k][m]['mean'], res[k][m]['min'], res[k][m]['max']) for k in keys]
|
||||
bar_chart(['2 реплики', '4 реплики'], [('tx: 5 round trip', C2, g([a for a, _ in ab], 'rps')),
|
||||
('oneshot: 1 запрос', C3, g([b for _, b in ab], 'rps'))],
|
||||
'Улучшение: запись сообщения одним SQL-оператором', 'успешные запросы/с', OUT / 'improvement-rps.svg')
|
||||
bar_chart(['2 реплики', '4 реплики'], [('tx p95', C2, g([a for a, _ in ab], 'p95_ms')),
|
||||
('oneshot p95', C3, g([b for _, b in ab], 'p95_ms'))],
|
||||
'Улучшение: p95 задержки', 'мс', OUT / 'improvement-p95.svg')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
RAW = ROOT / 'evidence' / 'track1' / 'raw'
|
||||
PROJECT = 'mtusi-lab3'
|
||||
|
||||
SERIES = {
|
||||
'fixed': {'f1x2.0': (1, '2.0', '512M', 20), 'f2x1.0': (2, '1.0', '256M', 10), 'f4x0.5': (4, '0.5', '128M', 5)},
|
||||
'growth': {'g1': (1, '1.0', '256M', 10), 'g2': (2, '1.0', '256M', 10),
|
||||
'g4': (4, '1.0', '256M', 10), 'g8': (8, '1.0', '256M', 10)},
|
||||
}
|
||||
|
||||
|
||||
def sh(args, env=None, check=True):
|
||||
r = subprocess.run(args, cwd=ROOT, capture_output=True, text=True, encoding='utf-8', env=env)
|
||||
if check and r.returncode != 0:
|
||||
raise RuntimeError(' '.join(args[:4]) + ': ' + r.stderr[-400:])
|
||||
return r.stdout
|
||||
|
||||
|
||||
def compose_env(cfg, extra):
|
||||
n, cpus, mem, pool = cfg
|
||||
env = dict(os.environ, API_REPLICAS=str(n), API_CPUS=cpus, API_MEMORY=mem, DB_MAX_CONNS=str(pool))
|
||||
env.update(extra)
|
||||
return env
|
||||
|
||||
|
||||
def apply(cfg, extra):
|
||||
env = compose_env(cfg, extra)
|
||||
sh(['docker', 'compose', 'up', '-d', '--wait', '--force-recreate', '--no-deps', 'api'], env=env)
|
||||
sh(['docker', 'compose', 'up', '-d', '--wait', '--no-deps', 'lb'], env=env)
|
||||
deadline = time.monotonic() + 60
|
||||
while time.monotonic() < deadline:
|
||||
seen = set()
|
||||
for _ in range(4 * cfg[0] + 4):
|
||||
with urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2) as r:
|
||||
seen.add(r.headers['X-Instance-Id'])
|
||||
if len(seen) == cfg[0]:
|
||||
return sorted(seen)
|
||||
time.sleep(1)
|
||||
raise RuntimeError('LB does not see %d replicas' % cfg[0])
|
||||
|
||||
|
||||
def parse_mem(s):
|
||||
m = re.match(r'([\d.]+)\s*([KMG]i?B|B)', s.strip())
|
||||
if not m:
|
||||
return None
|
||||
k = {'B': 1 / 2**20, 'KiB': 1 / 1024, 'KB': 1 / 1024, 'MiB': 1, 'MB': 1, 'GiB': 1024, 'GB': 1024}[m.group(2)]
|
||||
return float(m.group(1)) * k
|
||||
|
||||
|
||||
class Sampler(threading.Thread):
|
||||
def __init__(self):
|
||||
super().__init__(daemon=True)
|
||||
self.stop = threading.Event()
|
||||
self.stats = []
|
||||
self.pg = []
|
||||
|
||||
def run(self):
|
||||
while not self.stop.is_set():
|
||||
out = sh(['docker', 'stats', '--no-stream', '--format', '{{json .}}'], check=False)
|
||||
snap = {}
|
||||
for line in out.splitlines():
|
||||
try:
|
||||
d = json.loads(line)
|
||||
except ValueError:
|
||||
continue
|
||||
m = re.match(PROJECT + r'-(\w+?)-\d+$', d['Name'])
|
||||
if not m:
|
||||
continue
|
||||
cpu = float(d['CPUPerc'].rstrip('%') or 0)
|
||||
s = snap.setdefault(m.group(1), {'cpu': 0.0, 'mem_mib': 0.0, 'max_cpu': 0.0, 'n': 0})
|
||||
s['cpu'] += cpu
|
||||
s['max_cpu'] = max(s['max_cpu'], cpu)
|
||||
s['mem_mib'] += parse_mem(d['MemUsage'].split('/')[0]) or 0
|
||||
s['n'] += 1
|
||||
if snap:
|
||||
self.stats.append(snap)
|
||||
q = ("SELECT coalesce(wait_event_type,'CPU')||':'||coalesce(wait_event,'-'), count(*) "
|
||||
"FROM pg_stat_activity WHERE state='active' AND backend_type='client backend' "
|
||||
"AND pid<>pg_backend_pid() GROUP BY 1")
|
||||
out = sh(['docker', 'compose', 'exec', '-T', 'postgres', 'psql', '-U', 'messenger', '-d', 'messenger',
|
||||
'-At', '-F', '|', '-c', q], check=False)
|
||||
waits = {}
|
||||
for line in out.splitlines():
|
||||
if '|' in line:
|
||||
k, v = line.rsplit('|', 1)
|
||||
waits[k] = int(v)
|
||||
self.pg.append({'active': sum(waits.values()), 'waits': waits})
|
||||
|
||||
|
||||
K6_CPUS = '4'
|
||||
|
||||
|
||||
def k6(name, vus, duration, run_id, summary=None):
|
||||
args = ['docker', 'run', '--rm', '--network', PROJECT + '_app', '--cpus', K6_CPUS,
|
||||
'-v', str(ROOT / 'infra' / 'k6') + ':/scripts:ro',
|
||||
'-e', 'VUS=%d' % vus, '-e', 'DURATION=' + duration, '-e', 'RUN_ID=' + run_id]
|
||||
if summary:
|
||||
args += ['-v', str(RAW) + ':/out']
|
||||
args += ['grafana/k6:0.54.0', 'run', '--quiet']
|
||||
if summary:
|
||||
args += ['--summary-export', '/out/' + summary]
|
||||
args += ['/scripts/track1.js']
|
||||
env = dict(os.environ, MSYS_NO_PATHCONV='1')
|
||||
sh(args, env=env)
|
||||
|
||||
|
||||
def aggregate(sampler):
|
||||
svc = {}
|
||||
for snap in sampler.stats:
|
||||
for k, v in snap.items():
|
||||
svc.setdefault(k, []).append(v)
|
||||
out = {}
|
||||
for k, vals in svc.items():
|
||||
out[k] = {'cpu_pct_mean': round(sum(v['cpu'] for v in vals) / len(vals), 1),
|
||||
'cpu_pct_max_one_container': round(max(v['max_cpu'] for v in vals), 1),
|
||||
'mem_mib_mean': round(sum(v['mem_mib'] for v in vals) / len(vals), 1),
|
||||
'containers': vals[-1]['n']}
|
||||
waits = {}
|
||||
for s in sampler.pg:
|
||||
for k, v in s['waits'].items():
|
||||
waits[k] = waits.get(k, 0) + v
|
||||
n = max(1, len(sampler.pg))
|
||||
return out, {'samples': len(sampler.pg),
|
||||
'active_backends_mean': round(sum(s['active'] for s in sampler.pg) / n, 1),
|
||||
'wait_events_mean': {k: round(v / n, 2) for k, v in sorted(waits.items(), key=lambda x: -x[1])}}
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument('--series', choices=list(SERIES), required=True)
|
||||
p.add_argument('--only', nargs='*', default=None, help='subset of config names')
|
||||
p.add_argument('--repeat', type=int, default=3)
|
||||
p.add_argument('--vus', type=int, default=128)
|
||||
p.add_argument('--warmup', default='10s')
|
||||
p.add_argument('--duration', default='30s')
|
||||
p.add_argument('--tag', default='', help='suffix for an experiment variant, e.g. "-v2"')
|
||||
p.add_argument('--env', nargs='*', default=[], help='extra compose env KEY=VALUE')
|
||||
p.add_argument('--start-repeat', type=int, default=1, help='number of the first repeat (to interleave variants)')
|
||||
p.add_argument('--k6-cpus', default='4')
|
||||
a = p.parse_args()
|
||||
global K6_CPUS
|
||||
K6_CPUS = a.k6_cpus
|
||||
RAW.mkdir(parents=True, exist_ok=True)
|
||||
extra = dict(kv.split('=', 1) for kv in a.env)
|
||||
cfgs = {k: v for k, v in SERIES[a.series].items() if not a.only or k in a.only}
|
||||
for rep in range(a.start_repeat, a.start_repeat + a.repeat):
|
||||
for name, cfg in cfgs.items():
|
||||
label = '%s%s-r%d' % (name, a.tag, rep)
|
||||
print('==', label, cfg, flush=True)
|
||||
replicas = apply(cfg, extra)
|
||||
k6(name, a.vus, a.warmup, 'w%s%d' % (name.replace('.', ''), int(time.time())))
|
||||
sampler = Sampler()
|
||||
sampler.start()
|
||||
t0 = time.time()
|
||||
run_id = 'm%s%d' % (name.replace('.', ''), int(t0))
|
||||
k6(name, a.vus, a.duration, run_id, summary=label + '.k6.json')
|
||||
sampler.stop.set()
|
||||
sampler.join(timeout=20)
|
||||
stats, pg = aggregate(sampler)
|
||||
summary_path = RAW / (label + '.k6.json')
|
||||
k6sum = json.loads(summary_path.read_text(encoding='utf-8'))
|
||||
k6sum.pop('setup_data', None)
|
||||
summary_path.write_text(json.dumps(k6sum, indent=2) + '\n', encoding='utf-8')
|
||||
k = k6sum['metrics']
|
||||
dur = k['http_req_duration']
|
||||
rec = {'label': label, 'config': name + a.tag, 'series': a.series, 'repeat': rep,
|
||||
'replicas': cfg[0], 'cpus_per_replica': cfg[1], 'mem_per_replica': cfg[2],
|
||||
'db_pool_per_replica': cfg[3], 'extra_env': extra, 'k6_cpus': K6_CPUS, 'vus': a.vus, 'duration': a.duration,
|
||||
'started_unix': int(t0), 'instances': replicas,
|
||||
'rps': round(k['http_reqs']['rate'], 1),
|
||||
'error_ratio': round(k['http_req_failed']['value'], 6),
|
||||
'latency_ms': {q: round(dur[q], 2) for q in ('p(50)', 'p(95)', 'p(99)', 'max')},
|
||||
'docker_stats': stats, 'postgres': pg}
|
||||
(RAW / (label + '.json')).write_text(json.dumps(rec, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
||||
print(' rps=%s err=%s p95=%s api_cpu=%s pg_cpu=%s lb_cpu=%s pg_active=%s' % (
|
||||
rec['rps'], rec['error_ratio'], rec['latency_ms']['p(95)'],
|
||||
stats.get('api', {}).get('cpu_pct_mean'), stats.get('postgres', {}).get('cpu_pct_mean'),
|
||||
stats.get('lb', {}).get('cpu_pct_mean'), pg['active_backends_mean']), flush=True)
|
||||
apply((2, '1.0', '256M', 10), {})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user