added benchmark scripts

This commit is contained in:
Martin Farenholtz 2021-03-31 12:37:15 +02:00
parent cc5bfec4e3
commit 37155a9629
11 changed files with 241 additions and 13 deletions

View File

@ -1,5 +1,5 @@
How to compile: gcc execution.cpp sqlite3.c -lpthread -ldl -lstdc++ How to compile: `gcc execution.cpp sqlite3.c -lpthread -ldl -lstdc++ -o sqlite_binary`
How to run: ./a.out "name" How to run: `./sqlite_binary "name"`
How to run in memory: ./a.out ":memory:" How to run in memory: `./sqlite_binary ":memory:"`

View File

@ -0,0 +1,5 @@
CREATE TABLE benchmarktable(ID long, STR char(32))
load fill
load mixed
select * from benchmarktable
quit

View File

@ -0,0 +1,5 @@
CREATE TABLE benchmarktable(ID long, STR char(32))
CREATE INDEX idx ON benchmarktable(ID) USING BTREE
load fill
load mixed
quit

View File

@ -0,0 +1,5 @@
CREATE TABLE benchmarktable(ID long, STR char(32))
CREATE INDEX idx ON benchmarktable(ID) USING HASHTABLE
load fill
load mixed
quit

40
benchmarks/run_benchmarks.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
# Script for executing ALL benchmarks
# uncomment corresponding scripts to enable benchmark
# Failsafe to prevent execution of unwanted benchmarks
echo "Runtime of benchmarks can be up to 8h"
echo "The following benchmark scripts will be executed:"
if ! grep '^./run' ./run_benchmarks.sh
then
echo "No benchmarks enabled"
fi
echo "Are these the ONLY benchmarks you want to run?"
select answer in "y" "n"
do
case $answer in
y ) break;;
n ) exit;;
esac
done
# High contention, high conflict
# ~5h runtime
#./run_hchc.sh
# High contention, low conflict
# ~25min runtime
#./run_hclc.sh
# Low contention, low conflict
# ~25min runtime
#./run_lclc.sh
# Range queries
# ~8min runtime
#./run_rangequeries.sh
# Hashtable
# ~2h runtime
#./run_hashtable.sh

