Skip to content

Commit

Permalink
address incorrect scaling direction
Browse files Browse the repository at this point in the history
  • Loading branch information
shijiesheng committed Jan 2, 2025
1 parent 636c433 commit 25b9d7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion internal/worker/concurrency_auto_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (c *ConcurrencyAutoScaler) updatePollerPermit() {
return
}
currentQuota := c.concurrency.PollerPermit.Quota()
newQuota := int(math.Round(float64(currentQuota) * c.pollerWaitTimeInMsLog2.Average() / targetPollerWaitTimeInMsLog2))
newQuota := int(math.Round(float64(currentQuota) * targetPollerWaitTimeInMsLog2 / c.pollerWaitTimeInMsLog2.Average() ))
if newQuota < c.pollerMinCount {
newQuota = c.pollerMinCount
}
Expand Down
42 changes: 21 additions & 21 deletions internal/worker/concurrency_auto_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestConcurrencyAutoScaler(t *testing.T) {
},
},
{
"too many pollers",
"busy pollers",
[]*shared.AutoConfigHint{
{common.PtrOf(true), common.PtrOf(int64(10))}, // <- tick, in cool down
{common.PtrOf(true), common.PtrOf(int64(10))}, // <- tick, scale up
Expand All @@ -102,12 +102,12 @@ func TestConcurrencyAutoScaler(t *testing.T) {
{autoScalerEventStart, false, 100, "00:00:00"},
{autoScalerEventEnable, true, 100, "00:00:00"},
{autoScalerEventPollerSkipUpdateCooldown, true, 100, "00:00:01"},
{autoScalerEventPollerUpdate, true, 86, "00:00:02"},
{autoScalerEventStop, true, 86, "00:00:02"},
{autoScalerEventPollerUpdate, true, 116, "00:00:02"},
{autoScalerEventStop, true, 116, "00:00:02"},
},
},
{
"too many pollers, scale down to minimum",
"busy pollers, scale up to maximum",
[]*shared.AutoConfigHint{
{common.PtrOf(true), common.PtrOf(int64(0))}, // <- tick, in cool down
{common.PtrOf(true), common.PtrOf(int64(0))}, // <- tick, scale down to minimum
Expand All @@ -116,12 +116,12 @@ func TestConcurrencyAutoScaler(t *testing.T) {
{autoScalerEventStart, false, 100, "00:00:00"},
{autoScalerEventEnable, true, 100, "00:00:00"},
{autoScalerEventPollerSkipUpdateCooldown, true, 100, "00:00:01"},
{autoScalerEventPollerUpdate, true, 50, "00:00:02"},
{autoScalerEventStop, true, 50, "00:00:02"},
{autoScalerEventPollerUpdate, true, 200, "00:00:02"},
{autoScalerEventStop, true, 200, "00:00:02"},
},
},
{
"lack pollers",
"idl pollers waiting for tasks",
[]*shared.AutoConfigHint{
{common.PtrOf(true), common.PtrOf(int64(100))}, // <- tick, in cool down
{common.PtrOf(true), common.PtrOf(int64(100))}, // <- tick, scale up
Expand All @@ -130,12 +130,12 @@ func TestConcurrencyAutoScaler(t *testing.T) {
{autoScalerEventStart, false, 100, "00:00:00"},
{autoScalerEventEnable, true, 100, "00:00:00"},
{autoScalerEventPollerSkipUpdateCooldown, true, 100, "00:00:01"},
{autoScalerEventPollerUpdate, true, 166, "00:00:02"},
{autoScalerEventStop, true, 166, "00:00:02"},
{autoScalerEventPollerUpdate, true, 60, "00:00:02"},
{autoScalerEventStop, true, 60, "00:00:02"},
},
},
{
"lack pollers, scale up to maximum",
"idl pollers, scale down to minimum",
[]*shared.AutoConfigHint{
{common.PtrOf(true), common.PtrOf(int64(10000))}, // <- tick, in cool down
{common.PtrOf(true), common.PtrOf(int64(10000))}, // <- tick, scale up
Expand All @@ -144,12 +144,12 @@ func TestConcurrencyAutoScaler(t *testing.T) {
{autoScalerEventStart, false, 100, "00:00:00"},
{autoScalerEventEnable, true, 100, "00:00:00"},
{autoScalerEventPollerSkipUpdateCooldown, true, 100, "00:00:01"},
{autoScalerEventPollerUpdate, true, 200, "00:00:02"},
{autoScalerEventStop, true, 200, "00:00:02"},
{autoScalerEventPollerUpdate, true, 50, "00:00:02"},
{autoScalerEventStop, true, 50, "00:00:02"},
},
},
{
"lack pollers but disabled",
"idl pollers but disabled scaling",
[]*shared.AutoConfigHint{
{common.PtrOf(false), common.PtrOf(int64(100))}, // <- tick, in cool down
{common.PtrOf(false), common.PtrOf(int64(100))}, // <- tick, scale up
Expand All @@ -162,24 +162,24 @@ func TestConcurrencyAutoScaler(t *testing.T) {
},
},
{
"too many pollers but disabled at a later time",
"idl pollers but disabled scaling at a later time",
[]*shared.AutoConfigHint{
{common.PtrOf(true), common.PtrOf(int64(10))}, // <- tick, in cool down
{common.PtrOf(true), common.PtrOf(int64(10))}, // <- tick, scale up
{common.PtrOf(false), common.PtrOf(int64(10))}, // <- disable
{common.PtrOf(true), common.PtrOf(int64(100))}, // <- tick, in cool down
{common.PtrOf(true), common.PtrOf(int64(100))}, // <- tick, scale up
{common.PtrOf(false), common.PtrOf(int64(100))}, // <- disable
},
[]eventLog{
{autoScalerEventStart, false, 100, "00:00:00"},
{autoScalerEventEnable, true, 100, "00:00:00"},
{autoScalerEventPollerSkipUpdateCooldown, true, 100, "00:00:01"},
{autoScalerEventPollerUpdate, true, 86, "00:00:02"},
{autoScalerEventPollerUpdate, true, 60, "00:00:02"},
{autoScalerEventDisable, false, 100, "00:00:02"},
{autoScalerEventPollerSkipUpdateNotEnabled, false, 100, "00:00:03"},
{autoScalerEventStop, false, 100, "00:00:03"},
},
},
{
"lack pollers and enabled at a later time",
"idl pollers and enabled at a later time",
[]*shared.AutoConfigHint{
{common.PtrOf(false), common.PtrOf(int64(100))}, // <- tick, in cool down
{common.PtrOf(false), common.PtrOf(int64(100))}, // <- tick, not enabled
Expand All @@ -190,8 +190,8 @@ func TestConcurrencyAutoScaler(t *testing.T) {
{autoScalerEventPollerSkipUpdateNotEnabled, false, 100, "00:00:01"},
{autoScalerEventPollerSkipUpdateNotEnabled, false, 100, "00:00:02"},
{autoScalerEventEnable, true, 100, "00:00:02"},
{autoScalerEventPollerUpdate, true, 166, "00:00:03"},
{autoScalerEventStop, true, 166, "00:00:03"},
{autoScalerEventPollerUpdate, true, 60, "00:00:03"},
{autoScalerEventStop, true, 60, "00:00:03"},
},
},
} {
Expand Down

0 comments on commit 25b9d7c

Please sign in to comment.