Symfony 8.2 added --concurrency to messenger:consume. One process fetches from the transport and hands each message to a pool of child processes. The pull request's argument for it is one connection to the broker instead of N. The two earlier articles of this series covered what the pool does on its first message of every class and what it moves out of the handler process. This one answers the question that comes after reading them: should your Supervisor config say numprocs=4, or --concurrency=4, or both?
I ran five topologies through seven scenarios on Symfony 8.2.0 and measured what a tech lead has to trade: messages per second on short handlers, resident memory, connections to Redis, how long a cold restart takes to reach full speed, what happens to a latency-sensitive message behind a burst, how supervisorctl stop behaves with children in flight, and what a kill -9 of a process, a child or a parent does to the messages they were handling.
The single parent saves connections. It costs memory, some throughput at sixteen slots, restart time, and it adds one failure mode that N processes do not have. The decision table at the end says when that trade is still worth it.
Prerequisites
- PHP 8.4.22 with
ext-redis,ext-pcntlandext-posix symfony/messenger8.2.0,symfony/redis-messenger8.2.0,symfony/framework-bundle8.2.0amphp/parallel2.4.0, which--concurrencyrequires- Redis 7.4.9 as the transport, streams with a consumer group
- Supervisor 4.3.0
- The benchmark app: three message classes, a recorder that writes every boot and every handled message to a Redis list, and a script that writes a Supervisor config per topology, runs one scenario and stores the metrics. The repository is linked at the end.
The numbers come from a 16-core Apple M3 Max, so they describe the shape of each trade-off, not your server. RSS is what ps reports per process on macOS. Every number is the median of three runs. Throughput was first measured on 2000 messages, which was too short against the machine's background load (one topology ranged from 149 to 475 messages per second over eight runs), so the table below comes from 8000 messages.
1. The topologies and what each one is made of
A topology is P Supervisor processes with --concurrency=C, written PxC. Five of them cover the question:
topology PHP processes handler slots what it tests 4x1 4 4 the 8.1 way: four workers, no pool 1x4 1 parent + 4 children 4 the 8.2 pitch: one worker, four children 4x4 4 parents + 16 children 16 both 16x1 16 16 sixteen workers, no pool 1x16 1 parent + 16 children 16 one worker, sixteen children 4x1 and 1x4 have the same four slots and compare directly. 4x4 has sixteen, so 16x1 and 1x16 sit next to it as the controls. Without them, a 4x4 result only says that sixteen slots beat four.
The Supervisor program is the one from the Messenger docs, with the concurrency option added where the topology has one:
[program:worker] command=php /app/bin/console messenger:consume async --time-limit=3600 --concurrency=4 numprocs=1 process_name=%(program_name)s_%(process_num)02d autostart=true autorestart=true startsecs=0 startretries=10 stopwaitsecs=30 environment=APP_ENV="prod",MESSENGER_CONSUMER_NAME="%(program_name)s_%(process_num)02d" MESSENGER_CONSUMER_NAME feeds the consumer option of the Redis transport, so every Supervisor process reads the stream under its own name. The children never touch the transport, which is the point of the feature and what sections 2 and 7 come back to.
Three message classes make the workloads. FastMessage holds a slot for 20 or 50 milliseconds, SlowMessage for 10 to 20 seconds, and Ping does nothing but record how long it waited in the queue, which is what a user of a latency-sensitive message feels. The handlers hold their slot with a loop of short sleeps until a deadline rather than one usleep(), because a single usleep() returns early when SIGTERM arrives and makes a stopped handler look like a finished one. That cost me a wrong first result on the stop scenario.
2. Throughput: the parent costs 15% at sixteen slots
Eight thousand FastMessage of 20 ms, workers warm, every class already probed. The ideal for four slots is 200 messages per second, for sixteen it is 800.
topology msg/s min–max PHP processes RSS MB transport connections busiest parent CPU 4x1 150 143–151 4 136 4 2% 1x4 146 143–150 5 191 1 12% 4x4 601 593–618 20 768 4 11% 16x1 622 617–660 16 545 16 2% 1x16 526 435–560 17 595 1 23% At four slots the shape does not matter: 150 against 146. At sixteen it starts to. One parent with sixteen children does 85% of what sixteen processes do, and four parents with four children each close the gap. The parent does the fetching, the unserializing, the acknowledging and the channel round trip for every message, and the PR text says where that leads: "the fetch+unserialize steps are not parallelized when --concurrency is used. This is unfavorable for very short tasks". The parent of 1x16 sits at a quarter of a core, so the limit is not CPU but the serial loop: sixteen children hand back results faster than one loop can fetch, dispatch and acknowledge in turn. Shorter handlers should widen the gap, as the PR text says; I did not measure below 20 ms. The PR's own table, 20 ms handlers on 24 cores, shows 7.5x for eight children.
Memory: a child is a booted kernel
The PR pitch says nothing about memory, but the assumption that one process with children must be lighter than N processes is common. It is wrong. Each amphp child requires bin/console, boots the kernel and builds the container, so it weighs what a worker weighs:
process RSS MB Supervisor worker, --concurrency not set 34 amphp child 34 parent of 4 children 55 parent of 16 children 51 1x4 is five kernels against four, 191 MB against 136. 1x16 is seventeen against sixteen, 595 MB against 545. 4x4 is twenty, 768 MB. On this app a kernel is small; multiply by your own worker's RSS, the ratio stays.
Connections: the one thing the parent saves
16x1 holds sixteen connections to Redis, 1x16 holds one. For Redis that number does not matter. For a managed broker with a connection cap, or a Doctrine transport sharing a pool with the web tier, it is the argument for the parent, and it is the only one in this table.
3. Latency: same slots, same waits
Two SlowMessage of 15 s and two hundred FastMessage of 50 ms are queued, then a Ping every half second for 20 seconds. The pings arrive behind the backlog, so the first ones wait for it to drain, and the median tells how a ping fares once the slow handlers hold their slots.
topology ping wait p50 s p95 max fast wait p50 s 4x1 0.26 4.64 5.65 3.21 1x4 0.64 4.82 5.83 3.31 4x4 0.26 0.62 1.04 1.18 16x1 0.33 0.70 0.71 0.66 1x16 0.36 0.86 0.98 0.87 With every class probed and nothing to spawn, the topology does not matter: four slots give the same waits whether they live in four processes or one, and so do sixteen. The slow handlers occupy two slots either way. What moves the numbers is the slot count. This is the steady state, and it is what the PR's benchmark table measures, on warm workers. The next three scenarios are the ones it skips.
4. A burst meets the probe, and the fetch size hands it to one parent
Article one of this series measured the probe: the first message of each class on a parent runs alone, and the messages of that class fetched behind it are held until the probe answers. Here the slow class is left unprobed during warm-up, as it is after every restart, and four SlowMessage of 10 s arrive at once, with pings behind them.
topology slow wait p50 s ping wait max s drain s 4x1 0.58 10.09 16.0 1x4 10.33 9.83 21.0 4x4 10.35 0.90 20.9 16x1 0.24 0.89 15.8 1x16 10.30 0.94 20.9 Every topology with a parent takes five seconds longer, because three of the four slow messages wait 10 seconds for the probe of the first. Four processes take one each and finish together.
4x4 is the surprise. Four parents, four slow messages, and still three of them held. The cause is --fetch-size: it defaults to the value of --concurrency, so a parent with four children asks Redis for four messages per call, and the first parent to ask gets the whole burst. The other three parents sit idle with sixteen free slots between them while one parent holds three messages behind its probe. 16x1 fetches one message per process and spreads the burst by construction.
The pings tell the other half. On 4x1 and 1x4 they wait up to 10 seconds, because all four slots are taken, whether by four running handlers or by one probe plus three held messages, which count against the limit. On the sixteen-slot topologies the pings pass, because the burst does not fill the pool. Size the burst to the slot count and it does:
topology slow wait p50 s ping wait max s drain s 4x1 0.13 9.78 15.9 1x4 10.16 9.72 20.7 4x4 10.31 9.84 20.9 16x1 0.62 10.03 15.9 1x16 10.56 10.04 20.9 One slow message per slot pauses every topology for 10 seconds, pings included. The parent ones pay the probe on top and need 21 seconds to clear what the process ones clear in 16.
--fetch-size=1 on a topology with several parents softens this. On 4x4 the same burst then spread over three parents: three slow messages started at once and one was held, the drain stayed at 21 seconds because of that one, but the median slow wait fell from 10.3 seconds to 0.2. A parent with free children fetches again as soon as it has dispatched, so it can still take two messages before a sibling polls. The option costs a round trip per message, which section 2 showed the parent can afford less than the processes can.
5. Cold start: children boot one at a time
Four hundred FastMessage and twenty pings are queued before Supervisor starts. The table shows when the Nth message started handling, counted from the moment supervisord was launched.
topology boots 1st message s 10th 50th 100th drain s 4x1 4 2.02 2.09 2.41 2.76 4.83 1x4 1 + 4 2.37 3.71 4.03 4.36 7.76 4x4 4 + 16 3.13 4.20 4.54 4.62 5.37 16x1 16 1.93 2.02 2.08 2.15 2.66 1x16 1 + 16 2.68 7.13 10.54 10.78 11.87 Sixteen processes boot in parallel and are all handling within 0.3 seconds of each other. One parent with sixteen children handles its tenth message at 7 seconds and its fiftieth at 10.5. The recorder shows why: the children boot 0.45 to 0.5 seconds apart, in sequence.
0.00 messenger:consume async --concurrency=16 (parent) 0.73 child 1 1.39 child 2 1.91 child 3 ... 7.71 child 15 8.30 child 16 The kernel boot itself takes 20 to 40 milliseconds. The half second is the context start: ParallelExecutionStrategy::getChannel() creates a child when a message arrives and no channel is free, and createChannel() starts the amphp context and submits the task before the parent's loop continues. Children are created on demand, one per message that needs a slot, and the parent fetches nothing while one starts. So a pool of sixteen reaches full width eight seconds after every restart, and with --time-limit=3600 that is every hour, on top of one probe per class per parent.
4x4 looks fine at the 50th message because four parents spawn four chains in parallel, but its first message comes last of all, at 3.1 seconds: four parents fetching four messages each and all spawning at once.
6. Stop: the parent waits for its children
Every slot is inside a 20-second handler, with about 15 seconds left, when supervisorctl stop all runs. Supervisor sends SIGTERM and waits up to stopwaitsecs=30.
topology stop took s handlers finished left pending processes left 4x1 14.8 4 of 4 0 0 1x4 15.3 4 of 4 0 0 4x4 16.2 16 of 16 0 0 16x1 16.1 16 of 16 0 0 1x16 15.3 16 of 16 0 0 No difference. The parent receives the signal, stops fetching, waits for every child to return its result, acknowledges, shuts the pool down and exits. No child was orphaned, no message was left pending. stopasgroup=true and killasgroup=true, which send the signal to the children as well, changed nothing: amphp's process-runner.php registers a no-op handler for SIGTERM, SIGINT, SIGHUP and SIGUSR1 in every child, so a child finishes its handler and waits for its parent whatever Supervisor sends it. What matters is stopwaitsecs: it must cover your longest handler, on both topologies, or Supervisor escalates to SIGKILL and section 7 applies.
7. Kill: who dies decides whether the message runs twice
Same load, and three seconds in, one process gets SIGKILL. Three cases, because a topology with a parent has three kinds of process to lose.
A Supervisor worker without a pool, 4x1 and 16x1. Supervisor restarts it in about two seconds. The restarted worker has the same consumer name, and the Redis transport reads a consumer's own pending entries before new ones, so the message that died with the process is handled by its replacement 5.6 seconds after dispatch instead of 0.9. Every message handled once, nothing pending at the end.
A child, 1x4, 4x4 and 1x16. The parent logs A parallel worker failed: The context stopped responding during receive, the envelope fails with The parallel worker stopped before returning a result, WorkerMessageFailedEvent fires with willRetry() true, the retry strategy re-dispatches it with the default one-second delay, and the parent creates a new child. The message is handled once, 5.2 seconds after dispatch. The parent's other children keep running.
A parent, 1x4, 4x4 and 1x16. This is the case the pool adds.
topology dispatched handled boots after the kill last slow wait s 1x4 24 28 1 + 4 26.1 4x4 36 40 1 + 4 26.0 1x16 36 52 1 + 16 29.9 The children do not die with the parent. They keep their 20-second handlers running to the end, write their results, fail to send them to a parent that is gone, and exit. Supervisor restarts the parent, which reads its own pending entries, which are exactly the messages the orphans are finishing, and runs every one of them again on fresh children. One parent with sixteen children handled 52 messages for 36 dispatched: every in-flight message twice, 25 seconds apart.
Messenger is at-least-once, and a crashed 4x1 worker also loses its handler mid-way and repeats it. The difference is the blast radius. One dead process repeats one message. One dead parent repeats --concurrency messages, and the work it repeats was not interrupted, it completed. An idempotent handler shrugs this off. A handler that sends an email, charges a card or appends to a ledger needs its idempotency key before you add --concurrency, because the parent is one process that can run out of memory, hit a fatal error in a listener, or be killed by Supervisor at stopwaitsecs, and each of those now means N completed messages run again.
--memory-limit does not cause this case: a child that crosses it stops after its message and is replaced without a re-probe, and a parent that crosses it stops the way section 6 describes. The cases that kill the parent are the ones you do not plan.
8. The decisions
Short handlers and many slots, N processes. At 20 ms per message the pool of sixteen gave up 15% to sixteen processes, with the same memory; at four slots it gave up nothing. --concurrency is for handlers long enough that the parent's fetch loop is noise next to them, and the shorter the handler, the fewer children one parent can keep busy.
The parent earns its place by connections, not by memory. A child is a booted kernel of the same size as a worker, plus a parent. Choose 1xN when the broker's connection count is the constraint: a managed queue with a cap, a Doctrine transport on the web tier's database. Choose Nx1 when memory or restart time is.
Several parents want --fetch-size=1. With the default, one parent fetches a whole burst and holds it behind its probe while its siblings idle. On 4x4 the option spread a four-message burst over three parents instead of one.
Budget the restart. A pool of C children takes about C times half a second to reach full width, plus one probe per class, after every restart. With --time-limit=3600 that is every hour. Set the time limit from the slowest handler and keep it long; use --memory-limit, which restarts a child and not the parent, to contain leaks.
Make the handlers idempotent before the parent exists. A dead parent means every in-flight message completes in an orphan and runs again in the replacement. With sixteen children that is sixteen repeated side effects per crash.
stopwaitsecs covers the longest handler on every topology. The parent waits for its children on SIGTERM. Below the limit Supervisor sends SIGKILL and the previous rule applies.
Keep latency-sensitive messages on their own processes. The topology did not change the ping waits; the slot count and a burst of one slow class did. A second Supervisor program with numprocs=2 on the fast transport is cheaper than any concurrency setting.
If you run short messages on Redis, keep numprocs. If you run long messages against a broker that counts connections, run --concurrency with a long time limit and idempotent handlers, add --fetch-size=1 when there is more than one parent, and measure a kill of the parent before you trust it.
Source Code: You can find the full implementation and follow the project's progress on GitHub: https://github.com/mattleads/messenger-topology-bench
Let's Connect!
If you found this helpful or have questions about the implementation, I'd love to hear from you. Let's stay in touch and keep the conversation going across these platforms:
- LinkedIn: https://www.linkedin.com/in/matthew-mochalkin/
- X (Twitter): https://x.com/MattLeads
- Telegram: https://t.me/MattLeads
- GitHub: https://github.com/mattleads

