#!/bin/bash

##################
### Definition ###
##################
port_pub=5533
port_sub=5534

## Used source
SOURCE=patched

## Number of runs
NUMRUN=1

## Measurement for
SCALE=300
DURATION=600
NUMCLIENTS=40
WORKERS=32

echo "Test on $SOURCE with scale=$SCALE, duration=$DURATION and #workers=$WORKERS"

###########################
### measure performance ###
###########################

for i in `seq ${NUMRUN}`
do
    # Prepare clean enviroment for each measurements
    sh v1_pa_pub-sub_setup.sh $SOURCE $SCALE $WORKERS

    echo "=================="
    echo "${SOURCE}_${i}.dat"
    echo "=================="

    # Disable the subscription
    ./psql -U postgres -p $port_sub -c "ALTER SUBSCRIPTION sub DISABLE;"

##   ./psql -U postgres -p $port_pub -c "select count(*) from pgbench_history; TRUNCATE pgbench_history;"

  
    # Do actual measurements                                                                                        
    ./pgbench -p $port_pub -U postgres postgres -c $NUMCLIENTS -j $NUMCLIENTS -T $DURATION > pub_scale${SCALE}_${NUMCLIENTS}c_${WORKERS}w_${SOURCE}_${DURATION}s_${i}.dat 

    ####./pgbench -p $port_sub -U postgres postgres -c $NUMCLIENTS -j $NUMCLIENTS -T $DURATION > sub_${SOURCE}_${i}.dat


 ##  ./psql -U postgres -p $port_pub -c "select count(*) from pgbench_history; TRUNCATE pgbench_history;"

    # Enable the subscription
    ./psql -U postgres -p $port_sub -c "ALTER SUBSCRIPTION sub ENABLE;"

done
