Your Laravel queue worker count is a guess. Here is the math that replaces it.
Every Laravel deployment I have seen has a line like this somewhere: [program:queue-worker] numprocs = 10 Why 10? Nobody knows. Someone picked it years ago and it stayed. Too low and jobs wait minutes during a campaign blast. Too high and you burn RAM all night for workers doing nothing. The number is wrong in both directions because load changes and the config does not. I spent this week testing…
A Laravel deployment often includes a line specifying the number of queue worker processes, but this value is often arbitrary and may need adjustment. To determine the optimal number of workers, the author tested an alternative approach using the cboxdk/laravel-queue-autoscale package alongside cboxdk/laravel-queue-metrics. This system derives the number of workers based on a defined Service Level Agreement (SLA), which determines how long a job must be processed.
The formula calculates the required throughput based on the SLA and the number of jobs currently pending. The author's measured results showed that the formula accurately predicted the required number of workers for their specific workload. An important consideration is that the autoscaler uses Little's Law, a theorem from queueing theory, to determine the optimal number of workers.
The package also implements safeguards to prevent overscaling or underscaling the queue. The system can handle failures gracefully by scaling down to the minimum number of workers when all jobs fail. The autoscaler only needs a single Redis connection and works with PHP 8.4 or later. Overall, the package provides an automated way to determine the optimal number of workers based on the workload, rather than relying on arbitrarily chosen values.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.