Shopware 6 Admin Worker enabled
By default Shopware 6 runs scheduled tasks and queue tasks whenever a user is logged into the backend. This feature is called "Admin Workers" in Shopware 6.
While convenient to use, because it just works out of the box, it should not be used in a production environment.
Additionally the admin workers can hurt your overall shop performance by taking webserver resources and free processes away from valuable customers.
Instead these background tasks should be run by using the built in message queue of Shopware 6.
Tideways warns about the admin worker when it detects that the API controllers for the message consumption and running of scheduled tasks are being called:
-
Shopware\Core\Framework\MessageQueue\ScheduledTask\Api\ScheduledTaskController::runScheduledTasks
-
Shopware\Core\Framework\MessageQueue\Api\ConsumeMessagesController::consumeMessages
Once the admin worker is disabled the observation will leave the warning state after a few hours of these controllers not being called anymore.
Disable the Admin Worker in Configuration
First you need to disable the admin worker by creating or changing the
config/packages/shopware.yaml
file in your Shopware 6 shop to contain:
shopware:
admin_worker:
enable_admin_worker: false
A change to the configuration requires to clear the cache:
php bin/console cache:clear
Setup Systemd Service to process Message Queue
The message queue is a PHP script which is permanently running and processing tasks as they become available.
An angel process should supervise that this messenger script is always running, and promptly restarted should it crash. On modern Linux distributions this can be achieved by using systemd that is already installed and is already responsible for many other services.
Create a new file /etc/systemd/system/shopware-consumer.service
:
[Unit]
Description=Shopware Message Queue Consumer
After=mysql.service
[Service]
User=www-data # Change this user to your webservers user name
Restart=always
RestartSec=2
# Modify this next line to the path of your console script
ExecStart=php /var/www/shopware/bin/console messenger:consume --time-limit=600 --memory-limit=128M
Reload systemd and start the service:
sudo systemctl daemon-reload
sudo systemctl enable shopware-consumer
sudo systemctl start shopware-consumer
Setup Systemd Service to run Scheduled Tasks
Shopware also runs scheduled tasks (cronjobs) through a second message queue worker that you have to setup as well.
Create a new file /etc/systemd/system/shopware-scheduled-tasks.service
:
[Unit]
Description=Shopware Scheduled Tasks Worker
After=mysql.service
[Service]
User=www-data # Change this user to your webservers user name
Restart=always
RestartSec=2
# Modify this next line to the path of your console script
ExecStart=php /var/www/shopware/bin/console scheduled-task:run --time-limit=600 --memory-limit=128M
Reload systemd and start the service:
sudo systemctl daemon-reload
sudo systemctl enable shopware-scheduled-tasks
sudo systemctl start shopware-scheduled-tasks