mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Static Consumption added to autoscaling_utils.go
This commit is contained in:
parent
0f8cc8926f
commit
152991f06c
@ -28,15 +28,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
consumptionTimeInSeconds = 30
|
||||
sleepTime = 30 * time.Second
|
||||
requestSizeInMillicores = 100
|
||||
requestSizeInMegabytes = 100
|
||||
port = 80
|
||||
targetPort = 8080
|
||||
timeoutRC = 120 * time.Second
|
||||
image = "gcr.io/google_containers/resource_consumer:beta"
|
||||
rcIsNil = "ERROR: replicationController = nil"
|
||||
dynamicConsumptionTimeInSeconds = 30
|
||||
staticConsumptionTimeInSeconds = 3600
|
||||
dynamicRequestSizeInMillicores = 100
|
||||
dynamicRequestSizeInMegabytes = 100
|
||||
port = 80
|
||||
targetPort = 8080
|
||||
timeoutRC = 120 * time.Second
|
||||
image = "gcr.io/google_containers/resource_consumer:beta"
|
||||
rcIsNil = "ERROR: replicationController = nil"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -48,12 +48,24 @@ rc.ConsumeCPU(300)
|
||||
// ... check your assumption here
|
||||
*/
|
||||
type ResourceConsumer struct {
|
||||
name string
|
||||
framework *Framework
|
||||
cpu chan int
|
||||
mem chan int
|
||||
stopCPU chan int
|
||||
stopMem chan int
|
||||
name string
|
||||
framework *Framework
|
||||
cpu chan int
|
||||
mem chan int
|
||||
stopCPU chan int
|
||||
stopMem chan int
|
||||
consumptionTimeInSeconds int
|
||||
sleepTime time.Duration
|
||||
requestSizeInMillicores int
|
||||
requestSizeInMegabytes int
|
||||
}
|
||||
|
||||
func NewDynamicResourceConsumer(name string, replicas, initCPU, initMemory int, cpuLimit, memLimit int64, framework *Framework) *ResourceConsumer {
|
||||
return newResourceConsumer(name, replicas, initCPU, initMemory, dynamicConsumptionTimeInSeconds, dynamicRequestSizeInMillicores, dynamicRequestSizeInMegabytes, cpuLimit, memLimit, framework)
|
||||
}
|
||||
|
||||
func NewStaticResourceConsumer(name string, replicas, initCPU, initMemory int, cpuLimit, memLimit int64, framework *Framework) *ResourceConsumer {
|
||||
return newResourceConsumer(name, replicas, initCPU, initMemory, staticConsumptionTimeInSeconds, initCPU/replicas, initMemory/replicas, cpuLimit, memLimit, framework)
|
||||
}
|
||||
|
||||
/*
|
||||
@ -63,15 +75,19 @@ initMemory argument is in megabytes
|
||||
memLimit argument is in megabytes, memLimit is a maximum amount of memory that can be consumed by a single pod
|
||||
cpuLimit argument is in millicores, cpuLimit is a maximum amount of cpu that can be consumed by a single pod
|
||||
*/
|
||||
func NewResourceConsumer(name string, replicas, initCPU, initMemory int, cpuLimit, memLimit int64, framework *Framework) *ResourceConsumer {
|
||||
func newResourceConsumer(name string, replicas, initCPU, initMemory, consumptionTimeInSeconds, requestSizeInMillicores, requestSizeInMegabytes int, cpuLimit, memLimit int64, framework *Framework) *ResourceConsumer {
|
||||
runServiceAndRCForResourceConsumer(framework.Client, framework.Namespace.Name, name, replicas, cpuLimit, memLimit)
|
||||
rc := &ResourceConsumer{
|
||||
name: name,
|
||||
framework: framework,
|
||||
cpu: make(chan int),
|
||||
mem: make(chan int),
|
||||
stopCPU: make(chan int),
|
||||
stopMem: make(chan int),
|
||||
name: name,
|
||||
framework: framework,
|
||||
cpu: make(chan int),
|
||||
mem: make(chan int),
|
||||
stopCPU: make(chan int),
|
||||
stopMem: make(chan int),
|
||||
consumptionTimeInSeconds: consumptionTimeInSeconds,
|
||||
sleepTime: time.Duration(consumptionTimeInSeconds) * time.Second,
|
||||
requestSizeInMillicores: requestSizeInMillicores,
|
||||
requestSizeInMegabytes: requestSizeInMegabytes,
|
||||
}
|
||||
go rc.makeConsumeCPURequests()
|
||||
rc.ConsumeCPU(initCPU)
|
||||
@ -93,18 +109,22 @@ func (rc *ResourceConsumer) ConsumeMem(megabytes int) {
|
||||
func (rc *ResourceConsumer) makeConsumeCPURequests() {
|
||||
var count int
|
||||
var rest int
|
||||
sleepTime := time.Duration(0)
|
||||
for {
|
||||
select {
|
||||
case millicores := <-rc.cpu:
|
||||
count = millicores / requestSizeInMillicores
|
||||
rest = millicores - count*requestSizeInMillicores
|
||||
if rc.requestSizeInMillicores != 0 {
|
||||
count = millicores / rc.requestSizeInMillicores
|
||||
}
|
||||
rest = millicores - count*rc.requestSizeInMillicores
|
||||
case <-time.After(sleepTime):
|
||||
if count > 0 {
|
||||
rc.sendConsumeCPURequests(count, requestSizeInMillicores, consumptionTimeInSeconds)
|
||||
rc.sendConsumeCPURequests(count, rc.requestSizeInMillicores, rc.consumptionTimeInSeconds)
|
||||
}
|
||||
if rest > 0 {
|
||||
go rc.sendOneConsumeCPURequest(rest, consumptionTimeInSeconds)
|
||||
go rc.sendOneConsumeCPURequest(rest, rc.consumptionTimeInSeconds)
|
||||
}
|
||||
sleepTime = rc.sleepTime
|
||||
case <-rc.stopCPU:
|
||||
return
|
||||
}
|
||||
@ -114,18 +134,22 @@ func (rc *ResourceConsumer) makeConsumeCPURequests() {
|
||||
func (rc *ResourceConsumer) makeConsumeMemRequests() {
|
||||
var count int
|
||||
var rest int
|
||||
sleepTime := time.Duration(0)
|
||||
for {
|
||||
select {
|
||||
case megabytes := <-rc.mem:
|
||||
count = megabytes / requestSizeInMegabytes
|
||||
rest = megabytes - count*requestSizeInMegabytes
|
||||
if rc.requestSizeInMegabytes != 0 {
|
||||
count = megabytes / rc.requestSizeInMegabytes
|
||||
}
|
||||
rest = megabytes - count*rc.requestSizeInMegabytes
|
||||
case <-time.After(sleepTime):
|
||||
if count > 0 {
|
||||
rc.sendConsumeMemRequests(count, requestSizeInMegabytes, consumptionTimeInSeconds)
|
||||
rc.sendConsumeMemRequests(count, rc.requestSizeInMegabytes, rc.consumptionTimeInSeconds)
|
||||
}
|
||||
if rest > 0 {
|
||||
go rc.sendOneConsumeMemRequest(rest, consumptionTimeInSeconds)
|
||||
go rc.sendOneConsumeMemRequest(rest, rc.consumptionTimeInSeconds)
|
||||
}
|
||||
sleepTime = rc.sleepTime
|
||||
case <-rc.stopMem:
|
||||
return
|
||||
}
|
||||
|
@ -42,28 +42,28 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
|
||||
// CPU tests
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods (scale resource: CPU)", func() {
|
||||
rc = NewResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
||||
rc.WaitForReplicas(3)
|
||||
rc.CleanUp()
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod (scale resource: CPU)", func() {
|
||||
rc = NewResourceConsumer("rc", 3, 0, 0, 100, 100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 3, 0, 0, 100, 100, f)
|
||||
createCPUHorizontalPodAutoscaler(rc, "0.7")
|
||||
rc.WaitForReplicas(1)
|
||||
rc.CleanUp()
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to maximum 5 pods (scale resource: CPU)", func() {
|
||||
rc = NewResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||
createCPUHorizontalPodAutoscaler(rc, "0.1")
|
||||
rc.WaitForReplicas(5)
|
||||
rc.CleanUp()
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 1 (scale resource: CPU)", func() {
|
||||
rc = NewResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
||||
rc.WaitForReplicas(3)
|
||||
rc.ConsumeCPU(300)
|
||||
@ -72,7 +72,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 5 (scale resource: CPU)", func() {
|
||||
rc = NewResourceConsumer("rc", 1, 300, 0, 400, 100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 1, 300, 0, 400, 100, f)
|
||||
createCPUHorizontalPodAutoscaler(rc, "0.1")
|
||||
rc.WaitForReplicas(3)
|
||||
rc.ConsumeCPU(700)
|
||||
@ -81,7 +81,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod and from 1 to 3 (scale resource: CPU)", func() {
|
||||
rc = NewResourceConsumer("rc", 3, 0, 0, 800, 100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 3, 0, 0, 800, 100, f)
|
||||
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
||||
rc.WaitForReplicas(1)
|
||||
rc.ConsumeCPU(700)
|
||||
@ -90,7 +90,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 5 pods to 3 pods and from 3 to 1 (scale resource: CPU)", func() {
|
||||
rc = NewResourceConsumer("rc", 5, 700, 0, 200, 100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 5, 700, 0, 200, 100, f)
|
||||
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
||||
rc.WaitForReplicas(3)
|
||||
rc.ConsumeCPU(100)
|
||||
@ -100,28 +100,28 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
|
||||
// Memory tests
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods (scale resource: Memory)", func() {
|
||||
rc = NewResourceConsumer("rc", 1, 0, 800, 100, 900, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 1, 0, 800, 100, 900, f)
|
||||
createMemoryHorizontalPodAutoscaler(rc, "300")
|
||||
rc.WaitForReplicas(3)
|
||||
rc.CleanUp()
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod (scale resource: Memory)", func() {
|
||||
rc = NewResourceConsumer("rc", 3, 0, 0, 100, 100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 3, 0, 0, 100, 100, f)
|
||||
createMemoryHorizontalPodAutoscaler(rc, "700")
|
||||
rc.WaitForReplicas(1)
|
||||
rc.CleanUp()
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to maximum 5 pods (scale resource: Memory)", func() {
|
||||
rc = NewResourceConsumer("rc", 1, 0, 700, 100, 800, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 1, 0, 700, 100, 800, f)
|
||||
createMemoryHorizontalPodAutoscaler(rc, "100")
|
||||
rc.WaitForReplicas(5)
|
||||
rc.CleanUp()
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 1 (scale resource: Memory)", func() {
|
||||
rc = NewResourceConsumer("rc", 1, 0, 700, 100, 800, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 1, 0, 700, 100, 800, f)
|
||||
createMemoryHorizontalPodAutoscaler(rc, "300")
|
||||
rc.WaitForReplicas(3)
|
||||
rc.ConsumeMem(100)
|
||||
@ -130,7 +130,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 5 (scale resource: Memory)", func() {
|
||||
rc = NewResourceConsumer("rc", 1, 0, 500, 100, 1100, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 1, 0, 500, 100, 1100, f)
|
||||
createMemoryHorizontalPodAutoscaler(rc, "200")
|
||||
rc.WaitForReplicas(3)
|
||||
rc.ConsumeMem(1000)
|
||||
@ -139,7 +139,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
})
|
||||
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod and from 1 to 3 (scale resource: Memory)", func() {
|
||||
rc = NewResourceConsumer("rc", 3, 0, 0, 100, 800, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 3, 0, 0, 100, 800, f)
|
||||
createMemoryHorizontalPodAutoscaler(rc, "300")
|
||||
rc.WaitForReplicas(1)
|
||||
rc.ConsumeMem(700)
|
||||
@ -147,7 +147,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
rc.CleanUp()
|
||||
})
|
||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 5 pods to 3 pods and from 3 to 1 (scale resource: Memory)", func() {
|
||||
rc = NewResourceConsumer("rc", 5, 0, 700, 100, 800, f)
|
||||
rc = NewDynamicResourceConsumer("rc", 5, 0, 700, 100, 800, f)
|
||||
createMemoryHorizontalPodAutoscaler(rc, "300")
|
||||
rc.WaitForReplicas(3)
|
||||
rc.ConsumeMem(100)
|
||||
|
Loading…
Reference in New Issue
Block a user