#!/bin/bash

# Pure selects performance (run right after insert without recreating the database)

if [ $DATABASE == "rethinkdb" ]; then
    ./dbench                                                                                        \
        -d "$BENCH_DIR/bench_output/Select_performance" -H $SERVER_HOSTS            \
        {server}rethinkdb:"-m 32768 $SSD_DRIVES"                                              \
        {client}stress[$STRESS_CLIENT]:"-b 8-32 -v 8-32 -c $CANONICAL_CLIENTS -d $CANONICAL_DURATION -w 0/0/0/1 -i $TMP_KEY_FILE"     \
        iostat:1 vmstat:1 rdbstat:1
elif [ $DATABASE == "mysql" ]; then
    ./dbench                                                                                         \
        -d "$BENCH_DIR/bench_output/Select_performance" -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 $CANONICAL_CLIENTS -d $CANONICAL_DURATION -w 0/0/0/1 -i $TMP_KEY_FILE" \
        iostat:1 vmstat:1
elif [ $DATABASE == "membase" ]; then
    # Kill the page cache!
        sync
        sudo sh -c 'echo 1 > /proc/sys/vm/drop_caches'
        sync
        sleep 30
        sudo sh -c 'echo 0 > /proc/sys/vm/drop_caches'

    ./dbench                                                                                   \
        -d "$BENCH_DIR/bench_output/Select_performance" -H $SERVER_HOSTS -p 11211 \
        {server}membase:"-d $PERSISTENT_DATA_DIR -m 32768 -c yes"                                       \
        {client}stress[$STRESS_CLIENT]:"-b 8-32 -v 8-32 -c $CANONICAL_CLIENTS -d $CANONICAL_DURATION -w 0/0/0/1 -i $TMP_KEY_FILE" \
        iostat:1 vmstat:1
else
    echo "No workload configuration for $DATABASE"
fi
