Repository navigation
feat(queue): record consumed message size and log large messages - #14480
Conversation
A 138MB audits job OOMKilled every worker that reserved it for 14h with nothing pointing at it. Brokers now stamp the encoded size on each Message (no re-encode), the Server records it as messaging.process.message.size, and a message over 1MB is logged before decode so the line survives an OOM during decode.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
This PR instruments queue message sizes: brokers now measure each incoming payload and stamp it on the message, the server records the sizes into an OpenTelemetry histogram, and oversized messages trigger a log warning.
Reviewed commit: d03df43 |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
There was a problem hiding this comment.
Adds message-size telemetry (a nullable size on the queue Message, a warnIfLarge helper, and an OTel size histogram in the queue server) across the NATS and Redis brokers.
Key findings
- 🟡 Size histogram recorded without queue attribution — Server.php:368
| $size = $message->getSize(); | ||
| if ($size !== null) { | ||
| $this->messageSize->record($size); | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Size histogram recorded without queue attribution
messageSize is recorded with no attributes at packages/queue/src/Server.php:370, so all queues on a process collapse into one aggregate size series. The sibling depth gauges in the same setTelemetry() path attach messaging.destination.name and messaging.destination.namespace (packages/queue/src/Server.php:290-293), making the histogram inconsistent with them and unusable for the per-queue capacity analysis its name implies. Impact: operators cannot tell which queue produces large messages.
📋 Prompt for AI Agents
In packages/queue/src/Server.php around lines 368-371, change $this->messageSize->record($size) to pass the attributes ['messaging.destination.name' => $message->getQueue(), 'messaging.destination.namespace' => $this->adapter->namespace] — the same attribute set the depth gauges use in createDepthGauge (~line 290) — so the size histogram can be sliced per queue like the other messaging instruments.
🟢 Tier S · Ready to mergeThe Redis and NATS consumers measure encoded message bytes, attach the size to each decoded message, and log messages larger than 1 MiB before decoding. The queue server records message sizes in a histogram alongside its existing processing telemetry. Latest changes: The Redis claim path now measures only string reservations and reuses that size for logging and message metadata.
📂 Walkthrough · 4
Reviewed the commits since |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Script replies are mixed; the package's max-level phpstan rejects strlen on them.
What does this PR do?
On 2026-10-13 a single ~138MB
v1-auditsjob OOMKilled every worker that reserved it for 14h, and nothing pointed at it: worker memory looked flat between scrapes and no line was logged. This adds the missing signal at the consumer, where the raw bytes are already in hand.Message::getSize()/setSize(); brokers stampstrlen($raw)when they decodeMessage.php,Broker/Redis.php,Broker/Nats.phpmessaging.process.message.sizehistogram (bytes, 1KB–256MB buckets), next to the existing wait and process histogramsServer.phperror_logfor any message over 1MB, written before decode so it survives an OOM during decodeMessage::warnIfLarge()No re-encode on publish or consume, no limit, nothing rejected. Every consumer built on this Server gets it, cloud included.
Lean payloads themselves: #14477.
Test Plan
composer lint, phpstan pass.ConsumerResilienceTestsegfaults on the host Swoole build on base too; CI runs it in docker.histogram_quantile(0.99, sum by (le, service_name) (rate(messaging_process_message_size_bytes_bucket[5m])))per worker, and Loki|= "Large queue message".Related PRs and Issues
Checklist
Related: #14478