Add automation for ADML HTTP image creation
[anna.git] / example / diameter / launcher / resources / scripts / operation_tps.sh
1 #!/bin/bash
2    echo "     sendXS <requests per second> [amount: default -1 (no limit)]:"
3    echo "        send messages from burst list with the TPS provided. User could hot change"
4    echo "        speed by mean 'echo <TPS> > .tps' at another shell. You can stop the load"
5    echo "        removing that hidden file or using CTRL+C from the shell where you launched"
6    echo "        the burst command. Real tps is dumped on '.real_tps' file during testing."
7    echo "        You could limit the amount of messages sent by mean the second parameter."
8    echo "        No limit is established by default (-1 or negative value)."
9 > curl_log.txt
10 TRACE="--trace-ascii curl_log.txt"
11 SERVER=`cat .httpServer`
12
13 use () {
14
15    echo "Use: $0 <xml_file> [2c]"
16    echo
17    echo "Sends 'xml_file' to the diameter server or to the client when '2c' parameter is provided."
18    echo
19    exit
20 }
21
22    sendXS) [[ "$2" = "" ]] && uso
23          limit=$3
24          [[ "$limit" = "" ]] && limit=-1
25          entero $2
26          entero $limit
27          TPS=0
28          count=0
29          amount=1
30          echo $2 > .tps
31          while test -f .tps
32          do
33             [[ "$count" = "$limit" ]] && break
34             BEFORE_ns=`date +%s%N`
35             READ_TPS=`cat .tps`
36             # Hot change could make .tps still unavailable:
37             [[ "$READ_TPS" = "" ]] && READ_TPS=$TPS
38             # Volvemos a calcular medias (REAL_TPS) cada 10 segundos o cuando cambia el TPS en caliente:
39             [[ "$READ_TPS" != "$TPS" ]] && { BEGIN_ns=$BEFORE_ns ; count=0 ; }
40             [[ $count = $((10*TPS)) ]] && { BEGIN_ns=$BEFORE_ns ; count=0 ; }
41             TPS=$READ_TPS
42             [[ "$TPS" = "0" ]] && salir "Test stopped due to 0-tps value read"
43             # Background:
44             _curl "burst|send|$amount" &
45             count=$((count+amount))
46             AFTER_ns=`date +%s%N`
47             # Real tps:
48             REAL_TPS=$(calc "1000000000 * $count / ($AFTER_ns - $BEGIN_ns)")
49             echo $REAL_TPS > .real_tps
50             
51             COEF=1
52             [[ $(calc "$TPS > $REAL_TPS") = "1" ]] && COEF=$(calc "$REAL_TPS / $TPS")
53             K=$(calc "$COEF ^ 10")
54             amount=$(calc "scale=0;1/$K")
55             usleep $(calc "$K * 1000000/$TPS")
56          done
57    ;;
58 echo
59 [[ "$1" = "" ]] && use
60 [[ ! -f "$1" ]] && { echo "ERROR: file '$1' not found" ; echo; echo; exit ; }
61 echo
62 operation="sendxml2e|$1"
63 [[ "$2" = "2c" ]] && operation="sendxml2c|$1"
64
65 curl -m 1 --data "$operation" $TRACE ${SERVER}
66