Skip to content

Commit

Permalink
Merge pull request kubernetes#13684 from derekwaynecarr/fix_typo_in_r…
Browse files Browse the repository at this point in the history
…esource_consumer

Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Sep 8, 2015
2 parents 12c0058 + b05c11e commit d612803
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions test/e2e/autoscaling_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type ResourceConsumer struct {
}

// NewResourceConsumer creates new ResourceConsumer
// cpu argument is in milicores
// cpu argument is in millicores
func NewResourceConsumer(name string, replicas int, cpu int, framework *Framework) *ResourceConsumer {
runServiceAndRCForResourceConsumer(framework.Client, framework.Namespace.Name, name, replicas)
rc := &ResourceConsumer{
Expand All @@ -69,8 +69,8 @@ func NewResourceConsumer(name string, replicas int, cpu int, framework *Framewor
}

// ConsumeCPU consumes given number of CPU
func (rc *ResourceConsumer) ConsumeCPU(milicores int) {
rc.channel <- milicores
func (rc *ResourceConsumer) ConsumeCPU(millicores int) {
rc.channel <- millicores
}

func (rc *ResourceConsumer) makeConsumeCPURequests() {
Expand All @@ -79,9 +79,9 @@ func (rc *ResourceConsumer) makeConsumeCPURequests() {
var rest int
for {
select {
case milicores := <-rc.channel:
count = milicores / requestSizeInMilicores
rest = milicores - count*requestSizeInMilicores
case millicores := <-rc.channel:
count = millicores / requestSizeInMilicores
rest = millicores - count*requestSizeInMilicores
case <-time.After(sleepTime):
if count > 0 {
rc.sendConsumeCPUrequests(count, requestSizeInMilicores, consumptionTimeInSeconds)
Expand All @@ -95,21 +95,21 @@ func (rc *ResourceConsumer) makeConsumeCPURequests() {
}
}

func (rc *ResourceConsumer) sendConsumeCPUrequests(requests, milicores, durationSec int) {
func (rc *ResourceConsumer) sendConsumeCPUrequests(requests, millicores, durationSec int) {
for i := 0; i < requests; i++ {
go rc.sendOneConsumeCPUrequest(milicores, durationSec)
go rc.sendOneConsumeCPUrequest(millicores, durationSec)
}
}

// sendOneConsumeCPUrequest sends POST request for cpu consumption
func (rc *ResourceConsumer) sendOneConsumeCPUrequest(milicores int, durationSec int) {
func (rc *ResourceConsumer) sendOneConsumeCPUrequest(millicores int, durationSec int) {
_, err := rc.framework.Client.Post().
Prefix("proxy").
Namespace(rc.framework.Namespace.Name).
Resource("services").
Name(rc.name).
Suffix("ConsumeCPU").
Param("milicores", strconv.Itoa(milicores)).
Param("millicores", strconv.Itoa(millicores)).
Param("durationSec", strconv.Itoa(durationSec)).
Do().
Raw()
Expand Down
8 changes: 4 additions & 4 deletions test/images/resource-consumer/consume-cpu/consume_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ func doSomething() {
}

var (
milicores = flag.Int("milicores", 0, "milicores number")
millicores = flag.Int("millicores", 0, "millicores number")
durationSec = flag.Int("duration-sec", 0, "duration time in seconds")
)

func main() {
flag.Parse()
// converte milicores to percentage
milicoresPct := float64(*milicores) / float64(10)
// convert millicores to percentage
millicoresPct := float64(*millicores) / float64(10)
duration := time.Duration(*durationSec) * time.Second
start := time.Now()
first := systemstat.GetProcCPUSample()
for time.Now().Sub(start) < duration {
cpu := systemstat.GetProcCPUAverage(first, systemstat.GetProcCPUSample(), systemstat.GetUptime().Uptime)
if cpu.TotalPct < milicoresPct {
if cpu.TotalPct < millicoresPct {
doSomething()
} else {
time.Sleep(sleep)
Expand Down
6 changes: 3 additions & 3 deletions test/images/resource-consumer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (

const consumeCPUBinary = "./consume-cpu/consume-cpu"

func ConsumeCPU(milicores int, durationSec int) {
log.Printf("ConsumeCPU milicores: %v, durationSec: %v", milicores, durationSec)
func ConsumeCPU(millicores int, durationSec int) {
log.Printf("ConsumeCPU millicores: %v, durationSec: %v", millicores, durationSec)
// creating new consume cpu process
arg1 := fmt.Sprintf("-milicores=%d", milicores)
arg1 := fmt.Sprintf("-millicores=%d", millicores)
arg2 := fmt.Sprintf("-duration-sec=%d", durationSec)
consumeCPU := exec.Command(consumeCPUBinary, arg1, arg2)
consumeCPU.Start()
Expand Down

0 comments on commit d612803

Please sign in to comment.