From 43dd5a901a69fab5bab4662b33ce38cc9d5c74b9 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Thu, 27 Nov 2025 22:59:38 +0100 Subject: [PATCH] Update CLAUDE.md with correct ZMQ sender architecture --- CLAUDE.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 32fe7aa..b50be71 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -207,10 +207,16 @@ Every 1 second: - Recommended: Slow (60-300s): Disk, Systemd - **Independent tasks**: Each collector spawned as separate tokio task in `Agent::new()` - **Cache updates**: Collectors acquire write lock → update → release immediately -- **ZMQ sender**: Main loop reads cache every `collection_interval_seconds` and broadcasts -- **Notification check**: Runs every `notifications.check_interval_seconds` -- **Lock strategy**: Short-lived write locks prevent blocking, read locks for transmission -- **Stale data**: Acceptable for slow-changing metrics (SMART data, disk usage) +- **ZMQ sender**: Dedicated OS thread with own publisher socket, uses `try_read()` to avoid blocking +- **Non-blocking reads**: `try_read()` never blocks - sends previous data if cache is locked +- **Notification check**: Runs every `notifications.check_interval_seconds` in main loop +- **Lock strategy**: Short-lived write locks, non-blocking reads for transmission +- **Stale data**: Acceptable for slow-changing metrics AND when collector holds write lock + +**Threading Model:** +- Main thread: tokio runtime for command handling and notifications +- Collector threads: 7 independent tokio tasks updating shared cache +- ZMQ sender thread: Dedicated OS thread (ZMQ sockets not thread-safe) with lock-free reads **Configuration (NixOS):** All intervals and timeouts configurable in `services/cm-dashboard.nix`: @@ -232,9 +238,10 @@ Command Timeouts (prevent resource leaks from hung commands): - `collectors.network.command_timeout_seconds` (default: 10s) - ip route, ip addr **Code Locations:** -- agent/src/agent.rs:59-133 - Collector task spawning -- agent/src/agent.rs:151-179 - Independent collector task runner -- agent/src/agent.rs:199-207 - ZMQ sender in main loop +- agent/src/agent.rs:69-144 - Collector task spawning with configured intervals +- agent/src/agent.rs:162-190 - Independent collector task runner +- agent/src/agent.rs:202-249 - ZMQ sender in dedicated OS thread with try_read() +- agent/src/agent.rs:251-264 - Main loop (commands and notifications only) ### Maintenance Mode