summaryrefslogtreecommitdiff
path: root/qpid/java/tools/bin/controller
blob: fab86140397ee94a2624fcab04b4f0a25009444e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

# This starts the controller for coordinating perf tests/

. check-qpid-java-env

PROGRAM_NAME=controller
CONSUMER_COUNT=1
PRODUCER_COUNT=1
DURATION=-1
TEST_NAME="TEST_NAME"
EXTRA_JVM_ARGS=""

TEMP=$(getopt -n $PROGRAM_NAME -o c:p:d:n:a:h --long consumers:,producers:,jvm-args:help -- "$@")                                                            

usage()
{
  printf "\n%s\n" "Usage: controller [option].."

  printf "\n%31s\n%52s\n"  "-c, --consumer-count=count" "No of consumers participating in the test"

  printf "\n%31s\n%52s\n"  "-p, --producer-count=count" "No of producers participating in the test"

  printf "\n%24s\n%94s\n"  "-d, --duration=mins" "The duration of the test in mins. If not specified, it will just run one iteration."

  printf "\n%27s\n%32s\n"  "-n, --name=<test-name>" "The name of the test."

  printf "\n%19s\n%50s\n"  "-a, --jvm-args" "Extra jvm arguments you want to specify"
}

eval set -- "$TEMP"
while true; do     
        case $1 in 
                -c|--consumer-count)
                        CONSUMER_COUNT="$2"; shift; shift; continue
                ;;                                    
                -p|--producer-count)                            
                        PRODUCER_COUNT="$2"; shift; shift; continue  
                ;;                                 
                -d|--duration)
                        DURATION="$2"; shift; shift; continue
                ;;
                -n|--name)
                        TEST_NAME="$2"; shift; shift; continue
                ;;
                -h|--help)                            
                        usage                         
                        exit 0                        
                ;;                                    
                -a|--jvm-args)               
                        EXTRA_JVM_ARGS="$2"; shift; shift; continue 
                ;;                                                                  
                --)                                                                 
                        # no more arguments to parse                                
                        break                                                       
                ;;                                                                  
                *)       
                        # no more arguments to parse                                                                                            
                        break                                                      
                ;;                                                                  
        esac                                                                        
done     

CONTROLLER_ARGS="-server -Durl=amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5672' -Dprecision=mili -Dprod_count=$PRODUCER_COUNT -Dcons_count=$CONSUMER_COUNT -Dprint_std_dev=true -Dduration=${DURATION}"


waitfor() { until grep -a -l "$2" $1 >/dev/null 2>&1 ; do sleep 1 ; done ; }
cleanup()
{
  pids=`ps aux | grep java | grep PerfTestController | awk '{print $2}'`
  if [ "$pids" != "" ]; then
    kill -3 $pids
    kill -9 $pids >/dev/null 2>&1
  fi
}

run_controller()
{
  TEST_ARGS="$LOG_CONFIG $JAVA_MEM $CONTROLLER_ARGS $EXTRA_JVM_ARGS"
  echo "Running controller with : $TEST_ARGS" > test.out
  $JAVA -cp $CLASSPATH $TEST_ARGS org.apache.qpid.tools.PerfTestController >> test.out &
  waitfor test.out "Controller: Completed the test"
  sleep 2 #give a grace period to shutdown
  print_result $TEST_NAME
}

print_result()
{
  prod_rate=`cat test.out | grep "Avg Producer rate" | awk '{print $5}'`
  sys_rate=`cat test.out | grep "System Throughput" | awk '{print $4}'`
  cons_rate=`cat test.out | grep "Avg Consumer rate" | awk '{print $5}'` 
  avg_latency=`cat test.out | grep "Avg System Latency" | awk '{print $5}'`
  min_latency=`cat test.out | grep "Min System Latency" | awk '{print $5}'`
  max_latency=`cat test.out | grep "Max System Latency" | awk '{print $5}'`
  std_dev=`cat test.out | grep "Avg System Std Dev" | awk '{print $6}'`

  printf "|%-15s|%15.2f|%13.2f|%13.2f|%11.2f|%11.2f|%11.2f|%7.2f|\n" $1 $sys_rate $prod_rate $cons_rate $avg_latency $min_latency $max_latency $std_dev
  echo "--------------------------------------------------------------------------------------------------------"
}

trap cleanup EXIT

rm -rf *.out

if [ "$DURATION" = -1  ]; then
   echo "Test report on " `date +%F`
   echo "========================================================================================================"
   echo "|Test           |System throuput|Producer rate|Consumer Rate|Avg Latency|Min Latency|Max Latency|Std Dev|"
   echo "--------------------------------------------------------------------------------------------------------"
else
   echo "Test in progress....Tail stats-csv.log to see results being printed for each iteration."
fi

run_controller