Repository navigation
fix(messaging): send every multi request instead of failing past the pool size - #14238
Conversation
…pool size requestMulti spawned one coroutine per request against a 25-slot pool with a zero acquisition timeout, so every request after the 25th failed instantly. Large FCM pushes delivered 25 per 5000-token batch and the failed coroutines held enough memory to OOMKill worker-messaging.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
The change replaces the one-coroutine-per-request fan-out in
Reviewed commit: fc516b6 |
🟢 Tier S · Ready to merge
Changes requestMulti() to use at most 25 worker coroutines that drain a shared request cursor, rather than creating one coroutine per request. Results are sorted by request index after all workers finish. Adds a separate-process regression test covering 60 requests, successful results, index ordering, and bounded concurrency.
📂 Walkthrough · 2
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
There was a problem hiding this comment.
Refactors requestMulti to a bounded worker-pool coroutine pattern so more than MAX_CONCURRENT_REQUESTS requests all get sent, and adds a regression test.
Key findings
- 🟡 Add a lower bound proving test concurrency — RequestMultiTest.php:32
| $this->assertSame(\array_fill(0, 60, 200), \array_column($results, 'statusCode')); | ||
| $this->assertSame(\array_fill(0, 60, ''), \array_column($results, 'error')); | ||
| $this->assertSame(60, $client->sent); | ||
| $this->assertLessThanOrEqual(25, $client->peak); |
There was a problem hiding this comment.
🟡 suggestion · medium
Add a lower bound proving test concurrency
The only concurrency assertion is assertLessThanOrEqual(25, $client->peak) (packages/messaging/tests/Adapter/RequestMultiTest.php:32), which an implementation that sends all 60 requests serially (peak == 1) also satisfies. The test verifies counts and indexes but nothing distinguishes concurrent from sequential execution, so a regression that serializes requestMulti() would pass. A lower bound on peak is what actually proves fan-out.
📋 Prompt for AI Agents
In packages/messaging/tests/Adapter/RequestMultiTest.php at line 32, change assertLessThanOrEqual(25, $client->peak) to assertSame(25, $client->peak) — the 25 worker coroutines each increment SlowClient::$active before the first Coroutine::sleep(0.01) wakes, so the peak is deterministic. Without a lower bound the test passes even if requestMulti() regresses to fully serial sending.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What does this PR do?
requestMulti()spawned one coroutine per request (up to 5000 per FCM batch) against a pool capped atMAX_CONCURRENT_REQUESTS = 25withtimeout: 0.0. Every request after the 25th failed instantly with a pool-exhausted error, so large push messages delivered exactly 25 per batch and marked the rest as failed.It now runs at most 25 worker coroutines that drain a shared cursor. Each worker holds one pooled client at a time, so acquisition never waits and memory no longer scales with the recipient count.
Production impact (cloud fra1): about 100 push jobs a day since at least 2026-09-16 report
delivered_totalof exactly 25 or 50, with thousands of errors. On 2026-10-07,worker-messagingwas OOMKilled at 512Mi after a few pushes to about 6.5k tokens.Benchmark
Run on the production image (
appwrite/cloud:1.50.146, linux/amd64, 1 CPU) in a throwaway staging pod. Mock FCM endpoint on localhost with 80 ms latency,SWOOLE_HOOK_ALL, batching the same as the worker (5000 perrequestMulticall), and a fresh process per case.beforeis theAdapter.phpcurrently in that image.Every failure before the fix was
Pool 'messaging' could not provide a connection within 0s. The old version is only faster because it never sends 99% of the requests. The new wall time matches 25 concurrent requests at 80 ms (6500 / 25 × 0.08 s ≈ 20.8 s).Four 6,500-recipient jobs in one process: RSS settles at about 116 MB before the fix and about 100 MB after, with no growth from job to job. The cost per worker process is about +100 MB before the fix and about +40 MB after, over a ~60 MB baseline. Before the fix, each of the 3 processes on a pod pays it, which matches the steps seen in production before the OOM (167 → 267 → 365 MB).
Test Plan
bin/monorepo check messagingandbin/monorepo test messaging --linkedpass locally.Related PRs and Issues
timeout: 0.0assuming one slot per request.Checklist
Related: #14239