c72c744fbb36764b35d75aab76f8e6ea418fefbe
[iec.git] / src / tools / test_service_latency.sh
1 set -e
2
3 localIP=$(ip route show default | cut -d " " -f 9)
4 echo "localIP:"$localIP
5
6 if [ "x${1}" == "x" ]; then
7 echo "No node IP defined, uses the local IP instead."
8 fi
9
10 nodeIP=$localIP
11 aNum=1000
12
13
14 display_help () {
15   echo "Usage:"
16   echo " "
17   echo "Please input the nodeIP and access number"
18 }
19
20 ARGS=`getopt -a -o s:n:h -l nodeIP:,number:,help -- "$@"`
21 eval set -- "${ARGS}"
22 while true
23 do
24         case "$1" in
25         -s|--nodeIP)
26                 nodeIP="$2"
27                 echo "nodeIP=$2"
28                 shift
29                 ;;
30         -n|--number)
31                 aNum="$2"
32                 echo "access number=$2"
33                 shift
34                 ;;
35         -h|--help)
36                 echo "this is help case"
37                 display_help
38                 ;;
39         --)
40                 echo "Now do the test:"
41                 shift
42                 break
43                 ;;
44         esac
45 shift
46 done
47
48
49 svcIP=$(kubectl get svc | grep nginx |grep -i "nodeport" | awk -F'[ ]+' '{print $3}')
50 echo "Service IP:"$svcIP
51 nodePort=$(kubectl get svc | grep nginx |grep -i "nodeport" | awk -F'[ ]+' '{print $5}' | cut -d ":" -f 2 |cut -d "/" -f 1)
52 echo "NodePort:"$nodePort
53
54 accessNum=$((aNum + 0))
55 echo "Now access the service IP, $aNum times:"
56 #for i in {1..$(($aNum + 0))} 
57 START=1
58 END=$aNum
59
60 for (( c=$START; c<=$END; c++))
61 do 
62     curl -w "%{time_total}\n" -o /dev/null -s http://$svcIP
63 done | jq -s add/length
64
65 echo "Now access the NodePort, $aNum times"
66 for (( c=$START; c<=$END; c++))
67 do
68     #curl -w "%{time_total}\n" -o /dev/null -s http://10.169.210.208:31942 
69     #curl -w "%{time_total}\n" -o /dev/null -s http://10.169.210.208:31942 
70     curl -w "%{time_total}\n" -o /dev/null -s $localIP:$nodePort
71 done | jq -s add/length