Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 34c3048

Browse files
dmiusDmitry
authored andcommitted
Use min price with zone
1 parent 4fc79a7 commit 34c3048

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

nancy_run.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ if ([ "$RUN_ON" == "aws" ] && [ ! ${AWS_EC2_TYPE:0:2} == "i3" ] && \
584584
fi
585585

586586
set -ueo pipefail
587-
[ $DEBUG -eq 1 ] && set -ueox pipefail # to debug
587+
[ $DEBUG -eq 1 ] && set -uox pipefail # to debug
588588
shopt -s expand_aliases
589589

590590
## Docker tools
@@ -628,6 +628,7 @@ function createDockerMachine() {
628628
--amazonec2-ssh-keypath="$6" \
629629
--amazonec2-instance-type=$2 \
630630
--amazonec2-spot-price=$3 \
631+
--amazonec2-zone $7 \
631632
$1 2> >(grep -v "failed waiting for successful resource state" >&2) &
632633
# --amazonec2-block-duration-minutes=$4 \
633634
}
@@ -699,17 +700,24 @@ elif [[ "$RUN_ON" = "aws" ]]; then
699700
--start-time=$(date +%s) --product-descriptions="Linux/UNIX (Amazon VPC)" \
700701
--query 'SpotPriceHistory[*].{az:AvailabilityZone, price:SpotPrice}'
701702
)
702-
maxprice=$(echo $prices | jq 'max_by(.price) | .price')
703-
maxprice="${maxprice/\"/}"
704-
maxprice="${maxprice/\"/}"
705-
echo "$(date "+%Y-%m-%d %H:%M:%S"): Max price from history: $maxprice"
706-
multiplier="1.1"
707-
price=$(echo "$maxprice * $multiplier" | bc -l)
703+
minprice=$(echo $prices | jq 'min_by(.price) | .price')
704+
region=$(echo $prices | jq 'min_by(.price) | .az')
705+
region="${region/\"/}"
706+
region="${region/\"/}"
707+
minprice="${minprice/\"/}"
708+
minprice="${minprice/\"/}"
709+
zone=${region: -1}
710+
echo "$(date "+%Y-%m-%d %H:%M:%S"): Min price from history: $minprice in $region (zone: $zone)"
711+
multiplier="1.01"
712+
price=$(echo "$minprice * $multiplier" | bc -l)
708713
echo "$(date "+%Y-%m-%d %H:%M:%S"): Increased price: $price"
709714
EC2_PRICE=$price
715+
if [ -z $zone ]; then
716+
region='a' #default zone
717+
fi
710718

711719
createDockerMachine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
712-
60 $AWS_KEY_PAIR $AWS_KEY_PATH;
720+
60 $AWS_KEY_PAIR $AWS_KEY_PATH $zone;
713721
status=$(waitEC2Ready "docker-machine create" "$DOCKER_MACHINE" 1)
714722
if [ "$status" == "price-too-low" ]
715723
then
@@ -895,7 +903,7 @@ case "$DB_DUMP_EXT" in
895903
docker_exec bash -c "zcat $MACHINE_HOME/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test $OUTPUT_REDIRECT"
896904
;;
897905
pgdmp)
898-
docker_exec bash -c "pg_restore -j $CPU_CNT --no-owner --no-privileges -U postgres -d test $MACHINE_HOME/$DB_DUMP_FILENAME"
906+
docker_exec bash -c "pg_restore -j $CPU_CNT --no-owner --no-privileges -U postgres -d test $MACHINE_HOME/$DB_DUMP_FILENAME" || true
899907
;;
900908
esac
901909
END_TIME=$(date +%s);
@@ -980,7 +988,11 @@ if [ ! -z ${WORKLOAD_REAL+x} ] && [ "$WORKLOAD_REAL" != '' ];then
980988
echo "$(date "+%Y-%m-%d %H:%M:%S"): Execute pgreplay queries..."
981989
docker_exec psql -U postgres test -c 'create role testuser superuser login;'
982990
WORKLOAD_FILE_NAME=$(basename $WORKLOAD_REAL)
983-
docker_exec bash -c "pgreplay -r -j $MACHINE_HOME/$WORKLOAD_FILE_NAME"
991+
if [ ! -z ${WORKLOAD_REAL_REPLAY_SPEED+x} ] && [ "$WORKLOAD_REAL_REPLAY_SPEED" != '' ]; then
992+
docker_exec bash -c "pgreplay -r -s $WORKLOAD_REAL_REPLAY_SPEED $MACHINE_HOME/$WORKLOAD_FILE_NAME"
993+
else
994+
docker_exec bash -c "pgreplay -r -j $MACHINE_HOME/$WORKLOAD_FILE_NAME"
995+
fi
984996
else
985997
if ([ ! -z ${WORKLOAD_CUSTOM_SQL+x} ] && [ "$WORKLOAD_CUSTOM_SQL" != "" ]); then
986998
WORKLOAD_CUSTOM_FILENAME=$(basename $WORKLOAD_CUSTOM_SQL)

0 commit comments

Comments
 (0)