Xentral 22.1 comes with a queue component to normalize workloads. The queued jobs are executed by a long running worker process.
Command to start the worker manually:
php /xentral_root_dir/artisan queue:work
Command to stop the worker manually:
php /xentral_root_dir/artisan queue:restart
The command is called “restart” but it will only stop the process.
For more information and command options visit the Laravel documentation.
You should use a process Control System or process monitor to restart workers when they shut down or crash.
Any system that has the ability to automatically start a process via console command when it is not running will do.
You may define and run a service as the process control system using
systemd on Linux.
Define the service
create a file like
put the configuration in that file
[Unit] Description=Runs and keeps alive the artisan queue:work process [Service] Restart=always RestartSec=1 StartLimitIntervalSec=0 WorkingDirectory=/var/www/xentral/ User=<worker_user> ExecStart=php /var/www/xentral/artisan queue:work --max-time=3600 [Install] WantedBy=default.target
/var/www/xentralwith the root directory of your xentral installation.
Run the first worker
systemctl start queue_worker@1 # enable service on every boot systemctl enable queue_worker@1
You may run additional workers by repeating the command with subsequent numbers
systemctl start queue_worker@2 systemctl enable queue_worker@2 systemctl start queue_worker@3 systemctl enable queue_worker@3 . . .
You may use Supervisor as process control system to configure the queue process.
Visit the Supervisor Documentation for more information on how to use Supervisor.
[program:queue-worker] process_name=%(program_name)s_%(process_num)02d command=php /var/www/xentral/artisan queue:work --max-time=3600 autostart=true autorestart=true stopasgroup=true killasgroup=true numprocs=2 redirect_stderr=true stdout_logfile=/var/www/xentral/storage/logs/queue-worker.log stopwaitsecs=3600
Visit the Laravel Documentation for more information on the configuration.
When using a process control system, it is important to regularly stop and restart the worker process. One way to achieve this is by using the following options of the
artisan queue:work command:
A combination of both options is possible.
Tinker around with these values as you seem fit according to your experience. E.g. if a worker often exceeds its memory limit, you should consider restarting the workers more often.
You may run multiple worker processes at the same time. The amount of worker is controlled differently by different process control systems. For Systemd you need to start several services, Supervisor uses the
Take the following into consideration for the decision on how many workers should run.
How many unprocessed jobs are there?
Queued jobs are stored in the
queue_jobstable. When the jobs become too many you may add more workers.
More workers working jobs leads to higher CPU and RAM usage and might affect the response-time of the application.