Scaling Decision
Scaling Decision
Returned by ScalingEngine::evaluate() and dispatched in ScalingDecisionMade / SlaBreachPredicted events.
namespace Cbox\LaravelQueueAutoscale\Scaling;
readonly class ScalingDecision
{
public function __construct(
public string $connection,
public string $queue,
public int $currentWorkers,
public int $targetWorkers,
public string $reason,
public ?float $predictedPickupTime = null,
public int $slaTarget = 30,
public ?CapacityCalculationResult $capacity = null,
public ?SpawnCompensationConfiguration $spawnCompensation = null,
) {}
public function shouldScaleUp(): bool;
public function shouldScaleDown(): bool;
public function shouldHold(): bool;
public function workersToAdd(): int;
public function workersToRemove(): int;
public function action(): string; // 'scale_up' | 'scale_down' | 'hold'
public function isSlaBreachRisk(): bool; // predictedPickupTime > slaTarget
}
There is no confidence property on ScalingDecision, or anywhere else in the package.
Do not confuse ScalingDecision::action() ('scale_up' | 'scale_down' | 'hold') with WorkersScaled::$action, which is always 'up' or 'down'.
CapacityCalculationResult
ScalingDecision::$capacity, in Cbox\LaravelQueueAutoscale\Scaling\DTOs:
readonly class CapacityCalculationResult
{
public function __construct(
public int $maxWorkersByCpu,
public int $maxWorkersByMemory,
public int $maxWorkersByConfig,
public int $finalMaxWorkers,
public string $limitingFactor,
public array $details = [],
) {}
public function cpuBreakdown(): CpuBreakdown;
public function memoryBreakdown(): MemoryBreakdown;
public function isCpuLimited(): bool;
public function isMemoryLimited(): bool;
public function isConfigLimited(): bool;
public function getSummary(): string;
public function getFormattedDetails(): array;
}
cpuBreakdown() and memoryBreakdown() return the same numbers as the nested
cpu_details / memory_details entries of $details, as typed readonly objects —
prefer them over indexing into the array. MemoryBreakdown also derives usedMb()
and freeMb() from the percentage and total.
$cpu = $decision->capacity->cpuBreakdown();
$cpu->totalCores; // float
$cpu->usableCores; // float, total minus the reserve
$cpu->currentCpuPercent; // float
$cpu->workerCpuCoreEstimate; // float, cores one worker is assumed to occupy
$cpu->estimateSource; // 'measured', 'config' or 'default'
limitingFactor values seen on a decision: cpu, memory, balanced, config, strategy, fuse, system_metrics_unavailable.