Commit f9b288ad authored by Philipp Götze's avatar Philipp Götze
Browse files

🔨 Little optimization for benchmarks and their scripts

parent 29a6241f
#!/bin/bash
### LOCATIONS ###
REPO_ROOT=$PWD/..
BUILD_DIR=$REPO_ROOT/build
DATA=/mnt/pmem/test/tree_bench.data
OUTPUT_FILE=$PWD/results/writes.csv
### CUSTOMIZABLE PARAMETERS ###
bsize=512
depth=0
keypos=('first' 'middle' 'last')
LEAF_SIZES=( 256 512 1024 2048 4096 )
TREE="wBP" #FP/PBP/wBP
TREE_BASE="wBP" # for namespace and numKeys determination
SUFFIX="" # in case of binary vs. linear
### Do not change anything following here!!! ###
### needs manual adaption ###
fillratio=1.0
lat=75
### adapting Tree usage ###
sed -i'' -e 's/\(.*BRANCH_SIZE = \)\([0-9]\+\)\(.*\)/\1'"$bsize"'\3/' $REPO_ROOT/src/bench/trees/common.hpp
sed -i'' -e 's/\(.*DEPTH = \)\([0-9]\+\)\(.*\)/\1'"$depth"'\3/' $REPO_ROOT/src/bench/trees/common.hpp
sed -i'' -e 's/\(.*\"\).*\(Tree.hpp\"\)/\1'"$TREE"'\2/' $REPO_ROOT/src/bench/trees/common.hpp #include
sed -i'' -e 's/\(.*dbis::\).*\(tree;\)/\1'"${TREE_BASE,,}"'\2/' $REPO_ROOT/src/bench/trees/common.hpp #namespace
sed -i'' -e 's/\(.*LEAFKEYS = getLeafKeys\).*\(Tree.*\)/\1'"$TREE_BASE"'\2/' $REPO_ROOT/src/bench/trees/common.hpp #keys
sed -i'' -e 's/\(.*BRANCHKEYS = getBranchKeys\).*\(Tree.*\)/\1'"$TREE_BASE"'\2/' $REPO_ROOT/src/bench/trees/common.hpp #keys
sed -i'' -e 's/\(.*TreeType = \).*\(Tree.*\)/\1'"$TREE"'\2/' $REPO_ROOT/src/bench/trees/common.hpp #type
echo -n "Running benchmarks for ${Tree}Tree..."
for pos in "${keypos[@]}"
do
echo -en "\nKey Position: $pos - "
KEYPOS='2'
if [ $pos == "first" ];then
KEYPOS='ELEMENTS'
elif [ $pos == "last" ]; then
KEYPOS='1'
fi
sed -i'' -e 's/\(.*KEYPOS = ELEMENTS\/\)\(.\+\)\(;.*\)/\1'"$KEYPOS"'\3/' $REPO_ROOT/src/bench/trees/common.hpp
for lsize in "${LEAF_SIZES[@]}"
do
echo -n "$lsize "
sed -i'' -e 's/\(.*LEAF_SIZE = \)\([0-9]\+\)\(.*\)/\1'"$lsize"'\3/' $REPO_ROOT/src/bench/trees/common.hpp
pushd $BUILD_DIR > /dev/null
make tree_insert > /dev/null
rm -rf $DATA
OUTPUT="$(sh -c 'bench/tree_insert --benchmark_format=csv --benchmark_min_time=0.005' 2> /dev/null | tail -4)"
writes="$(echo "$OUTPUT" | head -1 | cut -d ':' -f2)"
elements="$(echo "$OUTPUT" | head -2 | tail -1 | cut -d ':' -f2)"
time="$(echo "$OUTPUT" | tail -1 | cut -d ',' -f4)"
echo "${TREE}Tree$SUFFIX,$elements,$lsize,$bsize,$depth,$fillratio,$pos,$time,$writes" >> $OUTPUT_FILE
popd > /dev/null
done
done
echo -e "\nFinished. Results in $OUTPUT_FILE"
......@@ -6,12 +6,17 @@ BUILD_DIR=$REPO_ROOT/build
DATA=/mnt/pmem/test/tree_bench.data
OUTPUT_FILE=$PWD/results/bytesWritten.csv
### Create header ###
if [ ! -s $OUTPUT_FILE ]; then
echo "tree,tblsize,lsize,bsize,depth,fillratio,keypos,time,writes" >> $OUTPUT_FILE
fi
### CUSTOMIZABLE PARAMETERS ###
bsize=512
depth=0
keypos=('first' 'middle' 'last')
LEAF_SIZES=( 256 512 1024 2048 4096 )
TREE="UnsortedPBP" #FP/PBP/wBP
TREE="BitPBP" #FP/PBP/wBP
TREE_BASE="PBP" # for namespace and numKeys determination
SUFFIX="" # in case of binary vs. linear
......@@ -19,7 +24,6 @@ SUFFIX="" # in case of binary vs. linear
### needs manual adaption ###
fillratio=1.0
lat=750
### adapting Tree usage ###
sed -i'' -e 's/\(.*BRANCH_SIZE = \)\([0-9]\+\)\(.*\)/\1'"$bsize"'\3/' $REPO_ROOT/src/bench/trees/common.hpp
......@@ -54,7 +58,7 @@ do
writes="$(echo "$OUTPUT" | head -1 | cut -d ':' -f2)"
elements="$(echo "$OUTPUT" | tail -3 | head -1 | cut -d ':' -f2)"
time="$(echo "$OUTPUT" | tail -1 | cut -d ',' -f4)"
echo "${TREE}Tree$SUFFIX,$elements,$lsize,$bsize,$depth,$fillratio,$pos,$time,$writes,$lat" >> $OUTPUT_FILE
echo "${TREE}Tree$SUFFIX,$elements,$lsize,$bsize,$depth,$fillratio,$pos,$time,$writes" >> $OUTPUT_FILE
done
popd > /dev/null
done
......
......@@ -18,7 +18,6 @@ SUFFIX="" # in case of binary vs. linear
### needs manual adaption ###
fillratio=1.0
lat=75
### adapting Tree usage ###
sed -i'' -e 's/\(.*BRANCH_SIZE = \)\([0-9]\+\)\(.*\)/\1'"$bsize"'\3/' $REPO_ROOT/src/bench/trees/common.hpp
......@@ -43,7 +42,7 @@ do
writes="$(echo "$OUTPUT" | head -1 | cut -d ':' -f2)"
elements="$(echo "$OUTPUT" | tail -3 | head -1 | cut -d ':' -f2)"
time="$(echo "$OUTPUT" | tail -1 | cut -d ',' -f4)"
echo "${TREE}Tree$SUFFIX,$elements,$lsize,$bsize,$depth,$fillratio,$(($elements+1)),$time,$writes,$lat" >> $OUTPUT_FILE
echo "${TREE}Tree$SUFFIX,$elements,$lsize,$bsize,$depth,$fillratio,$(($elements+1)),$time,$writes" >> $OUTPUT_FILE
done
popd > /dev/null
done
......
......@@ -37,20 +37,21 @@ static void BM_TreeGet(benchmark::State &state) {
} else {
LOG("Warning: " << path << " already exists");
pop = pool<root>::open(path, LAYOUT);
//pop.root()->tree->recover(); //< hybrids only
//pop.root()->treeRef.recover(); //< hybrids only
}
auto tree = pop.root()->tree;
//tree->printBranchNode(0, tree->rootNode.branch);
const auto tree = pop.root()->tree;
auto &treeRef = *tree;
//treeRef.printBranchNode(0, treeRef.rootNode.branch);
/* Getting a leaf node */
auto node = tree->rootNode;
auto node = treeRef.rootNode;
/* hybrid versions */
//auto d = tree->depth;
//auto d = treeRef.depth;
//while ( d-- > 0) node = node.branch->children[0];
/* nvm-only trees */
auto d = tree->depth.get_ro();
auto d = treeRef.depth.get_ro();
while ( d-- > 0) node = node.branch->children.get_ro()[0];
auto leaf = node.leaf;
......@@ -59,11 +60,11 @@ static void BM_TreeGet(benchmark::State &state) {
unsigned int p;
for (auto _ : state) {
benchmark::DoNotOptimize(
p = tree->lookupPositionInLeafNode(leaf, LEAFKEYS)
p = treeRef.lookupPositionInLeafNode(leaf, LEAFKEYS)
);
}
//tree->printBranchNode(0, tree->rootNode.branch);
//treeRef.printBranchNode(0, treeRef.rootNode.branch);
std::cout << "Elements:" << ELEMENTS << '\n';
pop.close();
}
......
......@@ -46,11 +46,12 @@ static void BM_TreeInsert(benchmark::State &state) {
pop.root()->tree = make_persistent<TreeType>();
});
}
auto tree = pop.root()->tree;
const auto tree = pop.root()->tree;
auto &treeRef = *tree;
/* Getting the leaf node */
auto leaf = tree->rootNode.leaf;
//tree->printLeafNode(0, leaf);
auto leaf = treeRef.rootNode.leaf;
//treeRef.printLeafNode(0, leaf);
const auto reqTup = MyTuple(KEYPOS, KEYPOS * 100, KEYPOS * 1.0);
TreeType::SplitInfo splitInfo;
......@@ -60,21 +61,21 @@ static void BM_TreeInsert(benchmark::State &state) {
for (auto _ : state) {
state.PauseTiming();
std::cout.setstate(std::ios_base::failbit);
tree->rootNode = tree->newLeafNode();
leaf = tree->rootNode.leaf;
treeRef.rootNode = treeRef.newLeafNode();
leaf = treeRef.rootNode.leaf;
prepare(tree);
dbis::PersistEmulation::getBytesWritten();
state.ResumeTiming();
split = tree->insertInLeafNode(leaf, KEYPOS, reqTup, &splitInfo);
split = treeRef.insertInLeafNode(leaf, KEYPOS, reqTup, &splitInfo);
state.PauseTiming();
assert(split == false);
tree->deleteLeafNode(leaf);
treeRef.deleteLeafNode(leaf);
state.ResumeTiming();
}
//tree->printLeafNode(0, leaf);
//treeRef.printLeafNode(0, leaf);
std::cout.clear();
std::cout << "Writes:" << dbis::PersistEmulation::getBytesWritten() << '\n';
std::cout << "Elements:" << ELEMENTS << '\n';
......@@ -86,10 +87,11 @@ BENCHMARK_MAIN();
/* preparing inserts */
void prepare(const persistent_ptr<TreeType> tree) {
auto insertLoop = [&tree](int start, int end) {
auto &treeRef = *tree;
auto insertLoop = [&treeRef](int start, int end) {
for (auto j = start; j < end + 1; ++j) {
auto tup = MyTuple(j, j * 100, j * 1.0);
tree->insert(j, tup);
treeRef.insert(j, tup);
}
};
switch (KEYPOS) {
......
......@@ -47,10 +47,11 @@ static void BM_TreeSplit(benchmark::State &state) {
});
}
auto tree = pop.root()->tree;
auto &treeRef = *tree;
/* Getting the leaf node */
auto leaf = tree->rootNode.leaf;
//tree->printLeafNode(0, leaf);
auto leaf = treeRef.rootNode.leaf;
//treeRef.printLeafNode(0, leaf);
const auto reqTup = MyTuple(ELEMENTS+1, (ELEMENTS+1) * 100, (ELEMENTS+1) * 1.0);
TreeType::SplitInfo splitInfo;
......@@ -60,23 +61,23 @@ static void BM_TreeSplit(benchmark::State &state) {
for (auto _ : state) {
state.PauseTiming();
std::cout.setstate(std::ios_base::failbit);
tree->rootNode = tree->newLeafNode();
leaf = tree->rootNode.leaf;
treeRef.rootNode = treeRef.newLeafNode();
leaf = treeRef.rootNode.leaf;
prepare(tree);
dbis::PersistEmulation::getBytesWritten();
//tree->printLeafNode(0, leaf);
//treeRef.printLeafNode(0, leaf);
state.ResumeTiming();
tree->splitLeafNode(leaf, &splitInfo);
treeRef.splitLeafNode(leaf, &splitInfo);
state.PauseTiming();
//tree->printLeafNode(0, leaf);
tree->deleteLeafNode(leaf->nextLeaf);
tree->deleteLeafNode(leaf);
//treeRef.printLeafNode(0, leaf);
treeRef.deleteLeafNode(leaf->nextLeaf);
treeRef.deleteLeafNode(leaf);
state.ResumeTiming();
}
//tree->printLeafNode(0, leaf);
//treeRef.printLeafNode(0, leaf);
std::cout.clear();
std::cout << "Writes:" << dbis::PersistEmulation::getBytesWritten() << '\n';
std::cout << "Elements:" << ELEMENTS << '\n';
......@@ -88,8 +89,9 @@ BENCHMARK_MAIN();
/* preparing inserts */
void prepare(const persistent_ptr<TreeType> tree) {
for (auto j = 1; j < ELEMENTS+1; ++j) {
auto tup = MyTuple(j, j * 100, j * 1.0);
tree->insert(j, tup);
}
auto &treeRef = *tree;
for (auto j = 1; j < ELEMENTS+1; ++j) {
auto tup = MyTuple(j, j * 100, j * 1.0);
treeRef.insert(j, tup);
}
}
......@@ -37,31 +37,32 @@ static void BM_TreeTraverse(benchmark::State &state) {
} else {
LOG("Warning: " << path << " already exists");
pop = pool<root>::open(path, LAYOUT);
//pop.root()->tree->recover(); //< Hybrids only
//pop.root()->treeRef.recover(); //< Hybrids only
}
auto tree = pop.root()->tree;
auto &treeRef = *tree;
persistent_ptr<TreeType::LeafNode> leaf;
/* BENCHMARKING */
for (auto _ : state) {
/* Getting a leaf node */
auto node = tree->rootNode;
auto node = treeRef.rootNode;
/* hybrid versions *//*
auto d = tree->depth;
auto d = treeRef.depth;
while ( --d > 0)
node = node.branch->children[tree->lookupPositionInBranchNode(node.branch, KEYPOS)];*/
node = node.branch->children[treeRef.lookupPositionInBranchNode(node.branch, KEYPOS)];*/
/* NVM-only versions */
auto d = tree->depth.get_ro();
auto d = treeRef.depth.get_ro();
while ( --d > 0)
node = node.branch->children.get_ro()[tree->lookupPositionInBranchNode(node.branch, KEYPOS)];
node = node.branch->children.get_ro()[treeRef.lookupPositionInBranchNode(node.branch, KEYPOS)];
benchmark::DoNotOptimize(
leaf = node.leaf
);
//auto p = tree->lookupPositionInLeafNode(leaf, 1);
//auto p = treeRef.lookupPositionInLeafNode(leaf, 1);
}
//tree->printBranchNode(0, tree->rootNode.branch);
//treeRef.printBranchNode(0, treeRef.rootNode.branch);
std::cout << "Elements:" << ELEMENTS << "\n";
pop.close();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment