Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Autoscaler never reduces processes to less than 1 #1221

Merged
merged 6 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AutoScaler.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function scalePool(Supervisor $supervisor, $pool, $workers)

if ($desiredProcessCount > $totalProcessCount) {
$maxUpShift = min(
$supervisor->options->maxProcesses - $supervisor->totalProcessCount(),
max(0, $supervisor->options->maxProcesses - $supervisor->totalProcessCount()),
$supervisor->options->balanceMaxShift
);

Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/AutoScalerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,26 @@ public function test_scaler_considers_max_shift_and_attempts_to_get_closer_to_pr
$this->assertEquals(100, $supervisor->processPools['first']->totalProcessCount());
$this->assertEquals(50, $supervisor->processPools['second']->totalProcessCount());
}

public function test_scaler_does_not_permit_going_to_zero_processes_despite_exceeding_max_processes()
{
$external = Mockery::mock(SystemProcessCounter::class);
$external->shouldReceive('get')->with('name')->andReturn(5);
$this->app->instance(SystemProcessCounter::class, $external);

[$scaler, $supervisor] = $this->with_scaling_scenario(15, [
'first' => ['current' => 16, 'size' => 1, 'runtime' => 1],
'second' => ['current' => 1, 'size' => 1, 'runtime' => 1],
], ['minProcesses' => 1]);

$scaler->scale($supervisor);

$this->assertSame(15, $supervisor->processPools['first']->totalProcessCount());
$this->assertSame(1, $supervisor->processPools['second']->totalProcessCount());

$scaler->scale($supervisor);

$this->assertSame(14, $supervisor->processPools['first']->totalProcessCount());
$this->assertSame(1, $supervisor->processPools['second']->totalProcessCount());
}
}