code wiki / (root) / nx_container_bench.nx

nx_container_bench.nx source

↩ module page · 240 lines · 12252 B

1// nx_container_bench.nx -- SOVEREIGN measured-exceed scorecard: Nishi Container Host vs Docker Desktop. 2// The no-wave JUDGE/AGGREGATOR (operator 2026-06-24: "s-class exceed container hosting strategy ... 3// measured-exceed vs Docker first"). Mirrors nx_gpu_bench's judge pattern. 4// 5// ROLE: this organ does NOT assert numbers. It INGESTS measurements taken LIVE on this machine 6// (knowledge/status/container_bench_measured.dat -- Docker booted+measured idle RAM/procs/cold-start 7// then torn down; Nishi governance/footprint measured) and computes an HONEST per-axis verdict 8// (EXCEEDS / PARITY / BEHIND / DIFFERENT-ALTITUDE). It REFUSES to score a different-config axis as an 9// exceed (gpu latency: 512^2 native vs 640x896 WSL2 = not comparable). LIAR-KILL: the verdict is COMPUTED 10// from the numbers, so a tampered "we win" cannot fool it; two negative controls prove the judge is not a 11// rubber-stamp. NO fake greens. license_tier: ORIGINAL 12import "nx_syscalls.nx" 13import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 14import "nx_runtime.nx" 15const CB_MAGIC_999999: i64 = 999999 16const CB_MAGIC_2774: i64 = 2774 17const CB_MAGIC_9999: i64 = 9999 18const CB_MAGIC_65536: i64 = 65536 19const CB_MAGIC_65535: i64 = 65535 20 21const CB_DAT: *u8 = "knowledge/status/container_bench_measured.dat" 22const CB_TSV: *u8 = "knowledge/status/container_bench.tsv" 23const CB_LOG: *u8 = "knowledge/status/container_bench.log" 24 25func cb_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 26// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 27// per call and never freed it. At page granularity that is 4096B leaked PER CALL -- the 28// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff. A BENCH is the worst home for 29// it: its purpose is millions of iterations. nxi_* is MSB-first and allocates NOTHING. 30func cb_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } 31func cb_p(s: *u8) -> i64 { return cb_w(1, s) } 32func cb_pn(v: i64) -> i64 { return cb_wn(1, v) } 33 34func cb_read(path: *u8, buf: *u8, cap: i64) -> i64 { 35 let fd: i64 = sys_openat_rd(path) 36 if fd < 0 { return 0 } 37 var tot: i64 = 0 38 var go: i64 = 1 39 while go == 1 { 40 let r: i64 = sys_read(fd, (buf as i64 + tot) as *u8, cap - tot) 41 if r <= 0 { go = 0 } else { tot = tot + r } 42 if tot >= cap { go = 0 } 43 } 44 sys_close(fd) 45 return tot 46} 47func cb_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 48func cb_find(buf: *u8, n: i64, pat: *u8, pl: i64) -> i64 { 49 if pl <= 0 { return 0 - 1 } 50 var i: i64 = 0 51 while i + pl <= n { 52 var k: i64 = 0 53 var hit: i64 = 1 54 while k < pl { if buf[i+k] != pat[k] { hit = 0; k = pl } else { k = k + 1 } } 55 if hit == 1 { return i + pl } 56 i = i + 1 57 } 58 return 0 - 1 59} 60func cb_read_int(buf: *u8, n: i64, key: *u8) -> i64 { 61 let kl: i64 = cb_strlen(key) 62 let p: i64 = cb_find(buf, n, key, kl) 63 if p < 0 { return 0 - CB_MAGIC_999999 } 64 var i: i64 = p 65 var v: i64 = 0 66 var any: i64 = 0 67 while i < n { 68 let c: i64 = buf[i] as i64 69 if c < 48 { i = n } else { if c > 57 { i = n } else { v = v * 10 + (c - 48); any = 1; i = i + 1 } } 70 } 71 if any == 0 { return 0 - CB_MAGIC_999999 } 72 return v 73} 74// dir_lower=1 => lower is better. comparable=0 => DIFFERENT-ALTITUDE. 1=EXCEEDS 0=PARITY (0-1)=BEHIND 2=DIFFERENT 75func cb_verdict(nishi: i64, docker: i64, dir_lower: i64, comparable: i64) -> i64 { 76 if comparable == 0 { return 2 } 77 if dir_lower == 1 { 78 if nishi < docker { return 1 } 79 if nishi > docker { return 0 - 1 } 80 return 0 81 } 82 if nishi > docker { return 1 } 83 if nishi < docker { return 0 - 1 } 84 return 0 85} 86func cb_vname(fd: i64, v: i64) -> i64 { 87 if v == 1 { cb_w(fd, "EXCEEDS" as *u8); return 0 } 88 if v == 0 { cb_w(fd, "PARITY" as *u8); return 0 } 89 if v == 2 { cb_w(fd, "DIFFERENT-ALTITUDE" as *u8); return 0 } 90 cb_w(fd, "BEHIND" as *u8) 91 return 0 92} 93func cb_row(fd: i64, name: *u8, nishi: i64, docker: i64, unit: *u8, v: i64) -> i64 { 94 cb_w(fd, name) 95 cb_w(fd, "\t" as *u8); cb_wn(fd, nishi) 96 cb_w(fd, "\t" as *u8); cb_wn(fd, docker) 97 cb_w(fd, "\t" as *u8); cb_w(fd, unit) 98 cb_w(fd, "\t" as *u8); cb_vname(fd, v) 99 cb_w(fd, "\n" as *u8) 100 return 0 101} 102 103func main() -> i64 { 104 cb_p("=== nx_container_bench: Nishi Container Host vs Docker -- sovereign no-wave scorecard (judge) ===\n" as *u8) 105 106 // ---- self-check KAT on the verdict engine ---- 107 var kat: i64 = 1 108 if cb_verdict(0, CB_MAGIC_2774, 1, 1) != 1 { kat = 0 } 109 if cb_verdict(5, 5, 1, 1) != 0 { kat = 0 } 110 if cb_verdict(10, 2, 1, 1) != (0 - 1) { kat = 0 } 111 if cb_verdict(99, 1, 1, 0) != 2 { kat = 0 } 112 113 // ---- LIAR-KILL negative controls (judge must not rubber-stamp) ---- 114 var neg1: i64 = 0 115 if cb_verdict(CB_MAGIC_9999, 10, 1, 1) == (0 - 1) { neg1 = 1 } 116 var neg2: i64 = 0 117 if cb_verdict(1, CB_MAGIC_9999, 1, 0) == 2 { neg2 = 1 } 118 119 // ---- ingest the LIVE measured data ---- 120 let buf: *u8 = sys_mmap(CB_MAGIC_65536) 121 let bn: i64 = cb_read(CB_DAT, buf, CB_MAGIC_65535) 122 var data_ok: i64 = 0 123 if bn > 0 { data_ok = 1 } 124 let ni_ram: i64 = cb_read_int(buf, bn, "nishi_idle_ram_mb=" as *u8) 125 let dk_ram: i64 = cb_read_int(buf, bn, "docker_idle_ram_mb=" as *u8) 126 let ni_proc: i64 = cb_read_int(buf, bn, "nishi_idle_procs=" as *u8) 127 let dk_proc: i64 = cb_read_int(buf, bn, "docker_idle_procs=" as *u8) 128 let ni_inst: i64 = cb_read_int(buf, bn, "nishi_install_bytes=" as *u8) 129 let dk_inst: i64 = cb_read_int(buf, bn, "docker_install_bytes=" as *u8) 130 let ni_cs: i64 = cb_read_int(buf, bn, "nishi_coldstart_ms=" as *u8) 131 let dk_cs: i64 = cb_read_int(buf, bn, "docker_coldstart_ms=" as *u8) 132 let ni_vm: i64 = cb_read_int(buf, bn, "nishi_vmtax_mb=" as *u8) 133 let dk_vm: i64 = cb_read_int(buf, bn, "docker_vmtax_mb=" as *u8) 134 let gpu_cmp: i64 = cb_read_int(buf, bn, "gpu_comparable=" as *u8) 135 let ni_gpu: i64 = cb_read_int(buf, bn, "nishi_gpu_ms=" as *u8) 136 let dk_gpu: i64 = cb_read_int(buf, bn, "docker_gpu_ms=" as *u8) 137 if ni_ram == (0 - CB_MAGIC_999999) { data_ok = 0 } 138 if dk_ram == (0 - CB_MAGIC_999999) { data_ok = 0 } 139 if ni_proc == (0 - CB_MAGIC_999999) { data_ok = 0 } 140 if dk_proc == (0 - CB_MAGIC_999999) { data_ok = 0 } 141 if ni_inst == (0 - CB_MAGIC_999999) { data_ok = 0 } 142 if dk_inst == (0 - CB_MAGIC_999999) { data_ok = 0 } 143 if ni_cs == (0 - CB_MAGIC_999999) { data_ok = 0 } 144 if dk_cs == (0 - CB_MAGIC_999999) { data_ok = 0 } 145 if ni_vm == (0 - CB_MAGIC_999999) { data_ok = 0 } 146 if dk_vm == (0 - CB_MAGIC_999999) { data_ok = 0 } 147 if gpu_cmp == (0 - CB_MAGIC_999999) { data_ok = 0 } 148 149 // ---- compute per-axis verdicts (all lower-better) ---- 150 let v_ram: i64 = cb_verdict(ni_ram, dk_ram, 1, 1) 151 let v_proc: i64 = cb_verdict(ni_proc, dk_proc, 1, 1) 152 let v_inst: i64 = cb_verdict(ni_inst, dk_inst, 1, 1) 153 let v_cs: i64 = cb_verdict(ni_cs, dk_cs, 1, 1) 154 let v_vm: i64 = cb_verdict(ni_vm, dk_vm, 1, 1) 155 let v_gpu: i64 = cb_verdict(ni_gpu, dk_gpu, 1, gpu_cmp) 156 157 // ---- tally ---- 158 var n_exc: i64 = 0 159 var n_diff: i64 = 0 160 var n_behind: i64 = 0 161 if v_ram == 1 { n_exc = n_exc + 1 } 162 if v_proc == 1 { n_exc = n_exc + 1 } 163 if v_inst == 1 { n_exc = n_exc + 1 } 164 if v_cs == 1 { n_exc = n_exc + 1 } 165 if v_vm == 1 { n_exc = n_exc + 1 } 166 if v_gpu == 1 { n_exc = n_exc + 1 } 167 if v_ram == 2 { n_diff = n_diff + 1 } 168 if v_proc == 2 { n_diff = n_diff + 1 } 169 if v_inst == 2 { n_diff = n_diff + 1 } 170 if v_cs == 2 { n_diff = n_diff + 1 } 171 if v_vm == 2 { n_diff = n_diff + 1 } 172 if v_gpu == 2 { n_diff = n_diff + 1 } 173 if v_ram == (0 - 1) { n_behind = n_behind + 1 } 174 if v_proc == (0 - 1) { n_behind = n_behind + 1 } 175 if v_inst == (0 - 1) { n_behind = n_behind + 1 } 176 if v_cs == (0 - 1) { n_behind = n_behind + 1 } 177 if v_vm == (0 - 1) { n_behind = n_behind + 1 } 178 if v_gpu == (0 - 1) { n_behind = n_behind + 1 } 179 180 // ---- emit scoreboard ---- 181 let tfd: i64 = sys_openat_wr(CB_TSV, 0x1a4) 182 if tfd >= 0 { 183 cb_w(tfd, "# nx_container_bench scoreboard -- Nishi Container Host vs Docker Desktop (measured live 2026-06-24, RTX 5080 laptop)\n" as *u8) 184 cb_w(tfd, "# axis\tnishi\tdocker\tunit\tverdict (lower=better; sovereign judge, numbers ingested not asserted)\n" as *u8) 185 cb_row(tfd, "idle_ram" as *u8, ni_ram, dk_ram, "MB" as *u8, v_ram) 186 cb_row(tfd, "idle_procs" as *u8, ni_proc, dk_proc, "count" as *u8, v_proc) 187 cb_row(tfd, "runtime_install" as *u8, ni_inst, dk_inst, "bytes" as *u8, v_inst) 188 cb_row(tfd, "coldstart_first_proc" as *u8, ni_cs, dk_cs, "ms" as *u8, v_cs) 189 cb_row(tfd, "isolation_vm_tax" as *u8, ni_vm, dk_vm, "MB" as *u8, v_vm) 190 cb_row(tfd, "gpu_latency" as *u8, ni_gpu, dk_gpu, "ms" as *u8, v_gpu) 191 cb_w(tfd, "# tally exceeds=" as *u8); cb_wn(tfd, n_exc) 192 cb_w(tfd, " different-altitude=" as *u8); cb_wn(tfd, n_diff) 193 cb_w(tfd, " behind=" as *u8); cb_wn(tfd, n_behind) 194 cb_w(tfd, "\n" as *u8) 195 sys_close(tfd) 196 } 197 198 // ---- stdout summary ---- 199 cb_p(" idle_ram MB nishi=" as *u8); cb_pn(ni_ram); cb_p(" docker=" as *u8); cb_pn(dk_ram); cb_p(" -> " as *u8); cb_vname(1, v_ram); cb_p("\n" as *u8) 200 cb_p(" idle_procs nishi=" as *u8); cb_pn(ni_proc); cb_p(" docker=" as *u8); cb_pn(dk_proc); cb_p(" -> " as *u8); cb_vname(1, v_proc); cb_p("\n" as *u8) 201 cb_p(" runtime_install B nishi=" as *u8); cb_pn(ni_inst); cb_p(" docker=" as *u8); cb_pn(dk_inst); cb_p(" -> " as *u8); cb_vname(1, v_inst); cb_p("\n" as *u8) 202 cb_p(" coldstart ms nishi=" as *u8); cb_pn(ni_cs); cb_p(" docker=" as *u8); cb_pn(dk_cs); cb_p(" -> " as *u8); cb_vname(1, v_cs); cb_p("\n" as *u8) 203 cb_p(" isolation_vm_tax MB nishi=" as *u8); cb_pn(ni_vm); cb_p(" docker=" as *u8); cb_pn(dk_vm); cb_p(" -> " as *u8); cb_vname(1, v_vm); cb_p("\n" as *u8) 204 cb_p(" gpu_latency ms nishi=" as *u8); cb_pn(ni_gpu); cb_p(" docker=" as *u8); cb_pn(dk_gpu); cb_p(" comparable=" as *u8); cb_pn(gpu_cmp); cb_p(" -> " as *u8); cb_vname(1, v_gpu); cb_p("\n" as *u8) 205 cb_p(" kat=" as *u8); cb_pn(kat); cb_p(" neg1=" as *u8); cb_pn(neg1); cb_p(" neg2=" as *u8); cb_pn(neg2); cb_p(" data_ok=" as *u8); cb_pn(data_ok); cb_p(" exceeds=" as *u8); cb_pn(n_exc); cb_p(" different=" as *u8); cb_pn(n_diff); cb_p(" behind=" as *u8); cb_pn(n_behind); cb_p("\n" as *u8) 206 207 // ---- gate ---- 208 var pass: i64 = 0 209 if kat == 1 { if neg1 == 1 { if neg2 == 1 { if data_ok == 1 { if n_exc == 5 { if n_diff == 1 { if n_behind == 0 { pass = 1 } } } } } } } 210 211 let lfd: i64 = sys_openat_append(CB_LOG, 0x1a4) 212 if pass == 1 { 213 cb_p("CONTAINERBENCHGATE verdict=GREEN (judge sound; 5/6 axes MEASURED-EXCEED vs Docker, gpu-latency honestly DIFFERENT-ALTITUDE; liar-kill neg-controls fired)\n" as *u8) 214 if lfd >= 0 { 215 cb_w(lfd, "CONTAINERBENCHGATE verdict=GREEN exceeds=" as *u8); cb_wn(lfd, n_exc) 216 cb_w(lfd, " different=" as *u8); cb_wn(lfd, n_diff) 217 cb_w(lfd, " behind=" as *u8); cb_wn(lfd, n_behind) 218 cb_w(lfd, " idle_ram_nishi=" as *u8); cb_wn(lfd, ni_ram) 219 cb_w(lfd, " idle_ram_docker=" as *u8); cb_wn(lfd, dk_ram) 220 cb_w(lfd, " coldstart_nishi=" as *u8); cb_wn(lfd, ni_cs) 221 cb_w(lfd, " coldstart_docker=" as *u8); cb_wn(lfd, dk_cs) 222 cb_w(lfd, " epoch=" as *u8); cb_wn(lfd, sys_now_realtime_sec()) 223 cb_w(lfd, "\n" as *u8) 224 sys_close(lfd) 225 } 226 cb_p("scoreboard -> knowledge/status/container_bench.tsv\n" as *u8) 227 return 0 228 } 229 cb_p("CONTAINERBENCHGATE verdict=RED (self-check or expected-profile failed)\n" as *u8) 230 if lfd >= 0 { 231 cb_w(lfd, "CONTAINERBENCHGATE verdict=RED kat=" as *u8); cb_wn(lfd, kat) 232 cb_w(lfd, " neg1=" as *u8); cb_wn(lfd, neg1) 233 cb_w(lfd, " neg2=" as *u8); cb_wn(lfd, neg2) 234 cb_w(lfd, " data_ok=" as *u8); cb_wn(lfd, data_ok) 235 cb_w(lfd, " exceeds=" as *u8); cb_wn(lfd, n_exc) 236 cb_w(lfd, "\n" as *u8) 237 sys_close(lfd) 238 } 239 return 1 240}