nx_mesh_lb.nx
buildroot/runtime/nx_mesh_lb.nx
about
nx_mesh_lb.nx -- WORKER MESH: multi-worker LOAD BALANCER + HEALTH-AWARE routing (the Triton/Ray replica-routing
analog). A worker CLASS (e.g. gpu-image) has N registered endpoints (laptop 5080, west 3090, ...). On a request the
balancer HEALTH-PROBES each endpoint (bounded, non-blocking connect so a down replica is skipped in ~1s), then
picks a HEALTHY one by round-robin (persisted counter -> spreads load), skipping every unhealthy replica. If none
is healthy it refuses. This is what turns "one worker per class" into a real load-balanced mesh, and it is exactly
how a second worker (west 3090) or a cloud replica joins: add an endpoint row, zero code.
CLI: (no args) -> self-test GATE (round-robin + health-skip + no-healthy + liar-kills)
pick <class> -> live: probe the class's endpoints, print health vector + the chosen replica
Classes: gpu-image (laptop 5080 + west 3090). NO fake greens: the gate proves it NEVER picks an unhealthy replica.
license_tier: ORIGINAL
dependencies 6 imports · 0 importers
imports: nx_syscalls.nxnx_estate_path.nxnx_connect.nxnx_runtime.nxnx_http_client.nxnx_swarm_endpoint_lib.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 30 | const LB_MAGIC_5080: i64 = 5080 |
| 31 | const LB_MAGIC_3090: i64 = 3090 |
| 32 | const LB_MAGIC_7861: i64 = 7861 |
| 33 | const LB_MAGIC_2048: i64 = 2048 |
| 34 | const LB_MAGIC_2000: i64 = 2000 |
| 35 | const LB_MAGIC_16384: i64 = 16384 |
| 36 | const LB_MAGIC_16383: i64 = 16383 |
| 57 | const LB_N_IMAGE: i64 = 2 |
functions
| 21 | func ml_where_role(role: *u8, label: *u8) -> *u8 |
| 38 | func lb_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 } |
| 39 | func lb_wn(fd: i64, v: i64) -> i64 |
| 52 | func lb_p(s: *u8) -> i64 { return lb_w(1, s) } |
| 53 | func lb_pn(v: i64) -> i64 { return lb_wn(1, v) } |
| 54 | func lb_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while b[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if a[i] != (0 as u8) { return 0 } return 1 } called by 1: main |
| 58 | func lb_ep(idx: i64, oct: *i64) -> i64 called by 1: main |
| 63 | func lb_ep_label(idx: i64) -> *u8 |
| 70 | func lb_pick(health: *i64, n: i64, counter: i64) -> i64 |
| 89 | func lb_pollfd(pfd: *u8, fd: i64, events: i64) -> i64 called by 1: lb_probe |
| 95 | func lb_resp_2xx(buf: *u8, n: i64) -> i64 called by 1: lb_probe |
| 104 | func lb_probe(a: i64, b: i64, c: i64, d: i64) -> i64 called by 1: main calls 11: sys_mmapnx_http_client_sockaddr_ipv4sys_socketnx_connect_boundedlb_pollfdsys_poll+5 |
| 131 | func lb_counter_read() -> i64 |
| 142 | func lb_counter_write(v: i64) -> i64 |
| 150 | func lb_gate() -> i64 |
| 193 | func main(argc: i64, argv: *i64) -> i64 |