atproto relay implementation in zig zlay.waow.tech
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

add broadcast queue push-lock spin counter

separates push-lock contention from queue-full contention so operator
can distinguish: producers fighting for the CAS lock vs producers
blocked on a full ring buffer.

new metric: relay_broadcast_queue_push_lock_spins_total
clarified: relay_broadcast_queue_full_total HELP text (ring capacity)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+12 -1
+12 -1
src/broadcaster.zig
··· 59 59 pool_queued_bytes: std.atomic.Value(u64) = .{ .raw = 0 }, 60 60 // persist/broadcast pipeline contention 61 61 persist_order_spins: std.atomic.Value(u64) = .{ .raw = 0 }, 62 + broadcast_queue_push_lock_spins: std.atomic.Value(u64) = .{ .raw = 0 }, 62 63 broadcast_queue_full: std.atomic.Value(u64) = .{ .raw = 0 }, 63 64 broadcast_queue_depth_hwm: std.atomic.Value(u32) = .{ .raw = 0 }, 64 65 broadcast_no_consumers: std.atomic.Value(u64) = .{ .raw = 0 }, ··· 275 276 var full_spins: u32 = 0; 276 277 while (true) { 277 278 // acquire spinlock 279 + var lock_spins: u32 = 0; 278 280 while (self.push_lock.cmpxchgWeak(0, 1, .acquire, .monotonic) != null) { 281 + lock_spins += 1; 279 282 std.atomic.spinLoopHint(); 283 + } 284 + if (lock_spins > 0) { 285 + _ = stats.broadcast_queue_push_lock_spins.fetchAdd(lock_spins, .monotonic); 280 286 } 281 287 282 288 const tail = self.tail.load(.monotonic); ··· 970 976 \\# HELP relay_persist_order_spins_total spin iterations waiting for persist ordering lock 971 977 \\relay_persist_order_spins_total {d} 972 978 \\ 979 + \\# TYPE relay_broadcast_queue_push_lock_spins_total counter 980 + \\# HELP relay_broadcast_queue_push_lock_spins_total spin iterations waiting for broadcast queue push lock 981 + \\relay_broadcast_queue_push_lock_spins_total {d} 982 + \\ 973 983 \\# TYPE relay_broadcast_queue_full_total counter 974 - \\# HELP relay_broadcast_queue_full_total spin iterations on full broadcast queue 984 + \\# HELP relay_broadcast_queue_full_total spin iterations on full broadcast queue (ring capacity) 975 985 \\relay_broadcast_queue_full_total {d} 976 986 \\ 977 987 \\# TYPE relay_broadcast_queue_depth_hwm gauge ··· 984 994 \\ 985 995 , .{ 986 996 stats.persist_order_spins.load(.acquire), 997 + stats.broadcast_queue_push_lock_spins.load(.acquire), 987 998 stats.broadcast_queue_full.load(.acquire), 988 999 stats.broadcast_queue_depth_hwm.load(.acquire), 989 1000 stats.broadcast_no_consumers.load(.acquire),