From 37155a96292e1157c72e039b37187700890d5a16 Mon Sep 17 00:00:00 2001 From: Martin Farenholtz Date: Wed, 31 Mar 2021 12:37:15 +0200 Subject: [PATCH] added benchmark scripts --- README.md | 6 +-- benchmarks/benchmark_run.txt | 5 ++ benchmarks/benchmark_run_btree.txt | 5 ++ benchmarks/benchmark_run_hash.txt | 5 ++ benchmarks/run_benchmarks.sh | 40 ++++++++++++++++ benchmarks/run_hashtable.sh | 22 +++++++++ benchmarks/run_hchc.sh | 33 +++++++++++++ benchmarks/run_hclc.sh | 20 ++++++++ benchmarks/run_lclc.sh | 20 ++++++++ benchmarks/run_rangequeries.sh | 21 ++++++++ execution.cpp | 77 ++++++++++++++++++++++++++---- 11 files changed, 241 insertions(+), 13 deletions(-) create mode 100644 benchmarks/benchmark_run.txt create mode 100644 benchmarks/benchmark_run_btree.txt create mode 100644 benchmarks/benchmark_run_hash.txt create mode 100755 benchmarks/run_benchmarks.sh create mode 100755 benchmarks/run_hashtable.sh create mode 100755 benchmarks/run_hchc.sh create mode 100755 benchmarks/run_hclc.sh create mode 100755 benchmarks/run_lclc.sh create mode 100755 benchmarks/run_rangequeries.sh diff --git a/README.md b/README.md index d8ec8ac..add9af7 100644 --- a/README.md +++ b/README.md @@ -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:"` \ No newline at end of file diff --git a/benchmarks/benchmark_run.txt b/benchmarks/benchmark_run.txt new file mode 100644 index 0000000..1c410ed --- /dev/null +++ b/benchmarks/benchmark_run.txt @@ -0,0 +1,5 @@ +CREATE TABLE benchmarktable(ID long, STR char(32)) +load fill +load mixed +select * from benchmarktable +quit diff --git a/benchmarks/benchmark_run_btree.txt b/benchmarks/benchmark_run_btree.txt new file mode 100644 index 0000000..8602f4e --- /dev/null +++ b/benchmarks/benchmark_run_btree.txt @@ -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 diff --git a/benchmarks/benchmark_run_hash.txt b/benchmarks/benchmark_run_hash.txt new file mode 100644 index 0000000..fc0b717 --- /dev/null +++ b/benchmarks/benchmark_run_hash.txt @@ -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 diff --git a/benchmarks/run_benchmarks.sh b/benchmarks/run_benchmarks.sh new file mode 100755 index 0000000..d4391a6 --- /dev/null +++ b/benchmarks/run_benchmarks.sh @@ -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 \ No newline at end of file diff --git a/benchmarks/run_hashtable.sh b/benchmarks/run_hashtable.sh new file mode 100755 index 0000000..e7a0ff0 --- /dev/null +++ b/benchmarks/run_hashtable.sh @@ -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 \ No newline at end of file diff --git a/benchmarks/run_hchc.sh b/benchmarks/run_hchc.sh new file mode 100755 index 0000000..4b378c2 --- /dev/null +++ b/benchmarks/run_hchc.sh @@ -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 \ No newline at end of file diff --git a/benchmarks/run_hclc.sh b/benchmarks/run_hclc.sh new file mode 100755 index 0000000..a9c5d72 --- /dev/null +++ b/benchmarks/run_hclc.sh @@ -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 \ No newline at end of file diff --git a/benchmarks/run_lclc.sh b/benchmarks/run_lclc.sh new file mode 100755 index 0000000..8ab978a --- /dev/null +++ b/benchmarks/run_lclc.sh @@ -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 \ No newline at end of file diff --git a/benchmarks/run_rangequeries.sh b/benchmarks/run_rangequeries.sh new file mode 100755 index 0000000..8eae0b8 --- /dev/null +++ b/benchmarks/run_rangequeries.sh @@ -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 \ No newline at end of file diff --git a/execution.cpp b/execution.cpp index 4dbbc8d..ac465b3 100644 --- a/execution.cpp +++ b/execution.cpp @@ -1,8 +1,11 @@ -#include -#include "sqlite3.h" -#include -#include +#include #include +#include +#include +#include +#include + +#include "sqlite3.h" static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; @@ -20,7 +23,9 @@ int main(int argc, char **argv){ 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); if( rc ){ @@ -38,15 +43,15 @@ int main(int argc, char **argv){ //std::cout << input << std::endl; - if(input == "exit") + if(input == "exit" || input == "quit") { run = false; } - else if(input == "load movies") + else if(input == "load movies" && !movies_loaded) { std::cout << "Loading movies" << std::endl; std::ifstream moviesfile; - moviesfile.open("transaction.txt"); + moviesfile.open("movies.txt"); std::string instruction; while (std::getline(moviesfile, instruction)) @@ -62,10 +67,62 @@ int main(int argc, char **argv){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } - delete(instructionchars); + delete[](instructionchars); } + movies_loaded = true; std::cout << "Done" << std::endl; } + else if( input == "load fill" && !fill_loaded ) { + std::ifstream is("fill.txt"); + std::string line; + std::vector 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 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 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 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 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 diff = end - start; + std::cout << "done, mixed file loaded in " << diff.count() * 1000 << "ms" << std::endl; + } + else { std::cout << "Executing input" << std::endl; @@ -76,7 +133,7 @@ int main(int argc, char **argv){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } - delete(inputchars); + delete[](inputchars); } } sqlite3_close(db);