fix(worker): 记住轮询间隔内的容量需求
异步视频任务在 River 轮询空档会释放本地 lease,采样瞬间可能观察不到已经触顶的领取需求,导致自适应容量长期停在初始值。本提交记录采样窗口内出现过的容量饱和,同时保持空闲 Worker 不盲目升容。\n\n移植时保留主线现有的单节点容量阶梯、请求下限和严格失败门禁,仅合入失败路径先记录并排空任务与回调、再删除模拟器资源的清理顺序,并补充脚本守卫。\n\n验证:go test ./... -count=1;go vet ./...;bash -n;ShellCheck;production-acceptance-script-test.sh。
This commit is contained in:
@@ -29,6 +29,43 @@ func TestControllerStartsConservativelyAndGrowsUnderSustainedDemand(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerRemembersDemandAcrossShortPollingRuns(t *testing.T) {
|
||||
controller := New(Config{Mode: ModeAdaptive, HardLimit: 8, InitialActive: 4, InitialHeavy: 4, HealthySamples: 2})
|
||||
for range 2 {
|
||||
leases := make([]*Lease, 0, 4)
|
||||
for range 4 {
|
||||
lease, ok := controller.TryStart()
|
||||
if !ok {
|
||||
t.Fatal("short polling task was not admitted")
|
||||
}
|
||||
leases = append(leases, lease)
|
||||
}
|
||||
for _, lease := range leases {
|
||||
lease.Release()
|
||||
}
|
||||
controller.Observe(ResourceSample{
|
||||
MemoryCurrentBytes: 30,
|
||||
MemoryLimitBytes: 100,
|
||||
CPUUtilization: .3,
|
||||
DBConnections: 3,
|
||||
DBMaxConnections: 20,
|
||||
})
|
||||
}
|
||||
if snapshot := controller.Snapshot(); snapshot.ActiveLimit != 5 || snapshot.SafeCapacity != 5 {
|
||||
t.Fatalf("grown snapshot=%+v, want active=5 safe=5", snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerDoesNotGrowWhileIdleWithoutDemand(t *testing.T) {
|
||||
controller := New(Config{Mode: ModeAdaptive, HardLimit: 8, InitialActive: 4, InitialHeavy: 1, HealthySamples: 2})
|
||||
for range 4 {
|
||||
controller.Observe(ResourceSample{MemoryCurrentBytes: 20, MemoryLimitBytes: 100, CPUUtilization: .2})
|
||||
}
|
||||
if snapshot := controller.Snapshot(); snapshot.ActiveLimit != 4 {
|
||||
t.Fatalf("idle snapshot=%+v, want active=4", snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerBusyAndCriticalPressureReduceNewClaims(t *testing.T) {
|
||||
controller := New(Config{Mode: ModeAdaptive, HardLimit: 16, InitialActive: 8, InitialHeavy: 2})
|
||||
busy := controller.Observe(ResourceSample{MemoryCurrentBytes: 80, MemoryLimitBytes: 100})
|
||||
|
||||
Reference in New Issue
Block a user