Skip to content

Instantly share code, notes, and snippets.

@tmcallaghan
Created February 19, 2015 18:34
Show Gist options
  • Save tmcallaghan/4d15c18f9e34e1ea8a21 to your computer and use it in GitHub Desktop.
Save tmcallaghan/4d15c18f9e34e1ea8a21 to your computer and use it in GitHub Desktop.
How to benchmark MongoDB
#!/bin/bash
# remember the directory we are starting from
# the script expects the MongoDB configuration files here
export homeDirectory=$PWD
# directory where MongoDB/TokuMX tarballs are located
export tarDirectory=/home/tcallaghan/big-dir/backups/mongodb
# directory used for MongoDB server binaries and data folder
export MONGO_DIR=~/temp
# perform some sanity checks
# check that $MONGO_DIR is defined
if [ -z "$MONGO_DIR" ]; then
echo "Need to set MONGO_DIR"
exit 1
fi
# check that $MONGO_DIR exists
if [ ! -d "$MONGO_DIR" ]; then
echo "Need to create directory $MONGO_DIR"
exit 1
fi
# check that $MONGO_DIR is empty
# force manual cleanup before starting
if [ "$(ls -A ${MONGO_DIR})" ]; then
echo "Directory $MONGO_DIR must be empty before starting"
exit 1
fi
# decide which tarballs and configurations we want to benchmark
# use semi-colon list of "tarball;id;config;mongo_type"
# tarball : MongoDB or TokuMX tarball
# id : Short hand description of this particular benchmark run, ends up in the log file and the summary log
# config : YAML configuration file to use for the this benchmark run
# mongo_type : Identifies which "type" of MongoDB, tokumx|mxse|wt|mongo
export benchmarkList=""
export benchmarkList="${benchmarkList} mongodb-linux-x86_64-tokumxse-1.0.0-rc.2.tgz;mxse_100rc2_none;tokumxse-uncompressed.conf;mxse"
export benchmarkList="${benchmarkList} mongodb-linux-x86_64-tokumxse-1.0.0-rc.2.tgz;mxse_100rc2_quicklz;tokumxse-quicklz.conf;mxse"
export benchmarkList="${benchmarkList} mongodb-linux-x86_64-tokumxse-1.0.0-rc.2.tgz;mxse_100rc2_zlib;tokumxse-zlib.conf;mxse"
export benchmarkList="${benchmarkList} mongodb-linux-x86_64-tokumxse-1.0.0-rc.2.tgz;mxse_100rc2_lzma;tokumxse-lzma.conf;mxse"
export benchmarkList="${benchmarkList} mongodb-linux-x86_64-3.0.0-rc8.tgz;mmapv1_300rc8;mmapv1.conf;mongo"
export benchmarkList="${benchmarkList} mongodb-linux-x86_64-3.0.0-rc8.tgz;wt_300rc8_none;wiredtiger-uncompressed.conf;wt"
export benchmarkList="${benchmarkList} mongodb-linux-x86_64-3.0.0-rc8.tgz;wt_300rc8_snappy;wiredtiger-snappy.conf;wt"
export benchmarkList="${benchmarkList} mongodb-linux-x86_64-3.0.0-rc8.tgz;wt_300rc8_zlib;wiredtiger-zlib.conf;wt"
# make sure we have valid tarballs and config scripts for this benchmark run
echo "checking that all needed tarballs exist."
for thisBenchmark in ${benchmarkList}; do
TARBALL=$(echo "${thisBenchmark}" | cut -d';' -f1)
MONGOD_CONFIG=$(echo "${thisBenchmark}" | cut -d';' -f3)
if [ -e ${tarDirectory}/${TARBALL} ]; then
echo " located ${tarDirectory}/${TARBALL}"
else
echo " unable to locate ${tarDirectory}/${TARBALL}, exiting."
exit 1
fi
if [ -e ${MONGOD_CONFIG} ]; then
echo " located ${MONGOD_CONFIG}"
else
echo " unable to locate ${MONGOD_CONFIG}, exiting."
exit 1
fi
done
export DB_NAME=test
export NUM_CLIENTS=2
export DOCS_PER_CLIENT=$((512 * 80000))
export NUM_INSERTS=$((NUM_CLIENTS * DOCS_PER_CLIENT))
export SUMMARY_LOG_NAME=summary.log
rm -f ${SUMMARY_LOG_NAME}
for thisBenchmark in ${benchmarkList}; do
export TARBALL=$(echo "${thisBenchmark}" | cut -d';' -f1)
export MINI_BENCH_ID=$(echo "${thisBenchmark}" | cut -d';' -f2)
export MONGOD_CONFIG=$(echo "${thisBenchmark}" | cut -d';' -f3)
export MONGO_TYPE=$(echo "${thisBenchmark}" | cut -d';' -f4)
echo "benchmarking tarball = ${TARBALL}"
# clean up + start the new server
pushd ${MONGO_DIR}
if [ "$?" -eq 1 ]; then
echo "Unable to pushd $MONGO_DIR, exiting."
exit 1
fi
# erase any files from the previous run
rm -rf *
# untar server binaries to here
tar xzvf ${tarDirectory}/${TARBALL} --strip 1
# create the "data" directory
mkdir data
bin/mongod --config ${homeDirectory}/${MONGOD_CONFIG}
popd
# wait for mongo to start
while [ 1 ]; do
$MONGO_DIR/bin/mongostat -n 1 > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
break
fi
sleep 5
done
sleep 5
# log for this run
export LOG_NAME=${MINI_BENCH_ID}-${NUM_CLIENTS}-${NUM_INSERTS}.log
rm -f ${LOG_NAME}
# TODO : log server performance with mongostat
# start the first inserter
T="$(date +%s)"
echo "`date` | starting insert client 1" | tee -a ${LOG_NAME}
$MONGO_DIR/bin/mongo ${DB_NAME} --eval 'load("./compress_test.js")' &
sleep 5
# start the additional insert clients
clientNumber=2
while [ ${clientNumber} -le ${NUM_CLIENTS} ]; do
echo "`date` | starting insert client ${clientNumber}" | tee -a ${LOG_NAME}
$MONGO_DIR/bin/mongo ${DB_NAME} --eval 'load("./compress_test.js")' &
let clientNumber=clientNumber+1
done
# wait for all of the client(s) to finish
wait
# report insert performance
T="$(($(date +%s)-T))"
printf "`date` | insert duration = %02d:%02d:%02d:%02d\n" "$((T/86400))" "$((T/3600%24))" "$((T/60%60))" "$((T%60))" | tee -a ${LOG_NAME}
DOCS_PER_SEC=`echo "scale=0; ${NUM_INSERTS}/${T}" | bc `
echo "`date` | inserts per second = ${DOCS_PER_SEC}" | tee -a ${LOG_NAME}
# stop the server
T="$(date +%s)"
echo "`date` | shutting down the server" | tee -a ${LOG_NAME}
$MONGO_DIR/bin/mongo admin --eval "db.shutdownServer({force: true})"
# wait for the MongoDB server to shutdown
while [ 1 ]; do
pgrep -U $USER mongod > /dev/null 2>&1
if [ "$?" -eq 1 ]; then
break
fi
sleep 5
done
T="$(($(date +%s)-T))"
printf "`date` | shutdown duration = %02d:%02d:%02d:%02d\n" "$((T/86400))" "$((T/3600%24))" "$((T/60%60))" "$((T%60))" | tee -a ${LOG_NAME}
# report size on disk
SIZE_BYTES=`du -c --block-size=1 ${MONGO_DIR}/data | tail -n 1 | cut -f1`
SIZE_MB=`echo "scale=2; ${SIZE_BYTES}/(1024*1024)" | bc `
echo "`date` | post-load sizing (SizeMB) = ${SIZE_MB}" | tee -a ${LOG_NAME}
# put all the information into the summary log file
echo "`date` | tech = ${MINI_BENCH_ID} | ips = ${DOCS_PER_SEC} | sizeMB = ${SIZE_MB}" | tee -a ${SUMMARY_LOG_NAME}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment