code wiki / _hdl_build / nx_apm_mock.nx

nx_apm_mock.nx

buildroot/runtime/_hdl_build/nx_apm_mock.nx

4207 B82 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic apm
docsdependenciesstructsconstsfunctions

about

nx_apm_mock.nx -- SOVEREIGN controllable mock HTTP daemon for gating the internal APM collector. WHY: the collector (nx_apm_collect) must be PROVEN to (a) measure low latency on a healthy daemon, (b) detect a daemon that SERIALIZES + wedges under concurrent load (the live :8791 reader symptom), (c) survive a daemon that is slower than the probe timeout (graceful degradation, no infinite hang), and (d) NOT report a DOWN daemon as healthy (liar-kill). This mock provides all four conditions deterministically without touching any real daemon. It is SINGLE-THREADED-SERIAL on purpose: it accepts one connection at a time, optionally sleeps `delay_ms`, then responds 200 + closes. Under N concurrent connects the Nth client therefore waits ~N*delay_ms -- exactly the serialization-amplification that makes "tabs don't load". It serves `max_reqs` requests then exits (SELF-TERMINATING -> the gate needs no kill primitive; it just reaps). usage: nx_apm_mock <port> <delay_ms> <max_reqs> (binds 127.0.0.1 only -- never LAN-exposed) license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_apm_mock.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main amk_atoi apm_mock_listen sys_socket sys_mmap sys_setsockopt amk_addr sys_bind sys_close sys_listen amk_slen sys_accept sys_sleep_ms sys_mmap ↻ sys_munmap sys_read sys_write

structs

none

consts

17const AMK_MAGIC_4096: i64 = 4096
18const AMK_MAGIC_18099: i64 = 18099
19const AMK_MAGIC_1000000: i64 = 1000000
21const AMK_RESP: *u8 = "HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok"

functions

23func amk_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: apm_mock_listen
26func amk_atoi(s: *u8) -> i64
called by 1: main
33func amk_addr(out: *u8, a: i64, b: i64, c: i64, d: i64, port: i64) -> i64
called by 1: apm_mock_listen
46func apm_mock_listen(port: i64, delay_ms: i64, hold_ms: i64, max_reqs: i64) -> i64
72func main(argc: i64, argv: *i64) -> i64