Ensure Autoscaler never reduces processes to less than 1 #1221
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Last week, we started noticing some of our queues having 0 Processes assigned, despite this being against how Horizon is designed to work. Processes must always be positive, even if you specifically set
minProcesses = 0
.After much digging, I eventually went through and added
Log::debug
statements all over the AutoScaler:Somehow Horizon would spawn 1 more process than was allowed (another issue for another day) and when then subtracting
maxProcesses
withtotalProcessCount()
, we would get -1.Later down in the code it then picks which value to use for scaling:
Conclusion
As we saw above,
$totalProcessCount = 1
and$maxUpShift = -1
, which means this will return 0, setting processes to zero!So when it tries to scale UP, it actually ends up scaling DOWN. Once it then hits 0, it seems to never be able to recover.
Solution
It is luckily not a difficult problem to solve. Wrapping
max(0, ...)
around the code that calculates$maxUpShift
will prevent it from ever being negative, thus solving our problem.I am aware that this technically fixes a problem that you might think is not there (why is processes greater than maxProcesses?) and whilst I agree, I also don't see the harm in covering all the bases.
Similar issue(s)
My abbreviated config for reference