Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial scale kept for first minute of experiment #261

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/driver/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export FUNC_NAME=$2
export CPU_REQUEST=$3
export CPU_LIMITS=$4
export MEMORY_REQUESTS=$5
INIT_SCALE=$6
export INIT_SCALE=$6
export MIN_SCALE=$6 # minimum scale is the same as initial scale during profiling

export PANIC_WINDOW=$7
export PANIC_THRESHOLD=$8

export AUTOSCALING_METRIC=$9
export AUTOSCALING_TARGET=${10}

cat $CONFIG_FILE | envsubst | kn service apply $FUNC_NAME --scale-init $INIT_SCALE --concurrency-target 1 --wait-timeout 2000000 -f /dev/stdin
cat $CONFIG_FILE | envsubst | kn service apply $FUNC_NAME --concurrency-target 1 --wait-timeout 2000000 -f /dev/stdin
36 changes: 35 additions & 1 deletion pkg/driver/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func DeployFunctionsKnative(functions []*common.Function, yamlPath string, isPar

func deployOne(function *common.Function, yamlPath string, isPartiallyPanic bool, endpointPort int,
autoscalingMetric string) bool {

panicWindow := "\"10.0\""
panicThreshold := "\"200.0\""
if isPartiallyPanic {
Expand All @@ -77,7 +78,7 @@ func deployOne(function *common.Function, yamlPath string, isPartiallyPanic bool
strconv.Itoa(function.CPURequestsMilli)+"m",
strconv.Itoa(function.CPULimitsMilli)+"m",
strconv.Itoa(function.MemoryRequestsMiB)+"Mi",
strconv.Itoa(function.InitialScale),
"\""+strconv.Itoa(function.InitialScale)+"\"",

panicWindow,
panicThreshold,
Expand Down Expand Up @@ -111,6 +112,39 @@ func deployOne(function *common.Function, yamlPath string, isPartiallyPanic bool
return true
}

func UpdateFunctionKnative(function *common.Function, endpointPort int) bool {

cmd := exec.Command(
"bash",
"./pkg/driver/update_deployment.sh",
function.Name,
)

stdoutStderr, err := cmd.CombinedOutput()
log.Debug("CMD response: ", string(stdoutStderr))

if err != nil {
// TODO: there should be a toggle to turn off deployment because if this is fatal then we cannot test the thing locally
log.Warnf("Failed to update deployment of function %s: %v\n%s\n", function.Name, err, stdoutStderr)

return false
}

if endpoint := urlRegex.FindStringSubmatch(string(stdoutStderr))[1]; endpoint != function.Endpoint {
// TODO: check when this situation happens
log.Debugf("Update function endpoint to %s\n", endpoint)
function.Endpoint = endpoint
} else {
function.Endpoint = fmt.Sprintf("%s.%s.%s", function.Name, namespace, bareMetalLbGateway)
}

// adding port to the endpoint
function.Endpoint = fmt.Sprintf("%s:%d", function.Endpoint, endpointPort)

log.Debugf("Updated deployment of function on %s\n", function.Endpoint)
return true
}

func CleanKnative() {
cmd := exec.Command("kn", "service", "delete", "--all")
var out bytes.Buffer
Expand Down
11 changes: 8 additions & 3 deletions pkg/driver/trace_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,9 @@ func (d *Driver) individualFunctionDriver(function *common.Function, announceFun

if d.Configuration.WithWarmup() {
currentPhase = common.WarmupPhase
// skip the first minute because of profiling
minuteIndex = 1
minuteIndex = 0

log.Infof("Warmup phase has started.")
log.Info("Profiling phase for 1 minute, no downscaling below initial scale.")
}

startOfMinute := time.Now()
Expand Down Expand Up @@ -374,6 +373,12 @@ func (d *Driver) proceedToNextMinute(function *common.Function, minuteIndex *int
*invocationIndex = 0
*previousIATSum = 0

if d.Configuration.WithWarmup() && *minuteIndex == 1 {
log.Info("profiling phase is done, updating deployments to allow downscaling below initial scale.")
if d.Configuration.LoaderConfiguration.Platform == "Knative" {
UpdateFunctionKnative(function, d.Configuration.LoaderConfiguration.EndpointPort)
}
}
if d.Configuration.WithWarmup() && *minuteIndex == (d.Configuration.LoaderConfiguration.WarmupDuration+1) {
*currentPhase = common.ExecutionPhase
log.Infof("Warmup phase has finished. Starting the execution phase.")
Expand Down
6 changes: 3 additions & 3 deletions pkg/driver/trace_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ func TestDriverCompletely(t *testing.T) {
record := records[i]

if test.withWarmup {
if i < 5 && record.Phase != int(common.WarmupPhase) {
if i < 10 && record.Phase != int(common.WarmupPhase) {
t.Error("Invalid record phase in warmup.")
} else if i > 5 && record.Phase != int(common.ExecutionPhase) {
} else if i >= 10 && record.Phase != int(common.ExecutionPhase) {
t.Error("Invalid record phase in execution phase.")
}
}
Expand All @@ -342,7 +342,7 @@ func TestDriverCompletely(t *testing.T) {

expectedInvocations := 5
if test.withWarmup {
expectedInvocations = 10
expectedInvocations = 15
}

if !(successfulInvocation == expectedInvocations && failedInvocations == 0) {
Expand Down
29 changes: 29 additions & 0 deletions pkg/driver/update_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

#
# MIT License
#
# Copyright (c) 2023 EASL and the vHive community
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

export FUNC_NAME=$1

kn service update $FUNC_NAME --scale-min 0 --scale-init 0
24 changes: 23 additions & 1 deletion pkg/trace/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
package trace

import (
"math"

log "github.com/sirupsen/logrus"
"github.com/vhive-serverless/loader/pkg/common"
"math"
)

func DoStaticTraceProfiling(functions []*common.Function) {
Expand All @@ -43,6 +44,7 @@ func ApplyResourceLimits(functions []*common.Function) {
for i := 0; i < len(functions); i++ {
memoryPct100 := int(functions[i].MemoryStats.Percentile100)
cpuShare := ConvertMemoryToCpu(memoryPct100)
// cpuShare := ConvertExecutionTimeToCpu(functions[i])

functions[i].CPURequestsMilli = cpuShare / common.OvercommitmentRatio
functions[i].MemoryRequestsMiB = memoryPct100 / common.OvercommitmentRatio
Expand Down Expand Up @@ -71,6 +73,26 @@ func ConvertMemoryToCpu(memoryRequest int) int {
return int(cpuRequest * 1000)
}

func ConvertExecutionTimeToCpu(function *common.Function) int {
var cpuRequest float32
switch executionTime := function.RuntimeStats.Average; {
case executionTime < 100:
cpuRequest = 1
case executionTime < 200:
cpuRequest = 0.9
case executionTime < 300:
cpuRequest = 0.8
case executionTime < 400:
cpuRequest = 0.7
case executionTime < 500:
cpuRequest = 0.6
default:
cpuRequest = 0.5
}

return int(cpuRequest * 1000)
}

func profileConcurrency(function *common.Function) float64 {
IPM := function.InvocationStats.Invocations[0]

Expand Down
4 changes: 2 additions & 2 deletions workloads/container/trace_func_go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ spec:
template:
metadata:
annotations:
autoscaling.knative.dev/initial-scale: "0" # Should start from 0, otherwise we can't deploy more functions than the node physically permits.
autoscaling.knative.dev/min-scale: "0" # This parameter only has a per-revision key, so it's necessary to have here in case of the warmup messes up.
autoscaling.knative.dev/initial-scale: $INIT_SCALE # Should start from 0, otherwise we can't deploy more functions than the node physically permits.
autoscaling.knative.dev/min-scale: $MIN_SCALE # This parameter only has a per-revision key, so it's necessary to have here in case of the warmup messes up.
autoscaling.knative.dev/target-utilization-percentage: "100" # Enforce container concurrency at any time.
autoscaling.knative.dev/target-burst-capacity: "-1" # Put activator always in the path explicitly.
autoscaling.knative.dev/max-scale: "200" # Maximum instances limit of Azure.
Expand Down