Multistack launcher
[anna.git] / example / diameter / launcher / resources / scripts / operation_tps.sh
diff --git a/example/diameter/launcher/resources/scripts/operation_tps.sh b/example/diameter/launcher/resources/scripts/operation_tps.sh
new file mode 100755 (executable)
index 0000000..29f41eb
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/bash
+   echo "     sendXS <requests per second> [amount: default -1 (no limit)]:"
+   echo "        send messages from burst list with the TPS provided. User could hot change"
+   echo "        speed by mean 'echo <TPS> > .tps' at another shell. You can stop the load"
+   echo "        removing that hidden file or using CTRL+C from the shell where you launched"
+   echo "        the burst command. Real tps is dumped on '.real_tps' file during testing."
+   echo "        You could limit the amount of messages sent by mean the second parameter."
+   echo "        No limit is established by default (-1 or negative value)."
+> curl_log.txt
+TRACE="--trace-ascii curl_log.txt"
+SERVER=`cat .httpServer`
+
+use () {
+
+   echo "Use: $0 <xml_file> [2c]"
+   echo
+   echo "Sends 'xml_file' to the diameter server or to the client when '2c' parameter is provided."
+   echo
+   exit
+}
+
+   sendXS) [[ "$2" = "" ]] && uso
+         limit=$3
+         [[ "$limit" = "" ]] && limit=-1
+         entero $2
+         entero $limit
+         TPS=0
+         count=0
+         amount=1
+         echo $2 > .tps
+         while test -f .tps
+         do
+            [[ "$count" = "$limit" ]] && break
+            BEFORE_ns=`date +%s%N`
+            READ_TPS=`cat .tps`
+            # Hot change could make .tps still unavailable:
+            [[ "$READ_TPS" = "" ]] && READ_TPS=$TPS
+            # Volvemos a calcular medias (REAL_TPS) cada 10 segundos o cuando cambia el TPS en caliente:
+            [[ "$READ_TPS" != "$TPS" ]] && { BEGIN_ns=$BEFORE_ns ; count=0 ; }
+            [[ $count = $((10*TPS)) ]] && { BEGIN_ns=$BEFORE_ns ; count=0 ; }
+            TPS=$READ_TPS
+            [[ "$TPS" = "0" ]] && salir "Test stopped due to 0-tps value read"
+            # Background:
+            _curl "burst|send|$amount" &
+            count=$((count+amount))
+            AFTER_ns=`date +%s%N`
+            # Real tps:
+            REAL_TPS=$(calc "1000000000 * $count / ($AFTER_ns - $BEGIN_ns)")
+            echo $REAL_TPS > .real_tps
+            
+            COEF=1
+            [[ $(calc "$TPS > $REAL_TPS") = "1" ]] && COEF=$(calc "$REAL_TPS / $TPS")
+            K=$(calc "$COEF ^ 10")
+            amount=$(calc "scale=0;1/$K")
+            usleep $(calc "$K * 1000000/$TPS")
+         done
+   ;;
+echo
+[[ "$1" = "" ]] && use
+[[ ! -f "$1" ]] && { echo "ERROR: file '$1' not found" ; echo; echo; exit ; }
+echo
+operation="sendxml|$1"
+[[ "$2" = "2c" ]] && operation="sendxml2c|$1"
+
+curl -m 1 --data "$operation" $TRACE ${SERVER}
+