diff --git a/metrics/lib/common.bash b/metrics/lib/common.bash index 5fb8768..6de63b9 100755 --- a/metrics/lib/common.bash +++ b/metrics/lib/common.bash @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (c) 2017,2018 Intel Corporation +# Copyright (c) 2017,2018,2019 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 @@ -11,7 +11,6 @@ RESULT_DIR="${LIB_DIR}/../results" source ${LIB_DIR}/kata-common.bash source ${LIB_DIR}/json.bash source /etc/os-release || source /usr/lib/os-release -KATA_KSM_THROTTLER="${KATA_KSM_THROTTLER:-no}" # Set variables to reasonable defaults if unset or empty DOCKER_EXE="${DOCKER_EXE:-docker}" @@ -27,26 +26,6 @@ KSM_SLEEP_FILE="${KSM_BASE}/sleep_millisecs" KSM_AGGRESIVE_PAGES=1000 KSM_AGGRESIVE_SLEEP=50 -# If we fail for any reason, exit through here and we should log that to the correct -# place and return the correct code to halt the run -die(){ - msg="$*" - echo "ERROR: $msg" >&2 - exit 1 -} - -# Sometimes we just want to warn about something - let's have a standard -# method for that, so maybe we can make a standard form that can be searched -# for in the logs/tooling -warning(){ - msg="$*" - echo "WARNING: $msg" >&2 -} - -info() { - echo -e "INFO: $*" -} - # This function checks existence of commands. # They can be received standalone or as an array, e.g. # @@ -207,14 +186,6 @@ show_system_state() { echo " --pgrep ${p}--" pgrep -a ${p} done - - # Verify kata-ksm-throttler - if [ "$KATA_KSM_THROTTLER" == "yes" ]; then - process="kata-ksm-throttler" - process_path=$(whereis ${process} | tr -d '[:space:]'| cut -d ':' -f2) - echo " --pgrep ${process}--" - pgrep -f ${process_path} > /dev/null - fi } common_init(){ diff --git a/metrics/lib/json.bash b/metrics/lib/json.bash index 67ca04a..692fed1 100644 --- a/metrics/lib/json.bash +++ b/metrics/lib/json.bash @@ -9,21 +9,6 @@ declare -a json_result_array declare -a json_array_array -# Generate a timestamp in nanoseconds since 1st Jan 1970 -timestamp_ns() { - local t - local s - local n - local ns - - t="$(date +%-s:%-N)" - s=$(echo $t | awk -F ':' '{print $1}') - n=$(echo $t | awk -F ':' '{print $2}') - ns=$(( (s * 1000000000) + n )) - - echo $ns -} - # Generate a timestamp in milliseconds since 1st Jan 1970 timestamp_ms() { echo $(($(date +%s%N)/1000000)) @@ -67,7 +52,7 @@ EOF local json="$(cat << EOF "date" : { - "ns": $(timestamp_ns), + "ns": $(date +%s%N), "Date": "$(date -u +"%Y-%m-%dT%T.%3N")" } EOF diff --git a/metrics/scaling/bb.yaml.in b/metrics/scaling/bb.yaml.in index 4b507bd..87d8af4 100644 --- a/metrics/scaling/bb.yaml.in +++ b/metrics/scaling/bb.yaml.in @@ -1,3 +1,7 @@ +# Copyright (c) 2017,2018,2019 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + apiVersion: apps/v1 # We use a deployment rather than a pod directly specifically so we can use it to # generate more replicas by re-deploying it. diff --git a/metrics/scaling/k8s_scale.sh b/metrics/scaling/k8s_scale.sh index 7ca1d64..3d2fd32 100755 --- a/metrics/scaling/k8s_scale.sh +++ b/metrics/scaling/k8s_scale.sh @@ -10,8 +10,8 @@ set -e SCRIPT_PATH=$(dirname "$(readlink -f "$0")") source "${SCRIPT_PATH}/../lib/common.bash" -input_yaml="bb.yaml.in" -generated_yaml="generated.yaml" +input_yaml="${SCRIPT_PATH}/bb.yaml.in" +generated_yaml="${SCRIPT_PATH}/generated.yaml" deployment="busybox" stats_pod="stats" @@ -41,7 +41,7 @@ get_num_nodes() { # $1 is the launch time in seconds this pod/container took to start up. # $2 is the number of pod/containers under test grab_stats() { - local launch_time=$1 + local launch_time_ms=$1 local n_pods=$2 info "And grab some stats" # Tell mpstat to measure over a short period, not only so we get slightly de-noised data, but also @@ -67,8 +67,8 @@ grab_stats() { "Units" : "%" }, "launch_time": { - "Result": $launch_time, - "Units" : "s" + "Result": $launch_time_ms, + "Units" : "ms" }, "mem_free": { "Result": ${mem_free}, @@ -98,7 +98,7 @@ init() { # kubelet config - from 'kubectl describe node -o json' ? # Launch our stats gathering pod - kubectl apply -f ${stats_pod}.yaml + kubectl apply -f ${SCRIPT_PATH}/${stats_pod}.yaml kubectl wait --for=condition=Ready pod "${stats_pod}" # FIXME - we should probably 'warm up' the cluster with the container image(s) we will @@ -138,36 +138,31 @@ run() { info "Testing replicas ${reqs} of ${NUM_PODS}" # Generate the next yaml file + local runtime_command if [ "$use_kata_runtime" != "no" ]; then - sed -e "s|@REPLICAS@|${reqs}|g" \ - -e "s|@RUNTIMECLASS@|${RUNTIME}|g" \ - -e "s|@DEPLOYMENT@|${deployment}|g" \ - -e "s|@LABEL@|${LABEL}|g" \ - -e "s|@LABELVALUE@|${LABELVALUE}|g" \ - < ${input_yaml} > ${generated_yaml} - else - sed -e "s|@REPLICAS@|${reqs}|g" \ - -e "/@RUNTIMECLASS@/d" \ - -e "s|@DEPLOYMENT@|${deployment}|g" \ - -e "s|@LABEL@|${LABEL}|g" \ - -e "s|@LABELVALUE@|${LABELVALUE}|g" \ - < ${input_yaml} > ${generated_yaml} - fi + runtime_command="s|@RUNTIMECLASS@|${RUNTIME}|g" + else + runtime_command="/@RUNTIMECLASS@/d" + fi + + sed -e "s|@REPLICAS@|${reqs}|g" \ + -e $runtime_command \ + -e "s|@DEPLOYMENT@|${deployment}|g" \ + -e "s|@LABEL@|${LABEL}|g" \ + -e "s|@LABELVALUE@|${LABELVALUE}|g" \ + < ${input_yaml} > ${generated_yaml} info "Applying changes" - # FIXME - time taken in 'seconds' - we can do better than that, if we - # use the date nanosecond stamp, and steal the magic from the density test script. - # switch to 'date +%N' - local start_time=$(date +%s) + local start_time=$(date +%s%N) kubectl apply -f ${generated_yaml} #cmd="kubectl get pods | grep busybox | grep Completed" kubectl rollout status --timeout=${wait_time}s deployment/${deployment} - local end_time=$(date +%s) - local total_seconds=$(( end_time - start_time )) - info "Took $total_seconds ($end_time - $start_time)" + local end_time=$(date +%s%N) + local total_milliseconds=$(( (end_time - start_time) / 1000000 )) + info "Took $total_milliseconds ms ($end_time - $start_time)" sleep ${settle_time} - grab_stats $total_seconds $reqs + grab_stats $total_milliseconds $reqs done } @@ -178,7 +173,7 @@ cleanup() { metrics_json_end_array "BootResults" kubectl delete pod --wait=true --timeout=${delete_wait_time}s "${stats_pod}" || true - local start_time=$(date +%s) + local start_time=$(date +%s%N) kubectl delete deployment --wait=true --timeout=${delete_wait_time}s "${deployment}" || true for x in $(seq 1 ${delete_wait_time}); do local npods=$(kubectl get pods -l=${LABEL}=${LABELVALUE} -o=name | wc -l) @@ -189,17 +184,17 @@ cleanup() { fi sleep 1 done - local end_time=$(date +%s) - local total_seconds=$(( end_time - start_time )) + local end_time=$(date +%s%N) + local total_milliseconds=$(( (end_time - start_time) / 1000000 )) if [ -z "$alldied" ]; then echo "ERROR: Not all pods died!" fi - info "Delete Took $total_seconds ($end_time - $start_time)" + info "Delete Took $total_milliseconds ms ($end_time - $start_time)" local json="$(cat << EOF "Delete": { - "Result": ${total_seconds}, - "Units" : "s" + "Result": ${total_milliseconds}, + "Units" : "ms" } EOF )" @@ -225,8 +220,8 @@ show_vars() echo -e "\t\tSeconds to wait for all pods to be deleted" echo -e "\tsettle_time (${settle_time})" echo -e "\t\tSeconds to wait after pods ready before taking measurements" - echo -e "\tuse_kata_runtime (${use_kata_runtime})" - echo -e "\t\tspecify yes or no to use kata runtime" + echo -e "\tuse_kata_runtime (${use_kata_runtime})" + echo -e "\t\tspecify yes or no to use kata runtime" } help()