From 0a0f33855c2e24a0f1d7e45ccfe4895e0fde6e46 Mon Sep 17 00:00:00 2001 From: trevor tao Date: Tue, 12 Jul 2022 22:32:59 +0800 Subject: [PATCH] Add a service access latency measurement tool Signed-off-by: trevor tao Change-Id: I98be0549ebf8a8e1ca49fefb22f48dc681d2014e --- src/tools/test_service_latency.sh | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 src/tools/test_service_latency.sh diff --git a/src/tools/test_service_latency.sh b/src/tools/test_service_latency.sh new file mode 100755 index 0000000..c72c744 --- /dev/null +++ b/src/tools/test_service_latency.sh @@ -0,0 +1,71 @@ +set -e + +localIP=$(ip route show default | cut -d " " -f 9) +echo "localIP:"$localIP + +if [ "x${1}" == "x" ]; then +echo "No node IP defined, uses the local IP instead." +fi + +nodeIP=$localIP +aNum=1000 + + +display_help () { + echo "Usage:" + echo " " + echo "Please input the nodeIP and access number" +} + +ARGS=`getopt -a -o s:n:h -l nodeIP:,number:,help -- "$@"` +eval set -- "${ARGS}" +while true +do + case "$1" in + -s|--nodeIP) + nodeIP="$2" + echo "nodeIP=$2" + shift + ;; + -n|--number) + aNum="$2" + echo "access number=$2" + shift + ;; + -h|--help) + echo "this is help case" + display_help + ;; + --) + echo "Now do the test:" + shift + break + ;; + esac +shift +done + + +svcIP=$(kubectl get svc | grep nginx |grep -i "nodeport" | awk -F'[ ]+' '{print $3}') +echo "Service IP:"$svcIP +nodePort=$(kubectl get svc | grep nginx |grep -i "nodeport" | awk -F'[ ]+' '{print $5}' | cut -d ":" -f 2 |cut -d "/" -f 1) +echo "NodePort:"$nodePort + +accessNum=$((aNum + 0)) +echo "Now access the service IP, $aNum times:" +#for i in {1..$(($aNum + 0))} +START=1 +END=$aNum + +for (( c=$START; c<=$END; c++)) +do + curl -w "%{time_total}\n" -o /dev/null -s http://$svcIP +done | jq -s add/length + +echo "Now access the NodePort, $aNum times" +for (( c=$START; c<=$END; c++)) +do + #curl -w "%{time_total}\n" -o /dev/null -s http://10.169.210.208:31942 + #curl -w "%{time_total}\n" -o /dev/null -s http://10.169.210.208:31942 + curl -w "%{time_total}\n" -o /dev/null -s $localIP:$nodePort +done | jq -s add/length -- 2.16.6