Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SNaRe's avatar
Level 7

Dynamic Number of Workers

Hi, Some of the jobs that have run is consuming high cpu on db side. So I would like to dynamically alter number of jobs that are running. By the way Laravel 5.8 and I'm using laravel horizon. Thanks in advance.

0 likes
5 replies
SNaRe's avatar
Level 7

Thank yo for your answer. @munazzil Actually My Question is how to dynamically change number of workers in horizon or directly artisan queue:work command

kobear's avatar

@snare Do you have more than one queue that needs workers assigned?

kobear's avatar

Sorry for the late response. What I do is I have a pool of workers that are managed by Horizon. The Horizon config has the 'balance' value set to auto. That way when the queues are idle, it splits the workers assigned between the queues that are defined, but when there is work to do in one queue, and not others, it dynamically changes those workers to process the other queues that have work ready.

For example, I have 2 queues and 40 workers defined. At idle, each queue has 20 workers assigned, but when items are assigned to the queue (generally there is a 100/1 ratio of items in the queues), it dynamically moves the queue workers to where the work needs to be done.

I hope that helps you.

Please or to participate in this conversation.