Sizing Laravel Horizon Supervisors Without Exhausting Server RAM
Unlike traditional PHP-FPM requests that tear down memory after every HTTP response, Laravel Horizon workers run as long-lived daemon processes. While persistent workers eliminate framework boot overhead, setting maxProcesses too high relative to physical RAM and memory_limit is the #1 cause of sudden Linux Out-Of-Memory (OOM) worker terminations during traffic spikes.
3 Rules for High-Throughput Redis Queues
- Budget for worst-case memory (
Workers × Memory Limit): Always leave at least 25%–30% of total VPS/server RAM reserved for the OS kernel, Redis in-memory datasets, PHP-FPM web workers, and MySQL buffers. - Isolate I/O-bound vs. CPU-bound queues: Webhook dispatches and external HTTP API calls spend most of their duration waiting on network sockets—you can safely run 16–32 workers per 4 vCPUs. CPU-heavy CSV exports or PDF generators should be isolated on a separate supervisor capped near your vCPU count.
- Rotate workers with
maxJobs: Setting'maxJobs' => 1000instructs Horizon to gracefully recycle a worker process after 1,000 jobs, preventing gradual memory fragmentation from third-party SDKs.
Frequently Asked Questions
What happens if retry_after is shorter than Horizon's timeout?
Redis will release the job back onto the queue while the first worker is still executing it, causing duplicate execution (double emails, duplicate SMS sends, or duplicate database writes). Always keep retry_after in config/queue.php at least 30 seconds higher than your supervisor's timeout.
Should I use auto or simple balancing?
Use 'balance' => 'auto' when a single supervisor handles multiple queues (e.g. ['high', 'default', 'exports']) so Horizon dynamically shifts idle workers toward whichever queue has the longest wait time.