Skip to content

Commit b4107d7

Browse files
changing dynamic poller scaling strategy. (#1197)
* changing dynamic poller scaling strategy.
1 parent 2618d0c commit b4107d7

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

internal/common/autoscaler/recommender.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ func (l *linearRecommender) Recommend(currentResource ResourceUnit, currentUsage
5151
if l.targetUsages[usageType] == 0 { // avoid division by zero
5252
r = math.MaxFloat64
5353
} else {
54-
r = currentResource.Value() * currentUsages[usageType].Value() / l.targetUsages[usageType].Value()
54+
if currentUsages[usageType].Value() == float64(1000) {
55+
r = l.upper.Value()
56+
} else {
57+
r = currentResource.Value() * currentUsages[usageType].Value() / l.targetUsages[usageType].Value()
58+
}
5559
}
5660
// boundary check
5761
r = math.Min(l.upper.Value(), math.Max(l.lower.Value(), r))

internal/common/autoscaler/recommender_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ func Test_linearRecommender_Recommend(t *testing.T) {
4141
},
4242
}
4343

44+
highUpperValue := fields{
45+
lower: 5,
46+
upper: 100,
47+
targetUsages: map[UsageType]MilliUsage{
48+
PollerUtilizationRate: 500,
49+
},
50+
}
51+
4452
tests := []struct {
4553
name string
4654
fields fields
@@ -113,6 +121,17 @@ func Test_linearRecommender_Recommend(t *testing.T) {
113121
},
114122
want: ResourceUnit(15),
115123
},
124+
{
125+
name: "over utilized, since we do not how many tasks are in the queue (because poller usage at 100%), scale up to max",
126+
fields: highUpperValue,
127+
args: args{
128+
currentResource: 10,
129+
currentUsages: map[UsageType]MilliUsage{
130+
PollerUtilizationRate: 1000,
131+
},
132+
},
133+
want: ResourceUnit(100),
134+
},
116135
}
117136
for _, tt := range tests {
118137
t.Run(tt.name, func(t *testing.T) {

internal/internal_poller_autoscaler_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
package internal
2222

2323
import (
24+
"math/rand"
25+
"sync"
26+
"testing"
27+
"time"
28+
2429
"github.com/stretchr/testify/assert"
2530
"go.uber.org/atomic"
2631
s "go.uber.org/cadence/.gen/go/shared"
2732
"go.uber.org/cadence/internal/common/autoscaler"
2833
"go.uber.org/zap/zaptest"
29-
"math/rand"
30-
"sync"
31-
"testing"
32-
"time"
3334
)
3435

3536
func Test_pollerAutoscaler(t *testing.T) {
@@ -114,7 +115,7 @@ func Test_pollerAutoscaler(t *testing.T) {
114115
autoScalerEpoch: 1,
115116
isDryRun: false,
116117
},
117-
want: 4,
118+
want: 10,
118119
},
119120
{
120121
name: "over utilized, scale up to max",

0 commit comments

Comments
 (0)