#!/bin/bash

# Takes the number of clients as its argument
function run_with_clients {
    NUMBER_OF_CLIENTS=$1
    
    if [ $DATABASE == "rethinkdb" ]; then
        ../../build/release/rethinkdb create $SSD_DRIVES --force
        ./dbench                                                                                      \
            -d "$BENCH_DIR/bench_output/Concurrent_clients_(canonical_workload)/$NUMBER_OF_CLIENTS" -H $SERVER_HOSTS    \
            {server}rethinkdb:"-m 32768 $SSD_DRIVES"                                            \
            {client}stress[$STRESS_CLIENT]:"-c $NUMBER_OF_CLIENTS -d $CANONICAL_MULTIRUN_DURATION" \
            iostat:1 vmstat:1 rdbstat:1
    elif [ $DATABASE == "mysql" ]; then
        if [ "$NUMBER_OF_CLIENTS" -lt "1025" ]; then
            ./dbench                                                                                   \
                -d "$BENCH_DIR/bench_output/Concurrent_clients_(canonical_workload)/$NUMBER_OF_CLIENTS" -H $SERVER_HOSTS \
                {server}mysql:"$MYSQL_COMMON_FLAGS $MYSQL_BUFFER_FLAGS $MYSQL_DURABILITY_FLAGS $MYSQL_SSD_FLAGS"        \
                {client}mysqlstress[$STRESS_CLIENT]:"-c $NUMBER_OF_CLIENTS -d $CANONICAL_MULTIRUN_DURATION" \
                iostat:1 vmstat:1
        else
            echo "Not running MySQL for more than 1024 clients"
        fi
    elif [ $DATABASE == "membase" ]; then
        ./dbench                                                                                   \
            -d "$BENCH_DIR/bench_output/Concurrent_clients_(canonical_workload)/$NUMBER_OF_CLIENTS" -H $SERVER_HOSTS -p 11211 \
            {server}membase:"-d $MEMBASE_DATA_PATH -m 32768"                                       \
            {client}stress[$STRESS_CLIENT]:"-c $NUMBER_OF_CLIENTS -d $CANONICAL_MULTIRUN_DURATION" \
            iostat:1 vmstat:1
    else
        echo "No workload configuration for $DATABASE"
    fi
}

