| 1 |
#!/bin/bash |
| 2 |
# Simple script to time running the examples in various languages. |
| 3 |
# Should be run in the build directory. |
| 4 |
# Use command line to run different combinations. |
| 5 |
# For example to run C broker, Go sender and C++ receiver pass arguments: C GO CPP |
| 6 |
|
| 7 |
MESSAGES=100000 |
| 8 |
|
| 9 |
BLD=$(pwd) |
| 10 |
|
| 11 |
C=$BLD/c/examples |
| 12 |
C_BROKER="$C/broker" |
| 13 |
C_SEND="$C/send localhost amqp x $MESSAGES" |
| 14 |
C_RECV="$C/receive localhost amqp x $MESSAGES" |
| 15 |
|
| 16 |
GO=$BLD/go/examples/electron |
| 17 |
GO_BROKER="$GO/broker" |
| 18 |
GO_SEND="$GO/send -count $MESSAGES /x" |
| 19 |
GO_RECV="$GO/receive -count $MESSAGES -prefetch 100 /x" |
| 20 |
|
| 21 |
CPP=$BLD/cpp/examples |
| 22 |
CPP_BROKER="$CPP/broker" |
| 23 |
CPP_SEND="$CPP/simple_send -a /x -m $MESSAGES" |
| 24 |
CPP_RECV="$CPP/simple_recv -a /x -m $MESSAGES" |
| 25 |
|
| 26 |
amqp_busy() { ss -tlp | grep $* amqp; } |
| 27 |
|
| 28 |
start_broker() { |
| 29 |
amqp_busy && { "amqp port busy"; exit 1; } |
| 30 |
"$@" & BROKER_PID=$! |
| 31 |
until amqp_busy -q; do sleep .1; done |
| 32 |
} |
| 33 |
|
| 34 |
stop_broker() { |
| 35 |
kill $BROKER_PID |
| 36 |
wait $BROKER_PID 2> /dev/null |
| 37 |
} |
| 38 |
|
| 39 |
run() { |
| 40 |
echo |
| 41 |
echo "run: $*" |
| 42 |
BROKER=${!1} |
| 43 |
SEND=${!2} |
| 44 |
RECV=${!3} |
| 45 |
start_broker $BROKER |
| 46 |
time { |
| 47 |
$RECV > /dev/null& RECV_PID=$! |
| 48 |
$SEND |
| 49 |
wait $RECV_PID |
| 50 |
} |
| 51 |
stop_broker |
| 52 |
} |
| 53 |
|
| 54 |
if test -z "$*"; then |
| 55 |
# By default run the broker/sender/receiver combo for each language |
| 56 |
run C_BROKER C_SEND C_RECV |
| 57 |
run GO_BROKER GO_SEND GO_RECV |
| 58 |
run CPP_BROKER CPP_SEND CPP_RECV |
| 59 |
else |
| 60 |
while test -n "$*"; do |
| 61 |
run ${1}_BROKER ${2}_SEND ${3}_RECV |
| 62 |
shift; shift; shift |
| 63 |
done |
| 64 |
fi |