#!/bin/bash

# Takes the number of cores as its argument
# Note: We run with a doubled number of clients here!
function run_with_cores {
    NUMBER_OF_CORES=$1
    
    if [ $DATABASE == "rethinkdb" ]; then
        ./dbench                                                                                                \
            --prime-caches                                                                                      \
            -d "$BENCH_DIR/bench_output/Number_of_cores_select_only_workload/$NUMBER_OF_CORES" -H $SERVER_HOSTS    \
            {server}rethinkdb:"-c $NUMBER_OF_CORES -m 32768 $SSD_DRIVES"                                            \
            {client}stress[$STRESS_CLIENT]:"-b 8-32 -v 8-32 -c 1024 -d $CANONICAL_MULTIRUN_DURATION -w 0/0/0/1 -i $TMP_KEY_FILE" \
            iostat:1 vmstat:1 rdbstat:1
    elif [ $DATABASE == "mysql" ]; then
        if [ "$NUMBER_OF_CORES" -lt "24" ]; then
            sudo bash -c "for CPU in {$NUMBER_OF_CORES..23}; do echo 0 > /sys/devices/system/cpu/cpu\$CPU/online; done"
        fi
        ./dbench                                                                                                \
            --prime-caches                                                                                   \
            -d "$BENCH_DIR/bench_output/Number_of_cores_select_only_workload/$NUMBER_OF_CORES" -H $SERVER_HOSTS             \
            {server}mysql:"$MYSQL_COMMON_FLAGS $MYSQL_BUFFER_FLAGS $MYSQL_DURABILITY_FLAGS $MYSQL_SSD_FLAGS"              \
            {client}mysqlstress[$STRESS_CLIENT]:"-b 8-32 -v 8-32 -c 128 -d $CANONICAL_MULTIRUN_DURATION -w 0/0/0/1 -i $TMP_KEY_FILE" \
            iostat:1 vmstat:1
        if [ "$NUMBER_OF_CORES" -lt "24" ]; then
            sudo bash -c "for CPU in {$NUMBER_OF_CORES..23}; do echo 1 > /sys/devices/system/cpu/cpu\$CPU/online; done"
        fi
    else
        echo "No workload configuration for $DATABASE"
    fi
}

