将策略推导出的集群目标与单 Worker 内存安全上限分离,避免失活实例的全部容量转移到单个 2 GiB Pod。 生产环境单实例上限和媒体物化并发设为 24;两实例正常时总容量由 16 提升至 48,后续可通过增加 Worker 节点继续扩展。新增 0093 迁移保存实例容量上限,并兼容滚动发布中的旧实例。 风险:更高媒体并发会增加 Worker 和节点内存压力,保留单实例 24 的硬边界并由持续监控观察 RSS、OOM、队列与节点余量。 验证:go test ./... -count=1;go vet ./...;真实 PostgreSQL 分配与故障转移测试;迁移安全检查;kubectl kustomize;gofmt -l;git diff --check。
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package store
|
|
|
|
import "testing"
|
|
|
|
func TestAllocateWorkerCapacitiesHonorsInstanceLimits(t *testing.T) {
|
|
workers := []activeWorkerCapacity{
|
|
{InstanceID: "worker-a", CapacityLimit: 24},
|
|
{InstanceID: "worker-b", CapacityLimit: 24},
|
|
}
|
|
allocations, global := allocateWorkerCapacities(workers, 310)
|
|
if global != 48 || allocations["worker-a"] != 24 || allocations["worker-b"] != 24 {
|
|
t.Fatalf("allocations=%v global=%d, want 24/24 and 48", allocations, global)
|
|
}
|
|
}
|
|
|
|
func TestAllocateWorkerCapacitiesBalancesBelowLimits(t *testing.T) {
|
|
workers := []activeWorkerCapacity{
|
|
{InstanceID: "worker-a", CapacityLimit: 24},
|
|
{InstanceID: "worker-b", CapacityLimit: 24},
|
|
}
|
|
allocations, global := allocateWorkerCapacities(workers, 5)
|
|
if global != 5 || allocations["worker-a"] != 3 || allocations["worker-b"] != 2 {
|
|
t.Fatalf("allocations=%v global=%d, want 3/2 and 5", allocations, global)
|
|
}
|
|
}
|
|
|
|
func TestAllocateWorkerCapacitiesKeepsSurvivorBounded(t *testing.T) {
|
|
workers := []activeWorkerCapacity{{InstanceID: "worker-a", CapacityLimit: 24}}
|
|
allocations, global := allocateWorkerCapacities(workers, 310)
|
|
if global != 24 || allocations["worker-a"] != 24 {
|
|
t.Fatalf("allocations=%v global=%d, want survivor capped at 24", allocations, global)
|
|
}
|
|
}
|
|
|
|
func TestAllocateWorkerCapacitiesSupportsUnequalLimits(t *testing.T) {
|
|
workers := []activeWorkerCapacity{
|
|
{InstanceID: "worker-a", CapacityLimit: 1},
|
|
{InstanceID: "worker-b", CapacityLimit: 4},
|
|
}
|
|
allocations, global := allocateWorkerCapacities(workers, 5)
|
|
if global != 5 || allocations["worker-a"] != 1 || allocations["worker-b"] != 4 {
|
|
t.Fatalf("allocations=%v global=%d, want 1/4 and 5", allocations, global)
|
|
}
|
|
}
|