Add a service access latency measurement tool 41/4941/1
authortrevor tao <trevor.tao@arm.com>
Tue, 12 Jul 2022 14:32:59 +0000 (22:32 +0800)
committertrevor tao <trevor.tao@arm.com>
Tue, 12 Jul 2022 14:32:59 +0000 (22:32 +0800)
Signed-off-by: trevor tao <trevor.tao@arm.com>
Change-Id: I98be0549ebf8a8e1ca49fefb22f48dc681d2014e

src/tools/test_service_latency.sh [new file with mode: 0755]

diff --git a/src/tools/test_service_latency.sh b/src/tools/test_service_latency.sh
new file mode 100755 (executable)
index 0000000..c72c744
--- /dev/null
@@ -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