code wiki / (root) / nx_mesh_lb.nx

nx_mesh_lb.nx

buildroot/runtime/nx_mesh_lb.nx

10322 B227 linesdepth 6pulls 11 transitivereach 0 importersview sourcekind tooltopic mesh
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_estate_path.nx nx_connect.nx nx_runtime.nx nx_http_client.nx nx_swarm_endpoint_lib.nx nx_mesh_lb.nx

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

main ep_anchor sys_openat_rd sys_close sys_chdir sys_mmap lb_streq lb_w sys_write lb_p lb_w ↻ lb_pn lb_wn sys_mmap ↻ sys_write ↻ sys_mmap ↻ lb_ep lb_probe sys_mmap ↻ nx_http_client_sockaddr_ip sys_socket nx_connect_bounded nx_fcntl sys_connect sys_mmap ↻ sys_poll lb_pollfd sys_poll ↻ sys_close ↻ nx_http_client_build_reque hc_put_caps sys_mmap ↻ nx_codec_caps_headers sys_mmap ↻ nx_codec_caps_accept_docum sys_mmap ↻ nx_codec_caps_accept_image nx_cc_put nx_codec_caps_accept_encod cc_encoding_have

structs

none

consts

30const LB_MAGIC_5080: i64 = 5080
31const LB_MAGIC_3090: i64 = 3090
32const LB_MAGIC_7861: i64 = 7861
33const LB_MAGIC_2048: i64 = 2048
34const LB_MAGIC_2000: i64 = 2000
35const LB_MAGIC_16384: i64 = 16384
36const LB_MAGIC_16383: i64 = 16383
57const LB_N_IMAGE: i64 = 2

functions

21func ml_where_role(role: *u8, label: *u8) -> *u8
called by 1: lb_ep_label calls 3: se_hostsys_mmapse_put
38func 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 }
called by 2: lb_pmain calls 1: sys_write
39func lb_wn(fd: i64, v: i64) -> i64
52func lb_p(s: *u8) -> i64 { return lb_w(1, s) }
called by 2: lb_gatemain calls 1: lb_w
53func lb_pn(v: i64) -> i64 { return lb_wn(1, v) }
called by 2: lb_gatemain calls 1: lb_wn
54func 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
58func lb_ep(idx: i64, oct: *i64) -> i64
called by 1: main
63func lb_ep_label(idx: i64) -> *u8
called by 1: main calls 1: ml_where_role
70func lb_pick(health: *i64, n: i64, counter: i64) -> i64
called by 2: lb_gatemain
89func lb_pollfd(pfd: *u8, fd: i64, events: i64) -> i64
called by 1: lb_probe
95func lb_resp_2xx(buf: *u8, n: i64) -> i64
called by 1: lb_probe
104func lb_probe(a: i64, b: i64, c: i64, d: i64) -> i64
131func lb_counter_read() -> i64
142func lb_counter_write(v: i64) -> i64
called by 1: main calls 3: sys_openat_wrlb_wnsys_close
150func lb_gate() -> i64
called by 1: main calls 4: lb_psys_mmaplb_picklb_pn
193func main(argc: i64, argv: *i64) -> i64