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

ivqonsanada's avatar

Laravel Cloud Scaling

Is there any insights to scale app for maybe 5000 RPS in Laravel Cloud? previously i tried 1 Pro CPU its not even used 10% CPU and less than 10% RAM usage, with 44 RPS, meanhwile in Laravel Forge it could goes to 121 RPS for cheaper option. Any recommended settings for octane workers?

the insight i get also that serverless postgres increase 2ms for each query,

so let say an API total cost 15ms with Laravel Cloud serverless, it now become 45ms

0 likes
2 replies
LaryAI's avatar
Level 58

To efficiently scale your Laravel app to handle 5000 RPS using Laravel Cloud (and leveraging Laravel Octane), here are some insights and recommended settings:

1. Ensure You're Using Octane's Strengths

Laravel Octane keeps your application in memory between requests, offering significant speedups for high RPS workloads. Make sure you’re using a supported server (Swoole or RoadRunner).

2. Octane Worker Settings

For high concurrency, adjust the following Octane settings in your config/octane.php:

// config/octane.php

'workers' => env('OCTANE_WORKERS', 24), // Start with number of CPU cores * 2
'task_workers' => env('OCTANE_TASK_WORKERS', 8),
'max_requests' => env('OCTANE_MAX_REQUESTS', 5000), // Restart worker after this many requests

You may need to increase OCTANE_WORKERS if you have more CPU cores available. Test what your CPU can handle and increment as needed.

3. Optimize Your App

  • Cache Config/Routes: Always use php artisan config:cache and php artisan route:cache.
  • Database: Use a managed DB and optimize queries (limit N+1 problems).
  • Queue Jobs: Offload heavy work to queues.
  • Sessions/Cache driver: Use Redis for both, not file/database drivers.

4. Use a Load Balancer

  • If possible, scale horizontally—run multiple instances of your app behind a load balancer.
  • Leverage Laravel Cloud's scaling settings to increase the number of containers as needed.

5. Scale Database & Dependencies

  • Ensure your DB, cache, queue, etc., can handle the load (don’t let these become bottlenecks).

6. Monitor Octane Memory Leaks

  • Memory leaks or long request times may force workers to restart. Use monitoring/logs to track this.

7. Test Practically

Example benchmarking command:

wrk -t16 -c500 -d30s https://your-app-url.com/

8. Sample octane.ini for Swoole

If you're using Swoole, you can fine-tune via an .ini or in your config/octane.php:

'swoole' => [
    'options' => [
        'reactor_num'   => env('SWOOLE_REACTOR_NUM', 12), // usually CPU cores
        'worker_num'    => env('SWOOLE_WORKER_NUM', 24),
        'max_request'   => env('SWOOLE_MAX_REQUEST', 5000),
        'task_worker_num' => env('SWOOLE_TASK_WORKER_NUM', 8),
        // Other Swoole specific options
    ],
],

Summary Checklist

  • Use Octane (Swoole/RoadRunner)
  • Set workers to at least number of CPU cores * 2
  • Use Redis for cache/sessions
  • Offload heavy processes to queues
  • Use horizontal scaling with a Load Balancer
  • Optimize queries, Eloquent usage, and avoid bootstrapping Laravel on each request
  • Test with real-world RPS and monitor

Further reading:

You might need more than just CPU if you run into connection limits on DB/cache, so scale dependencies accordingly.

Let me know if you have questions about a specific configuration or error you’re hitting!

ivqonsanada's avatar

so its best to scale horizontally for increasing CPU Core and workers numbers? despite of the CPU utilization not fully used

Please or to participate in this conversation.