22
benchmarks/run_hashtable.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
# script for executing benchmark for hashtable
# create/clear benchmark subdirectory
mkdir -p hashtable
rm -rf hashtable/*
# copy raw files to correct location
cp /home/kreft/benchmark/benchmarks/fill_hash_sqlite ./fill.txt
cp /home/kreft/benchmark/benchmarks/mixed_hash_sqlite ./mixed.txt
echo "Executing hashtable benchmark"
for run in 1 2 3 4 5
do
echo "Executing run $run"
cat benchmark_run.txt | ../sqlite_binary >> ./hashtable/messung.txt
echo "Executing run $run with hashtable"
cat benchmark_run_hash.txt | ../sqlite_binary >> ./hashtable/messung_hash.txt
echo "Executing run $run with btree"
cat benchmark_run_btree.txt | ../sqlite_binary >> ./hashtable/messung_btree.txt
done

33
benchmarks/run_hchc.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# script for executing benchmark for high contention, high conflict
# create/clear benchmark subdirectory
mkdir -p hchc
rm -rf hchc/*
# copy raw file to correct location
cp /home/kreft/benchmark/benchmarks/fill_hchc_sqlite ./fill.txt
echo "Executing hchc benchmark"
for updates in 1 2 3 4 5 6 7 8 9 10
do
# create/clear subdirectories for different parameters
dir_name="upd_$updates"
mkdir -p ./hchc/$dir_name
rm -f ./hchc/$dir_name/*.txt
# copy raw file to correct location
cp /home/kreft/benchmark/benchmarks/mixed_hchc$((updates))_sqlite ./mixed.txt
echo "Executing runs for $updates updates"
for run in 1 2 3 4 5
do
echo "Executing run $run"
cat benchmark_run.txt | ../sqlite_binary >> ./hchc/$dir_name/messung.txt
echo "Executing run $run with hashtable"
cat benchmark_run_hash.txt | ../sqlite_binary >> ./hchc/$dir_name/messung_hash.txt
echo "Executing run $run with btree"
cat benchmark_run_btree.txt | ../sqlite_binary >> ./hchc/$dir_name/messung_btree.txt
done
done

20
benchmarks/run_hclc.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# script for executing benchmark for high contention, low conflict
# create/clear benchmark subdirectory
mkdir -p hclc
rm -rf hclc/*
# copy raw files to correct location
cp /home/kreft/benchmark/benchmarks/fill_hclc_sqlite ./fill.txt
cp /home/kreft/benchmark/benchmarks/mixed_hclc_sqlite ./mixed.txt
echo "Executing hclc benchmark"
for run in 1 2 3 4 5
do
echo "Executing run $run"
cat benchmark_run.txt | ../sqlite_binary >> ./hclc/messung.txt
#cat benchmark_run_hash.txt | ../sqlite_binary >> ./lclc/messung_hash.txt
#cat benchmark_run_btree.txt | ../sqlite_binary >> ./lclc/messung_btree.txt
done

20
benchmarks/run_lclc.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# script for executing benchmark for low contention, low conflict
# create/clear benchmark subdirectory
mkdir -p lclc
rm -rf lclc/*
# copy raw files to correct location
cp /home/kreft/benchmark/benchmarks/fill_lclc_sqlite ./fill.txt
cp /home/kreft/benchmark/benchmarks/mixed_lclc_sqlite ./mixed.txt
echo "Executing lclc benchmark"
for run in 1 2 3 4 5
do
echo "Executing run $run"
cat benchmark_run.txt | ../sqlite_binary >> ./lclc/messung.txt
#cat benchmark_run_hash.txt | ../sqlite_binary >> ./lclc/messung_hash.txt
#cat benchmark_run_btree.txt | ../sqlite_binary >> ./lclc/messung_btree.txt
done

21
benchmarks/run_rangequeries.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
# script for executing benchmark for range queries
# create/clear benchmark subdirectory
mkdir -p rangequeries
rm -rf rangequeries/*
# copy raw files to correct location
cp /home/kreft/benchmark/benchmarks/fill_ranges_sqlite ./fill.txt
cp /home/kreft/benchmark/benchmarks/mixed_ranges_sqlite ./mixed.txt
echo "Executing range query benchmark"
for run in 1 2 3 4 5
do
echo "Executing run $run"
cat benchmark_run.txt | ../sqlite_binary >> ./rangequeries/messung.txt
#cat benchmark_run_hash.txt | ../sqlite_binary >> ./rangequeries/messung_hash.txt
echo "Executing run $run with btree"
cat benchmark_run_btree.txt | ../sqlite_binary >> ./rangequeries/messung_btree.txt
done

View File

@ -1,8 +1,11 @@
#include <stdio.h> #include <chrono>
#include "sqlite3.h"
#include <iostream>
#include <string.h>
#include <fstream> #include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include "sqlite3.h"
static int callback(void *NotUsed, int argc, char **argv, char **azColName){ static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i; int i;
@ -20,7 +23,9 @@ int main(int argc, char **argv){
bool run = true; bool run = true;
bool movies_db_loaded = false; bool movies_loaded = false;
bool fill_loaded = false;
bool mixed_loaded = false;
rc = sqlite3_open(argv[1], &db); rc = sqlite3_open(argv[1], &db);
if( rc ){ if( rc ){
@ -38,15 +43,15 @@ int main(int argc, char **argv){
//std::cout << input << std::endl; //std::cout << input << std::endl;
if(input == "exit") if(input == "exit" || input == "quit")
{ {
run = false; run = false;
} }
else if(input == "load movies") else if(input == "load movies" && !movies_loaded)
{ {
std::cout << "Loading movies" << std::endl; std::cout << "Loading movies" << std::endl;
std::ifstream moviesfile; std::ifstream moviesfile;
moviesfile.open("transaction.txt"); moviesfile.open("movies.txt");
std::string instruction; std::string instruction;
while (std::getline(moviesfile, instruction)) while (std::getline(moviesfile, instruction))
@ -62,10 +67,62 @@ int main(int argc, char **argv){
fprintf(stderr, "SQL error: %s\n", zErrMsg); fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg); sqlite3_free(zErrMsg);
} }
delete(instructionchars); delete[](instructionchars);
} }
movies_loaded = true;
std::cout << "Done" << std::endl; std::cout << "Done" << std::endl;
} }
else if( input == "load fill" && !fill_loaded ) {
std::ifstream is("fill.txt");
std::string line;
std::vector<char*> instructions;
while (getline(is,line)) {
char *linechars = new char[line.length() + 1];
strcpy(linechars, line.c_str());
instructions.emplace_back(linechars);
//delete[](linechars);
}
std::cout << "Loading fill file..." << std::endl;
std::chrono::time_point<std::chrono::high_resolution_clock> start;
start = std::chrono::high_resolution_clock::now();
for( char* instr : instructions) {
rc = sqlite3_exec(db, instr, callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
}
fill_loaded = true;
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << "done, fill file loaded in " << diff.count() * 1000 << "ms" << std::endl;
}
// lädt anderes einkompiliertes File zeilenweise
else if( input == "load mixed" && !mixed_loaded ) {
std::ifstream is("mixed.txt");
std::string line;
std::vector<char*> instructions;
while (getline(is,line)) {
char *linechars = new char[line.length() + 1];
strcpy(linechars, line.c_str());
instructions.emplace_back(linechars);
}
std::cout << "Loading mixed file..." << std::endl;
std::chrono::time_point<std::chrono::high_resolution_clock> start;
start = std::chrono::high_resolution_clock::now();
for( char* instr : instructions) {
rc = sqlite3_exec(db, instr, callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
}
mixed_loaded = true;
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << "done, mixed file loaded in " << diff.count() * 1000 << "ms" << std::endl;
}
else else
{ {
std::cout << "Executing input" << std::endl; std::cout << "Executing input" << std::endl;
@ -76,7 +133,7 @@ int main(int argc, char **argv){
fprintf(stderr, "SQL error: %s\n", zErrMsg); fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg); sqlite3_free(zErrMsg);
} }
delete(inputchars); delete[](inputchars);
} }
} }
sqlite3_close(db); sqlite3_close(db);