#!/bin/sh # Measure replica budgets, load saturation and a pool-size A/B using the same workload. set -eu cd "$(dirname "$0")/.." : "${KUBE_CONTEXT:=dev}" "${NAMESPACE:=highload-applications}" "${RELEASE:=lab2}" : "${DURATION:=30}" "${VUS:=32}" : "${EVIDENCE_DIR:=evidence/research-$(date -u +%Y%m%d%H%M%S)}" helm_apply_mode= if helm upgrade --help | rg -q -- '--server-side'; then helm_apply_mode=--server-side=false; fi export KUBE_CONTEXT NAMESPACE DURATION VUS EVIDENCE_DIR mkdir -p "$EVIDENCE_DIR" helm get values "$RELEASE" --kube-context "$KUBE_CONTEXT" -n "$NAMESPACE" -o yaml > "$EVIDENCE_DIR/restore-values.yaml" restore() { helm upgrade $helm_apply_mode "$RELEASE" charts/messenger --kube-context "$KUBE_CONTEXT" -n "$NAMESPACE" -f "$EVIDENCE_DIR/restore-values.yaml" --wait --wait-for-jobs --timeout 240s > "$EVIDENCE_DIR/restore.txt" 2>&1 } trap restore EXIT trap 'exit 130' INT trap 'exit 143' TERM helm upgrade $helm_apply_mode "$RELEASE" charts/messenger --kube-context "$KUBE_CONTEXT" -n "$NAMESPACE" --reuse-values --set autoscaling.enabled=false --wait --wait-for-jobs --timeout 240s > "$EVIDENCE_DIR/disable-hpa.txt" # Allow an already-running HPA reconciliation to finish before changing replicas. sleep 16 date -u '+%Y-%m-%dT%H:%M:%SZ' > "$EVIDENCE_DIR/date.txt" git rev-parse HEAD > "$EVIDENCE_DIR/base-revision.txt" shasum -a 256 student-tests/load/scaling.js charts/messenger/values.yaml internal/controller/http/fiber/errors.go > "$EVIDENCE_DIR/source.sha256" kubectl --context "$KUBE_CONTEXT" get nodes -o wide > "$EVIDENCE_DIR/nodes.txt" printf 'profile,run,replicas,cpu_millicores_per_replica,memory_mib_per_replica,pool,vus,duration\n' > "$EVIDENCE_DIR/profiles.csv" for profile in ${PROFILES:-fixed1 fixed2 fixed4 growing1 growing2 growing4 saturation8 saturation64 single32a single8b single32b}; do pool=8; vus=$VUS; probe_timeout=2; probe_failures=2 case "$profile" in fixed1) replicas=1; cpu=1000; memory=512 ;; fixed2) replicas=2; cpu=500; memory=256 ;; fixed4|growing4|pool8b) replicas=4; cpu=250; memory=128 ;; growing1) replicas=1; cpu=250; memory=128 ;; growing2) replicas=2; cpu=250; memory=128 ;; saturation8) replicas=1; cpu=1000; memory=512; vus=8 ;; saturation64) replicas=1; cpu=1000; memory=512; vus=64 ;; resource-low-a|resource-low-b) replicas=2; cpu=250; memory=128 ;; resource-high-a|resource-high-b) replicas=2; cpu=500; memory=256 ;; probe2a|probe2b) replicas=1; cpu=1000; memory=512 ;; probe5a|probe5b) replicas=1; cpu=1000; memory=512; probe_timeout=5; probe_failures=1 ;; single8a|single8b) replicas=1; cpu=1000; memory=512 ;; single32a|single32b) replicas=1; cpu=1000; memory=512; pool=32 ;; pool32a|pool32b) replicas=4; cpu=250; memory=128; pool=32 ;; *) echo "Unknown profile $profile" >&2; exit 2 ;; esac set -- if [ -n "${BENCHMARK_NODE:-}" ]; then set -- --set-json "api.nodeSelector={\"kubernetes.io/hostname\":\"$BENCHMARK_NODE\"}" fi run="$profile-$(date -u +%Y%m%d%H%M%S)" helm upgrade $helm_apply_mode "$RELEASE" charts/messenger --kube-context "$KUBE_CONTEXT" -n "$NAMESPACE" --reuse-values --set autoscaling.enabled=false --set "api.replicas=$replicas" --set "api.resources.requests.cpu=${cpu}m,api.resources.limits.cpu=${cpu}m,api.resources.requests.memory=${memory}Mi,api.resources.limits.memory=${memory}Mi" --set-string api.env.GOMEMLIMIT=80MiB --set-string "api.env.DEPENDENCY_POOL_SIZE=$pool" --set "api.readiness.timeoutSeconds=$probe_timeout,api.readiness.failureThreshold=$probe_failures" "$@" --wait --wait-for-jobs --timeout 240s > "$EVIDENCE_DIR/rollout-$profile.txt" # Let old admission leases expire after rolling replacement. sleep 31 printf '%s,%s,%s,%s,%s,%s,%s,%s\n' "$profile" "$run" "$replicas" "$cpu" "$memory" "$pool" "$vus" "$DURATION" >> "$EVIDENCE_DIR/profiles.csv" RUN="$run" VUS="$vus" scripts/run-load.sh done