Skip to content

docs(queue): Broker\Nats control connection is inertia, not intent - #149

Open
levivannoort wants to merge 1 commit into
mainfrom
docs/nats-getqueuesize-rationale
Open

docs(queue): Broker\Nats control connection is inertia, not intent#149
levivannoort wants to merge 1 commit into
mainfrom
docs/nats-getqueuesize-rationale

Conversation

@levivannoort

Copy link
Copy Markdown
Contributor

Comment-only. Records why Broker\Nats::getQueueSize() reads over a client connection and needs a dedicated control connection (added in #147), so the next reader doesn't mistake it for a deliberate "metrics get their own NATS connection" design.

Why it exists — inertia, not intent:

  • getQueueSize() is part of the Consumer contract, and Queue\Server emits a generic queue-depth gauge through it.
  • That gauge was built for Redis, where getQueueSize() is a cheap LLEN on a pooled connection — free, unnoticed.
  • On NATS the same call is a JetStream consumer.info() round-trip over the single-owner socket. Making Broker\Nats a drop-in Consumer (MIG-4) kept that call, and the control connection is only there to keep it safe under Swoole (the consume loop and the telemetry coroutine can't share one socket).
  • The same num_pending is already published on the NATS monitoring endpoint (the promExporter scrape). So the client-side read and the extra connection are a migration-parity stopgap.

Retire path: once autoscaling/telemetry read depth from the monitoring endpoint (KEDA / MIG-9), drop the client-side depth gauge for NATS and delete the control connection — then it's exactly one connection per consume coroutine and zero for metrics.

No behaviour change; php -l and Pint clean.

…ntent

Document why getQueueSize() reads over a client connection and needs a dedicated
control connection: it's the inherited Consumer-contract depth gauge (a free LLEN
on Redis, a consumer.info() round-trip on NATS), not a deliberate metrics-connection
design. The same num_pending is already on the NATS monitoring endpoint, so this and
the extra connection are a migration-parity stopgap to retire once depth comes from
that endpoint (KEDA/observability work).
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