You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
2.9 KiB
125 lines
2.9 KiB
6 years ago
|
#!/bin/bash
|
||
|
|
||
6 years ago
|
ROOT=$(dirname $0)/..
|
||
|
|
||
6 years ago
|
set -eo pipefail
|
||
|
|
||
6 years ago
|
function cleanup() {
|
||
|
for pid in `/bin/ps -fu $USER| grep "benchmark\|txgen\|soldier\|commander\|profiler\|beacon" | grep -v "grep" | grep -v "vi" | awk '{print $2}'`;
|
||
|
do
|
||
|
echo 'Killed process: '$pid
|
||
|
kill -9 $pid 2> /dev/null
|
||
|
done
|
||
|
}
|
||
|
|
||
6 years ago
|
function killnode() {
|
||
|
local port=$1
|
||
|
|
||
|
if [ -n "port" ]; then
|
||
|
pid=$(/bin/ps -fu $USER | grep "benchmark" | grep "$port" | awk '{print $2}')
|
||
|
echo "killing node with port: $port"
|
||
|
kill -9 $pid 2> /dev/null
|
||
|
echo "node with port: $port is killed"
|
||
|
fi
|
||
|
}
|
||
|
|
||
6 years ago
|
trap cleanup SIGINT SIGTERM
|
||
6 years ago
|
|
||
|
function usage {
|
||
|
local ME=$(basename $0)
|
||
|
|
||
|
cat<<EOU
|
||
6 years ago
|
USAGE: $ME [OPTIONS] config_file_name
|
||
|
|
||
|
-h print this help message
|
||
|
-d enable db support (default: $DB)
|
||
|
-t toggle txgen (default: $TXGEN)
|
||
6 years ago
|
-D duration txgen run duration (default: $DURATION)
|
||
6 years ago
|
-m min_peers minimal number of peers to start consensus (default: $MIN)
|
||
6 years ago
|
-s shards number of shards (default: $SHARDS)
|
||
6 years ago
|
-k nodeport kill the node with specified port number (default: $KILLPORT)
|
||
6 years ago
|
|
||
|
This script will build all the binaries and start benchmark and txgen based on the configuration file.
|
||
|
|
||
|
EXAMPLES:
|
||
|
|
||
|
$ME local_config.txt
|
||
6 years ago
|
$ME -p local_config.txt
|
||
6 years ago
|
|
||
|
EOU
|
||
|
exit 0
|
||
|
}
|
||
|
|
||
6 years ago
|
DB=
|
||
6 years ago
|
TXGEN=true
|
||
6 years ago
|
DURATION=90
|
||
|
MIN=5
|
||
6 years ago
|
SHARDS=2
|
||
6 years ago
|
KILLPORT=9004
|
||
6 years ago
|
|
||
6 years ago
|
while getopts "hdtD:m:s:k:" option; do
|
||
6 years ago
|
case $option in
|
||
|
h) usage ;;
|
||
|
d) DB='-db_supported' ;;
|
||
6 years ago
|
t) TXGEN=$OPTARG ;;
|
||
6 years ago
|
D) DURATION=$OPTARG ;;
|
||
6 years ago
|
m) MIN=$OPTARG ;;
|
||
6 years ago
|
s) SHARDS=$OPTARG ;;
|
||
6 years ago
|
k) KILLPORT=$OPTARG ;;
|
||
6 years ago
|
esac
|
||
|
done
|
||
|
|
||
|
shift $((OPTIND-1))
|
||
|
|
||
6 years ago
|
config=$1
|
||
|
if [ -z "$config" ]; then
|
||
|
usage
|
||
|
fi
|
||
|
|
||
6 years ago
|
|
||
6 years ago
|
# Kill nodes if any
|
||
6 years ago
|
cleanup
|
||
6 years ago
|
|
||
|
# Since `go run` will generate a temporary exe every time,
|
||
|
# On windows, your system will pop up a network security dialog for each instance
|
||
|
# and you won't be able to turn it off. With `go build` generating one
|
||
|
# exe, the dialog will only pop up once at the very first time.
|
||
|
# Also it's recommended to use `go build` for testing the whole exe.
|
||
6 years ago
|
pushd $ROOT
|
||
6 years ago
|
echo "compiling ..."
|
||
6 years ago
|
go build -o bin/benchmark
|
||
|
go build -o bin/txgen client/txgen/main.go
|
||
6 years ago
|
go build -o bin/beacon beaconchain/main/main.go
|
||
6 years ago
|
popd
|
||
6 years ago
|
|
||
6 years ago
|
# Create a tmp folder for logs
|
||
|
t=`date +"%Y%m%d-%H%M%S"`
|
||
6 years ago
|
log_folder="tmp_log/log-$t"
|
||
6 years ago
|
|
||
6 years ago
|
mkdir -p $log_folder
|
||
6 years ago
|
|
||
6 years ago
|
echo "launching beacon chain ..."
|
||
6 years ago
|
$ROOT/bin/beacon -numShards $SHARDS > $log_folder/beacon.log 2>&1 &
|
||
6 years ago
|
sleep 1 #wait or beachchain up
|
||
6 years ago
|
|
||
6 years ago
|
# Start nodes
|
||
6 years ago
|
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||
6 years ago
|
IFS=' ' read ip port mode shardID <<< $line
|
||
6 years ago
|
#echo $ip $port $mode
|
||
6 years ago
|
if [ "$mode" != "client" ]; then
|
||
6 years ago
|
$ROOT/bin/benchmark -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN &
|
||
6 years ago
|
sleep 0.5
|
||
6 years ago
|
fi
|
||
6 years ago
|
done < $config
|
||
6 years ago
|
|
||
6 years ago
|
# Emulate node offline
|
||
|
(sleep 45; killnode $KILLPORT) &
|
||
|
|
||
6 years ago
|
echo "launching txgen ..."Z
|
||
6 years ago
|
if [ "$TXGEN" == "true" ]; then
|
||
6 years ago
|
echo "launching txgen ..."
|
||
6 years ago
|
$ROOT/bin/txgen -log_folder $log_folder -duration $DURATION
|
||
6 years ago
|
fi
|
||
6 years ago
|
|
||
6 years ago
|
cleanup
|