Disable Admin Worker in Shopware 6

In this article, you will learn how to disable the Admin Worker in Shopware 6 and manage the message queue using the CLI Worker instead.

In Shopware 6, the so-called Admin Worker, which performs tasks asynchronously in the background, is enabled by default. These tasks are located in the message queue and are triggered when a user is logged into the Shopware admin.

However, with a large number of users logged into the Shopware Admin, the CPU load can increase to such an extent that the execution of the tasks is disrupted. In addition, no tasks are executed if there is no logged-in user in Shopware Admin. This can, for example, affect tasks that are to be performed at night.

The official recommendation from Shopware is therefore to disable the Admin Worker and use the CLI Worker instead to process the message queue. There are several options available for the setup. One possible approach is to call the message queue via a cronjob. Alternatively, it can be invoked via a process management service such as Supervisor or Systemd.

Disabling the Admin Worker

To disable the Admin Worker, the following configuration must be added to the config/packages/shopware.yaml file:

shopware:
    admin_worker:
        enable_admin_worker: false

After the admin worker has been disabled, the processes scheduled-task:run as well as messenger:consume have to be started. For this purpose we present three different possibilities in the following.

Calling the Message Queue via Cronjob

To run the Consumer and Scheduled Task processes using cronjobs, enter the following lines in your crontab list:

*/3 * * * * /usr/bin/php /var/www/share/demoshop.com/shopware/bin/console scheduled-task:run --time-limit=120
*/3 * * * * /usr/bin/php /var/www/share/demoshop.com/shopware/bin/console messenger:consume --time-limit=120

This will automatically run both processes every three minutes. The runtime of both processes is two minutes each. The runtimes are to ensure that the processes are not started multiple times in parallel. Shopware recommends the setting of a short runtime to avoid memory leaks with long running PHP processes.

Calling the message queue via Supervisor

To manage the processes using Supervisor, you can use the following configuration templates for the Consumer as well as the Scheduled Task. If the process is terminated by the time limit, Supervisor will restart it. Via numprocs you can define how many processes should be started at the same time. Usually one process is sufficient. Only in the case of very large instances or many tasks is it worth increasing the number.

Consumer

[program:messenger-consumer]
command=php /var/www/share/demoshop.com/shopware6/bin/console messenger:consume --time-limit=120
numprocs=1
startsecs=0
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d

Scheduled Task

[program:scheduled-task]
command=php /var/www/share/demoshop.com/shopware6/bin/console scheduled-task:run --time-limit=120
numprocs=1
startsecs=0
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d

Calling the message queue via Systemd

To execute the two processes via Systemd, you can use the Systemd units shown below.

The two units are used to start and manage the consumer and scheduled task of Systemd respectively. The time-limit parameter is used to keep the runtime of the processes low, while the memory-limit parameter ensures that they do not use more than 512 MB of RAM. After the time-limit expires, the process terminates and Systemd restarts accordingly. You may need to replace the path to your Shopware instance that contains bin/console.

Consumer

The file must be placed in /etc/system/system/shopware_consumer.service with the following content:

[Unit]
Description=Shopware Consumer
After=mysql.service

[Service]
Type=simple
User=web-user
Group=web-user
Restart=always
ExecStart=/usr/bin/php /var/www/share/demoshop.com/shopware/bin/console messenger:consume --time-limit=60 --memory-limit=512M

[Install]
WantedBy=multi-user.target

Scheduled Task

The file must be placed in /etc/systemd/system/shopware_scheduled_task.service with the following content:

[Unit]
Description=Shopware Scheduled Task
After=mysql.service

[Service]
Type=simple
User=web-user
Group=web-user
Restart=always
ExecStart=/usr/bin/php /var/www/share/demoshop.com/shopware/bin/console scheduled-task:run --time-limit=60 --memory-limit=512M

[Install]
WantedBy=multi-user.target

Do you need assistance?

favicon
maxcluster GmbH
24 / 7 Customer support
Telephone:
+49 5251 414130
E-Mail:
support@maxcluster.de
logo

Do you need assistance?

maxcluster GmbH
24 / 7 Customer support
Telephone:
+49 5251 414130
E-Mail:
support@maxcluster.de
image
image