Download the PHP package adamczykpiotr/laravel-balanced-queues without Composer
On this page you can find all versions of the php package adamczykpiotr/laravel-balanced-queues. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download adamczykpiotr/laravel-balanced-queues
More information about adamczykpiotr/laravel-balanced-queues
Files in adamczykpiotr/laravel-balanced-queues
Package laravel-balanced-queues
Short Description Laravel package designed to optimize the performance and efficiency of your application's queue usage
License MIT
Homepage https://github.com/adamczykpiotr/laravel-balanced-queues
Informations about the package laravel-balanced-queues
Laravel Balanced Queues
Stop guessing how many queue workers you need. This package automatically optimizes worker counts based on job type (CPU-intensive, API calls, file downloads) and your server's resources.
Why You Need This
Running 10 workers for everything? You're wasting resources or creating bottlenecks.
- Image downloads saturate your network with too many workers
- API calls queue up with too few concurrent workers
- CPU jobs leave cores idle or cause context-switching overhead
Are you running your application on different machines? Different CPU core configurations, changing network bandwidth? With this package you can optimize it automatically and fine tune it for best results.
Quick Start
Tag your jobs with the right workload type using traits:
Run your queues:
Done. The package spawns all the queues with adjusted worker counts for each job type.
Available helpers
| Helper method | Workload Type | Use Case |
|---|---|---|
onHighCpuUsageQueue |
CPU_HIGH | Large file processing ~MB/GB |
onMediumCpuUsageQueue |
CPU_MEDIUM | PDF generation, smaller file parsing (~KB/MB) |
onLowCpuUsageQueue |
CPU_LOW | Quick background queries |
onHighNetworkRequestUsageQueue |
NETWORK_HIGH_BANDWIDTH | Large file downloads (~ >10MB) |
onHighNetworkBandwidthUsageQueue |
NETWORK_HIGH_REQUESTS | API calls, webhooks |
onFilesystemQueue |
FILESYSTEM | Filesystem operations (duh!) |
How It Works
By default, CPU_HIGH usage assumes 100-50% CPU utilisation for a single job, ~50-25% for CPU_MEDIUM and ~10-20% for CPU_LOW.
Jobs on NETWORK_HIGH_BANDWIDTH are best suited for downloading large files that completely saturate network bandwidth
whereas NETWORK_HIGH_REQUESTS are in most cases are bottleneck by neither network nor cpu and are offloaded on a queue
simply to improve UX. FILESYSTEM jobs are assumed to be bottlenecked by disk I/O.
If the default configuration doesn't fully utilize your machine, adjust the following default configuration in
config/balanced-queues.php:
The default configuration aims to ensure best results across wide range of cases. In order to get full benefits of this approach, it's highly recommended to fine-tune the configuration to your specific use-case. The clue to optimisation is to ensure a single queue can fully saturate the machine:
- Dispatching
CPU_CORESjobs toCPU_HIGHqueue should result in ~100% CPU usage - Dispatching
2*CPU_CORESjobs toCPU_MEDIUMqueue should result in ~100% CPU usage - Dispatching
4*CPU_CORESjobs toCPU_LOWqueue should result in ~100% CPU usage - Dispatching
5jobs toNETWORK_HIGH_BANDWIDTHqueue should result in full network saturation - Dispatching
50jobs toNETWORK_HIGH_REQUESTSshould result in jobs being finished as soon as possible (no real bottleneck) - Dispatching
2jobs toFILESYSTEMqueue should result in full disk I/O saturation
In case more than one queue is fully saturated, OS scheduler will balance processes CPU time accordingly.
Advanced Configuration
Custom Queue Names
VM / Docker CPU Limits
Override auto-detected CPU core count:
Worker Options
Add additional options to artisan queue:work command:
Supervisor Configuration
Customize the generated Supervisor configuration:
Commands
Docker container entrypoint example
Requirements
- PHP 8.3+
- Laravel 11.x or 12.x
- Supervisor
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Piotr Adamczyk
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-balanced-queues with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0