mirror of
https://github.com/actions-runner-controller/actions-runner-controller.git
synced 2026-10-01 16:53:59 +02:00
Improve performance of controllers
This commit is contained in:
@@ -229,22 +229,18 @@ func (w *Scaler) setDesiredWorkerState(count int) int {
|
||||
dirty := w.dirty
|
||||
w.dirty = false
|
||||
|
||||
if w.patchSeq == math.MaxInt32 {
|
||||
if w.patchSeq == math.MaxInt64 {
|
||||
w.patchSeq = 0
|
||||
}
|
||||
w.patchSeq++
|
||||
|
||||
targetRunnerCount := min(w.config.MinRunners+count, w.config.MaxRunners)
|
||||
oldTargetRunners := w.targetRunners
|
||||
w.targetRunners = targetRunnerCount
|
||||
|
||||
desiredPatchID := w.patchSeq
|
||||
if !dirty && targetRunnerCount == oldTargetRunners && targetRunnerCount == w.config.MinRunners {
|
||||
// If there were no events sent, and the target runner count
|
||||
// is the same as the last patched count, we can force the state.
|
||||
//
|
||||
// TODO: see to remove w.config.MinRunenrs from the equation, as it is not relevant to the decision of whether to patch or not.
|
||||
desiredPatchID = 0
|
||||
desiredPatchID := w.patchSeq + 1
|
||||
if dirty || targetRunnerCount != oldTargetRunners || targetRunnerCount != w.config.MinRunners {
|
||||
w.patchSeq++
|
||||
desiredPatchID = w.patchSeq
|
||||
}
|
||||
|
||||
w.logger.Info(
|
||||
|
||||
@@ -129,7 +129,7 @@ func TestSetDesiredWorkerState_MinSet(t *testing.T) {
|
||||
assert.Equal(t, 1, w.patchSeq)
|
||||
})
|
||||
|
||||
t.Run("desired patch is 0 but sequence continues on empty batch and min runners", func(t *testing.T) {
|
||||
t.Run("desired patch repeats without advancing sequence on empty batch and min runners", func(t *testing.T) {
|
||||
w := newEmptyWorker()
|
||||
patchID := w.setDesiredWorkerState(3)
|
||||
assert.False(t, w.dirty)
|
||||
@@ -147,9 +147,9 @@ func TestSetDesiredWorkerState_MinSet(t *testing.T) {
|
||||
// Empty batch on min runners
|
||||
patchID = w.setDesiredWorkerState(0)
|
||||
assert.False(t, w.dirty)
|
||||
assert.Equal(t, 0, patchID) // forcing the state
|
||||
assert.Equal(t, 2, patchID)
|
||||
assert.Equal(t, 1, w.targetRunners)
|
||||
assert.Equal(t, 2, w.patchSeq)
|
||||
assert.Equal(t, 1, w.patchSeq)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ func TestSetDesiredWorkerState_MaxSet(t *testing.T) {
|
||||
assert.Equal(t, 1, w.patchSeq)
|
||||
})
|
||||
|
||||
t.Run("force 0 on empty batch and last patch == min runners", func(t *testing.T) {
|
||||
t.Run("desired patch repeats without advancing sequence on empty batch and min runners", func(t *testing.T) {
|
||||
w := newEmptyWorker()
|
||||
patchID := w.setDesiredWorkerState(3)
|
||||
assert.Equal(t, 0, patchID)
|
||||
@@ -249,9 +249,9 @@ func TestSetDesiredWorkerState_MaxSet(t *testing.T) {
|
||||
|
||||
// Empty batch on min runners
|
||||
patchID = w.setDesiredWorkerState(0)
|
||||
assert.Equal(t, 0, patchID) // forcing the state
|
||||
assert.Equal(t, 2, patchID)
|
||||
assert.Equal(t, 0, w.targetRunners)
|
||||
assert.Equal(t, 2, w.patchSeq)
|
||||
assert.Equal(t, 1, w.patchSeq)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ func TestSetDesiredWorkerState_MinMaxSet(t *testing.T) {
|
||||
assert.Equal(t, 0, w.patchSeq)
|
||||
})
|
||||
|
||||
t.Run("force 0 on empty batch and last patch == min runners", func(t *testing.T) {
|
||||
t.Run("desired patch repeats without advancing sequence on empty batch and min runners", func(t *testing.T) {
|
||||
w := newEmptyWorker()
|
||||
patchID := w.setDesiredWorkerState(3)
|
||||
assert.False(t, w.dirty)
|
||||
@@ -327,8 +327,8 @@ func TestSetDesiredWorkerState_MinMaxSet(t *testing.T) {
|
||||
// Empty batch on min runners
|
||||
patchID = w.setDesiredWorkerState(0)
|
||||
assert.False(t, w.dirty)
|
||||
assert.Equal(t, 0, patchID) // forcing the state
|
||||
assert.Equal(t, 2, patchID)
|
||||
assert.Equal(t, 1, w.targetRunners)
|
||||
assert.Equal(t, 2, w.patchSeq)
|
||||
assert.Equal(t, 1, w.patchSeq)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user