Skip to content

Lazy DEALER creation: defer snapshot sockets until first subscribe#12

Merged
bricke merged 1 commit into
mainfrom
lazy-dealer
Apr 30, 2026
Merged

Lazy DEALER creation: defer snapshot sockets until first subscribe#12
bricke merged 1 commit into
mainfrom
lazy-dealer

Conversation

@bricke
Copy link
Copy Markdown
Owner

@bricke bricke commented Apr 30, 2026

Summary

  • DEALER sockets are no longer created at peer discovery time; they are deferred until the first bacaro_subscribe call via the new discovery_ensure_dealer helper
  • Pure publishers that never subscribe create zero DEALER sockets, eliminating unnecessary snapshot handshakes at boot
  • PeerInfo gains a rep_endpoint field so the endpoint string is available when the DEALER is eventually created
  • close_peer handles a null dealer_sock gracefully

Why

On a device with 30+ processes, every peer used to open a DEALER socket to every other peer immediately at discovery — even if neither side ever exchanged a snapshot. This causes a boot storm of N² socket setups and snapshot requests that return empty. The lazy approach means only processes that actually subscribe ever pay the DEALER cost.

Test plan

  • All existing tests pass (ctest)
  • Pure publisher (no bacaro_subscribe) holds zero DEALER sockets after discovery
  • Subscriber creates DEALER on first bacaro_subscribe and receives snapshot correctly
  • Mid-life subscribe (peer already discovered, DEALER not yet created) still works

DEALER sockets are no longer created at peer discovery time. They are
created lazily when bacaro_subscribe is called, or at discovery time
only if subscriptions already exist.

Pure publishers (never subscribe) now create zero DEALER sockets.
At device boot with N processes starting simultaneously, processes
that haven't subscribed yet only pay for zmq_connect on the shared
SUB socket — no DEALER creation, no snapshot requests.
@bricke bricke merged commit 758ea4f into main Apr 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant