From f5cf9c72d2abe3d52fe1959e79d1634fd143416a Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Tue, 4 Oct 2016 15:09:21 +0200 Subject: [PATCH] skiplist benchmark --- CMakeLists.txt | 6 +++++ benchmark/CMakeLists.txt | 8 +++++++ benchmark/skiplist.cpp | 29 ++++++++++++++++++++++++ config/memgraph.yaml | 2 +- include/utils/time/timer.hpp | 44 ++++++++++++++++++++++++++++++++++++ poc/CMakeLists.txt | 10 ++++---- poc/profile.cpp | 36 ++++++++++++----------------- 7 files changed, 108 insertions(+), 27 deletions(-) create mode 100644 benchmark/CMakeLists.txt create mode 100644 benchmark/skiplist.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 11a4c99fb..f3c7de67f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -376,6 +376,8 @@ option(TOOLS "Build tool executables" ON) message(STATUS "TOOLS binaries: ${TOOLS}") option(TESTS "Build test binaries" ON) message(STATUS "TESTS binaries: ${TESTS}") +option(BENCHMARK "Build benchmark binaries" ON) +message(STATUS "BENCHMARK binaries: ${BENCHMARK}") # -- binaries ----------------------------------------------------------------- # -- barrier - this is the way how the engine is isolated so it can be shipped # wherever, the code is completely hidden behind the barrier, during the @@ -511,6 +513,10 @@ if (POC) add_subdirectory(poc) endif() +# benchmark binaries +if (BENCHMARK) + add_subdirectory(benchmark) +endif() # memgraph build name execute_process( diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt new file mode 100644 index 000000000..55ec3b973 --- /dev/null +++ b/benchmark/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) + +project(memgraph_benchmark) + +add_executable(skiplist_benchmark skiplist.cpp) +target_link_libraries(skiplist_benchmark Threads::Threads) +target_link_libraries(skiplist_benchmark memgraph) +target_link_libraries(skiplist_benchmark ${fmt_static_lib}) diff --git a/benchmark/skiplist.cpp b/benchmark/skiplist.cpp new file mode 100644 index 000000000..776ed64f8 --- /dev/null +++ b/benchmark/skiplist.cpp @@ -0,0 +1,29 @@ +#include + +#include "data_structures/concurrent/skiplist.hpp" +#include "utils/time/timer.hpp" + +int main(void) +{ + SkipList skiplist; + + // insert a bunch of elements + { + int iters_no = 1000000; + auto skiplist_accessor = skiplist.access(); + Stopwatch sw; + + sw.Start(); + for (int i = 0; i < iters_no; ++i) + { + skiplist_accessor.insert(std::move(i)); + } + + std::cout << "Skiplist contains: " + << skiplist_accessor.size() + << " elements" + << std::endl; + } + + return 0; +} diff --git a/config/memgraph.yaml b/config/memgraph.yaml index d29fa9425..7ba6c4a8c 100644 --- a/config/memgraph.yaml +++ b/config/memgraph.yaml @@ -4,5 +4,5 @@ barrier_template_cpu_cpp_path: "./template/barrier_template_code_cpu.cpp" template_cpu_hpp_path: "./template/template_code_cpu.hpp" snapshots_path: "snapshots" cleaning_cycle_sec: "300" -snapshot_cycle_sec: "3600" +snapshot_cycle_sec: "60" max_retained_snapshots: "3" diff --git a/include/utils/time/timer.hpp b/include/utils/time/timer.hpp index ac5ad95e7..e8332c5b3 100644 --- a/include/utils/time/timer.hpp +++ b/include/utils/time/timer.hpp @@ -22,3 +22,47 @@ auto timer(F func, Args &&... args) func(std::forward(args)...); return to_duration(time_now() - start_time); } + +// idea from Optimized C++ Kurt Guntheroth 2016 +// TODO: make more modular and easier to use +class Stopwatch +{ +public: + Stopwatch() : start(std::chrono::system_clock::time_point::min()) {} + + void Clear() + { + start = std::chrono::system_clock::time_point::min(); + } + + bool IsStarted() const + { + return (start != std::chrono::system_clock::time_point::min()); + } + + void Start() + { + start = std::chrono::system_clock::now(); + } + + unsigned long GetMs() + { + if (IsStarted()) + { + std::chrono::system_clock::duration diff; + diff = std::chrono::system_clock::now() - start; + return (unsigned) (std::chrono::duration_cast(diff).count()); + } + + return 0; + } + + ~Stopwatch() + { + std::cout << "Time: " << GetMs() << "ms" << std::endl; + } + +private: + std::chrono::system_clock::time_point start; + +}; diff --git a/poc/CMakeLists.txt b/poc/CMakeLists.txt index fe6b87353..ccad1fadf 100644 --- a/poc/CMakeLists.txt +++ b/poc/CMakeLists.txt @@ -11,11 +11,11 @@ target_link_libraries(poc_astar Threads::Threads) target_link_libraries(poc_astar ${fmt_static_lib}) target_link_libraries(poc_astar ${yaml_static_lib}) -add_executable(profile profile.cpp) -target_link_libraries(profile memgraph) -target_link_libraries(profile Threads::Threads) -target_link_libraries(profile ${fmt_static_lib}) -target_link_libraries(profile ${yaml_static_lib}) +add_executable(powerlinx_profile profile.cpp) +target_link_libraries(powerlinx_profile memgraph) +target_link_libraries(powerlinx_profile Threads::Threads) +target_link_libraries(powerlinx_profile ${fmt_static_lib}) +target_link_libraries(powerlinx_profile ${yaml_static_lib}) add_executable(csv_import csv_import.cpp) target_link_libraries(csv_import memgraph) diff --git a/poc/profile.cpp b/poc/profile.cpp index b74c9674c..41d3ff5c4 100644 --- a/poc/profile.cpp +++ b/poc/profile.cpp @@ -1,46 +1,46 @@ -#include "profile.hpp" - -#include "barrier/barrier.cpp" - -#include "database/db.hpp" -#include "database/db_accessor.hpp" - #include #include #include #include #include +#include "barrier/barrier.cpp" +#include "database/db.hpp" +#include "database/db_accessor.hpp" #include "communication/bolt/v1/serialization/bolt_serializer.hpp" #include "import/csv_import.hpp" #include "logging/default.hpp" #include "logging/streams/stdout.hpp" #include "utils/command_line/arguments.hpp" +#include "profile.hpp" using namespace std; +// (company, {type_name, score}) using company_profile_type = pair>; -// Accepts flags for csv import. +// Accepted flags for CSV import. // -db name # will create database with that name. -// -s true # will create snapshot of the database after import. +// -s true # will create snapshot of the database after import. int main(int argc, char **argv) { + // initialize logger logging::init_async(); logging::log->pipe(std::make_unique()); + // read program arguments auto para = all_arguments(argc, argv); Db db(get_argument(para, "-db", "powerlinks_profile")); + // import database import_csv_from_arguments(db, para); { DbAccessor t(db); - vector company_profiles; - // QUERY BENCHMARK + // query benchmark auto begin = clock(); int n = for_all_companys(barrier::trans(t), company_profiles); clock_t end = clock(); @@ -51,6 +51,7 @@ int main(int argc, char **argv) return 0; } + // performance statistics cout << endl << "Query duration: " << (elapsed_s / n) * 1000 * 1000 << " [us]" << endl; @@ -67,8 +68,8 @@ int main(int argc, char **argv) int company_id = std::stoi(get_argument(para, "-company_id", "230216")); for (auto &company_profile : company_profiles) { auto prop_vertex_id = t.vertex_property_key("company_id"); - auto db_company_id = *barrier::trans(company_profile.first) - .at(prop_vertex_id).get(); + auto db_company_id = + *barrier::trans(company_profile.first).at(prop_vertex_id).get(); if (db_company_id == company_id) { cout << endl << "CompanyID: " << company_id << endl; for (auto e : company_profile.second) { @@ -77,20 +78,13 @@ int main(int argc, char **argv) } } - // double sum = 0; - // for (auto r : coll) { - // for (auto e : r.second) { - // sum += e.second; - // } - // } - // cout << endl << endl << "Compiler sum " << sum << endl; - t.commit(); } if (get_argument(para, "-s", "false") == "true") { db.snap_engine.make_snapshot(); } + // usleep(1000 * 1000 * 60); return 0;