From 6cd63e8ac94d6fa4a16a9df6bccaf1a7df34626a Mon Sep 17 00:00:00 2001 From: florijan Date: Fri, 18 Aug 2017 14:47:20 +0200 Subject: [PATCH] Expansion benchmark added Summary: It's purpose is to illustrate that currently expansion from a single node (with a fixed degree) does not execute in consistent time, but the execution time depends on the rest of the graph (that's disconnected). Current benchmark results: ``` florijan@florxps:~/Memgraph/memgraph/build$ ./tests/benchmark/expansion Run on (8 X 3500 MHz CPU s) 2017-08-17 16:06:30 ***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead. ***WARNING*** Library was built as DEBUG. Timings may be affected. Benchmark Time CPU Iterations ------------------------------------------------------------------------- ExpansionBenchFixture/Match/1 0 ms 0 ms 4903 ExpansionBenchFixture/Match/1024 0 ms 0 ms 4785 ExpansionBenchFixture/Match/1024k 0 ms 0 ms 4623 ExpansionBenchFixture/Expand/1 9 ms 9 ms 83 ExpansionBenchFixture/Expand/1024 20 ms 20 ms 41 ExpansionBenchFixture/Expand/1024k 3430 ms 3430 ms 1 ``` Reviewers: mislav.bradac, buda Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D676 --- .../concurrent/skiplist_gc.hpp | 4 +- tests/benchmark/expansion.cpp | 74 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests/benchmark/expansion.cpp diff --git a/src/data_structures/concurrent/skiplist_gc.hpp b/src/data_structures/concurrent/skiplist_gc.hpp index 09f6192d9..43cda570a 100644 --- a/src/data_structures/concurrent/skiplist_gc.hpp +++ b/src/data_structures/concurrent/skiplist_gc.hpp @@ -31,8 +31,8 @@ template class SkipListGC { public: explicit SkipListGC() { - executor_job_id_ = GetExecutioner().RegisterJob( - std::bind(&SkipListGC::GarbageCollect, this)); + executor_job_id_ = + GetExecutioner().RegisterJob([this]() { GarbageCollect(); }); } ~SkipListGC() { diff --git a/tests/benchmark/expansion.cpp b/tests/benchmark/expansion.cpp new file mode 100644 index 000000000..034cf6e38 --- /dev/null +++ b/tests/benchmark/expansion.cpp @@ -0,0 +1,74 @@ +#include +#include +#include + +#include "communication/result_stream_faker.hpp" +#include "database/dbms.hpp" +#include "query/interpreter.hpp" +#include "query/typed_value.hpp" + +class ExpansionBenchFixture : public benchmark::Fixture { + protected: + std::experimental::optional dbms_; + query::Interpreter interpeter_; + + void SetUp(const benchmark::State &state) override { + if (!dbms_) + dbms_.emplace(); + auto dba = dbms_->active(); + for (int i = 0; i < state.range(0); i++) dba->InsertVertex(); + + // the fixed part is one vertex expanding to 1000 others + auto start = dba->InsertVertex(); + start.add_label(dba->Label("Start")); + auto edge_type = dba->EdgeType("edge_type"); + for (int i = 0; i < 1000; i++) { + auto dest = dba->InsertVertex(); + dba->InsertEdge(start, dest, edge_type); + } + dba->Commit(); + } + + void TearDown(const benchmark::State &) override { + auto dba = dbms_->active(); + for (auto vertex : dba->Vertices(false)) dba->DetachRemoveVertex(vertex); + dba->Commit(); + } +}; + +BENCHMARK_DEFINE_F(ExpansionBenchFixture, Match)(benchmark::State &state) { + auto query = "MATCH (s:Start) return s"; + auto dba = dbms_->active(); + while (state.KeepRunning()) { + ResultStreamFaker results; + interpeter_.Interpret(query, *dba, results, {}); + } +} + +BENCHMARK_REGISTER_F(ExpansionBenchFixture, Match) + ->RangeMultiplier(1024) + ->Range(1, 1 << 20) + ->Unit(benchmark::kMillisecond); + +BENCHMARK_DEFINE_F(ExpansionBenchFixture, Expand)(benchmark::State &state) { + auto query = "MATCH (s:Start) WITH s MATCH (s)--(d) RETURN count(d)"; + auto dba = dbms_->active(); + while (state.KeepRunning()) { + ResultStreamFaker results; + interpeter_.Interpret(query, *dba, results, {}); + } +} + +BENCHMARK_REGISTER_F(ExpansionBenchFixture, Expand) + ->RangeMultiplier(1024) + ->Range(1, 1 << 20) + ->Unit(benchmark::kMillisecond); + +int main(int argc, char **argv) { + gflags::ParseCommandLineFlags(&argc, &argv, true); + google::InitGoogleLogging(argv[0]); + + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); + return 0; +}