Autoscaling
A Laravel application on PAM has two independent things to scale:
| What | Scaled with | Unit |
|---|---|---|
| HTTP concurrency | pam start pam.php --workers N, replicas, or servers |
Workers (one Laravel request each) |
| Background work | pam.processes.json, pam:process scale, pam:autoscale |
Process instances (queue workers, Horizon, custom daemons) |
Do not add HTTP workers to drain a queue, and never process a queue inside a request.
Scaling HTTP Workers
Section titled “Scaling HTTP Workers”On one server, change --workers and reload:
pam start pam.php --workers 12 --admin-address 127.0.0.1:3010Size it with Performance Tuning.
Across servers, put several PAM instances behind a load balancer that checks
each instance’s /ready, and add instances when CPU or p95 latency stays high.
On PAM Cloud:
pam artisan pam:remote scale production --process=http --instances=8Scaling Queue Workers Manually
Section titled “Scaling Queue Workers Manually”pam artisan pam:process scale queue 4pam artisan pam:process statusThe override is saved in storage/pam/processes/scale.json and survives
restarts of the manifest. Instances are limited to 1..128.
Scaling From Metrics
Section titled “Scaling From Metrics”pam:autoscale compares CPU and p95 latency with your targets and scales a
manifest process:
pam artisan pam:autoscale queue --cpu=80 --p95=400queue desired instances: 2The rules:
- Scale up by
max(1, ceil(current × 25%))when CPU is abovePAM_AUTOSCALE_TARGET_CPUor p95 is abovePAM_AUTOSCALE_TARGET_P95_MS. - Scale down by one instance when CPU and p95 are both below half of their targets.
- Stay within
PAM_AUTOSCALE_MIN..PAM_AUTOSCALE_MAX(and never above128). - Wait
PAM_AUTOSCALE_COOLDOWNseconds between changes to the same process; the last change is recorded instorage/pam/processes/autoscale.json.
PAM_AUTOSCALE_MIN=1PAM_AUTOSCALE_MAX=16PAM_AUTOSCALE_TARGET_CPU=65PAM_AUTOSCALE_TARGET_P95_MS=250PAM_AUTOSCALE_COOLDOWN=60Scaling restarts the process with the new instance count, so queue workers
must handle SIGTERM gracefully (Laravel’s workers finish the current job).
Continuous Reconciliation
Section titled “Continuous Reconciliation”Point the command at an endpoint that returns the current numbers:
PAM_AUTOSCALE_METRICS_URL=https://metrics.example.com/pam/queue-capacityPAM_AUTOSCALE_METRICS_TOKEN=your-token{ "cpuPercent": 72.5, "p95Milliseconds": 310 }pam artisan pam:autoscale queue --watch --interval=30- The URL must be HTTPS, or HTTP on
127.0.0.1,localhost, or::1. - The token is sent as
Authorization: Bearer …. --intervalis clamped to5..300seconds (default15).--watchwithout a metrics URL is rejected; any fetch error stops the command with exit code1, so run it under a supervisor that restarts it.
Guardrails
Section titled “Guardrails”- Cap database and Redis connections before you raise instance counts.
- Alert on queue age, not only depth.
- Make jobs idempotent and bound their retries.
- Respect third-party API rate limits; more workers can mean more
429s. - Keep the scheduler at exactly one instance.