~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
47 lines · 2.5 KB Raw History
import argparse
import json
import re
from pathlib import Path
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

parser = argparse.ArgumentParser()
parser.add_argument('root', type=Path)
parser.add_argument('output', type=Path)
a = parser.parse_args()
ss = [json.loads(line) for line in (a.root / 'samples.jsonl').read_text().splitlines()]
def series(pattern, key='metrics', scale=2**20):
    return [(s['seconds'],float(m.group(1))/scale) for s in ss if (m:=re.search(pattern,s[key] or '',re.M))]
fig, axes=plt.subplots(1,3,figsize=(13,5.2))
axes[0].plot(*zip(*series(r'^VmRSS:\s+(\d+)','status',1024)),color='#176d9c',linewidth=2)
axes[0].set_title('Relay resident memory',loc='left')
axes[0].set_ylabel('MiB RSS')
for pattern,label,color in [
    (r'^relay_cache_logical_bytes\{component="signing_keys"\}\s+(\S+)','Signing-key nodes + keys','#798b44'),
    (r'^relay_cache_logical_bytes\{component="did_uids"\}\s+(\S+)','DID/UID nodes + keys','#27857c'),
    (r'^relay_cache_logical_bytes\{component="host_ids"\}\s+(\S+)','Host-ID nodes + keys','#b55b25'),
    (r'^relay_zkv_block_cache_bytes\s+(\S+)','ZKV block-cache accounting','#8054b1'),
    (r'^relay_zkv_memtable_bytes\s+(\S+)','Writer memtable payload','#8c969c')]:
    data=series(pattern)
    axes[1].plot(*zip(*data),label=label,color=color,linewidth=1.7)
axes[1].set_title('Measured cache components',loc='left')
axes[1].set_ylabel('MiB logical/accounted bytes')
axes[1].legend(frameon=False,fontsize=7,loc='upper left')
axes[1].set_ylim(0,2.1)
axes[2].plot(*zip(*series(r'^relay_pool_queued_bytes\s+(\S+)')),color='#b55b25',linewidth=2)
axes[2].set_title('Queued frame payload',loc='left')
axes[2].set_ylabel('MiB queued')
for ax in axes:
    ax.set_xlabel('Elapsed seconds')
    ax.set_xlim(0,130)
    ax.set_ylim(bottom=0)
    ax.spines[['top','right']].set_visible(False)
    ax.grid(alpha=.15)
fig.suptitle('Live relay with RAM and disk replay disabled',x=.07,ha='left',fontsize=17)
fig.text(.07,.88,'2 shared CPUs / 2 GiB; default cache limits; real upstream traffic; RAM history remained at zero.',fontsize=10)
fig.text(.07,.045,'Cache bytes exclude hashmap slack, allocator overhead/retention, TLS, socket buffers and stacks. Different panel scales; not an RSS decomposition.',fontsize=9)
fig.subplots_adjust(left=.07,right=.98,top=.76,bottom=.21,wspace=.42)
fig.savefig(a.output,facecolor='white')
a.output.write_text('\n'.join(l.rstrip() for l in a.output.read_text().splitlines())+'\n')
fig.savefig(a.output.with_suffix('.png'),dpi=150,facecolor='white')