Skip to content

Magento 2 spawns many consumers per queue over time

I’m using many queues and configure Magento to use separate consumers for every queue. It works well. But every few days it probably misses all consumer locks and spawns new processes for all queues. After a couple of weeks I see the following process list:

Load average: 1.60 1.51 1.23 2/275 3469
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
  443    14 php      S     338m   2%   2   0% php-fpm: pool www
  664    14 php      S     338m   2%   1   0% php-fpm: pool www
 3089    14 php      S     338m   2%   1   0% php-fpm: pool www
   14     1 root     S     335m   2%   3   0% php-fpm: master process (/usr/local/etc/php-fpm.conf)
10474     1 php      S     205m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted1 --single-thread --max-messages=10000
23912     1 php      S     205m   1%   1   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted1 --single-thread --max-messages=10000
31940     1 php      S     205m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted1 --single-thread --max-messages=10000
28414     1 php      S     205m   1%   0   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted1 --single-thread --max-messages=10000
 2591     1 php      S     205m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted2 --single-thread --max-messages=10000
10044     1 php      S     205m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted2 --single-thread --max-messages=10000
23455     1 php      S     205m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted2 --single-thread --max-messages=10000
28422     1 php      S     205m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted2 --single-thread --max-messages=10000
31948     1 php      S     203m   1%   0   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted2 --single-thread --max-messages=10000
12464     1 php      S     201m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted3 --single-threa
25883     1 php      S     201m   1%   1   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted3 --single-threa
28430     1 php      S     201m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted3 --single-threa
31956     1 php      S     201m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted3 --single-threa
 2577     1 php      S     199m   1%   1   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start async.m2.redacted4 --single-thread --max-messages=10
15911     1 php      S     199m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start async.m2.redacted4 --single-thread --max-messages=10
29285     1 php      S     199m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start async.m2.redacted4 --single-thread --max-messages=10
10077     1 php      S     199m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start async.m2.redacted4 --single-thread --max-messages=10
24946     1 php      S     199m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start async.m2.redacted4 --single-thread --max-messages=10
28406     1 php      S     199m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start async.m2.redacted4 --single-thread --max-messages=10
31932     1 php      S     199m   1%   0   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start async.m2.redacted4 --single-thread --max-messages=10
14457     1 php      S     199m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted5 --single-thread --max-messages=10000
27649     1 php      S     199m   1%   1   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted5 --single-thread --max-messages=10000
 2595     1 php      S     199m   1%   3   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted5 --single-thread --max-messages=10000
29748     1 php      S     199m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted5 --single-thread --max-messages=10000
10564     1 php      S     199m   1%   1   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted5 --single-thread --max-messages=10000
28428     1 php      S     199m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted5 --single-thread --max-messages=10000
31954     1 php      S     199m   1%   2   0% /usr/local/bin/php /magento/bin/magento queue:consumers:start sync.m2.redacted5 --single-thread --max-messages=10000

(command lines truncated because some queue names are long and I’ve redacted real queue names)

You may see that every queue has many consumers. When the server is just started up, I see only one consumer per queue.

How to fix this?