Search code examples
laravelqueuejobssupervisord

Supervisord configuration for Laravel


I am using Supervisord to help keep my Laravel-based App queue running. And I am wondering if the below configuration is correct.

In Laravel docs, for example, numprocs is set 8, which means that Supervisord will run queue:work 8 times, is and why this is a good thing?

Also, should I be using --daemon in the queue:work command?

[program:app-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /home/app/public_html/app/artisan queue:work --daemon --sleep=3 --tries=3
autostart=true
autorestart=true
user=root
startsecs=0
stopwaitsecs=60
redirect_stderr=true
stdout_logfile=/home/app/public_html/app/storage/logs/queue-out.log

Solution

  • numprocs will spawn 8 processes that will then poll the queue every 3 seconds. When daemon is set, these processes will not restart unless told to which has both advantages in terms of server load and disadvantages in the form of some potential edge cases when updating your code base.

    Having 8 processes means that you have potentially 8 times the throughput when running jobs.


    Example:

    There are many scenarios where having multiple processes running in parallel are advantageous.

    For instance, say you are processing 1000 users and want to check how many comments each has made in the last month. Say each check takes a minute to process (extreme but it makes a better point), it would take 1000 minutes to complete if you run then in sequence by looping through a array or collection of a 1000 users. That's over 16 hours!

    If you queued these as jobs and have numprocs set to 16, then you are done in just over and hour!