Skip to content

Commit

Permalink
Updated Benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Griezn committed Dec 16, 2024
1 parent 247aa92 commit 0b3774c
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 58 deletions.
144 changes: 119 additions & 25 deletions benchmark/Query1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ where {
#include "data/traffic_data.hpp"

extern "C" {
#include "defs.h"
#include "query.h"
#include "file_source.h"
#include "mutli_source.h"
}

bool natural_join(const triple_t in1, const triple_t in2)
Expand All @@ -58,65 +56,161 @@ bool filter_obs_id(const triple_t in)
return in.predicate == SOSA_MADE_BY_SENSOR;
}

bool filter_id(const triple_t in)
{
return in.predicate == SOSA_OBSERVATION;
}

bool check_join_main1(const triple_t in1, const triple_t in2)
{
return in1.predicate == SOSA_OBSERVATION && in2.predicate == SOSA_OBSERVATION;
}

static void query1(benchmark::State& state)
{
source_t *source1 = create_file_source("../../benchmark/data/AarhusTrafficData182955.bin", 1, 255);
source_t *source2 = create_file_source("../../benchmark/data/AarhusTrafficData158505.bin", 1, 255);
source_t *msource = create_multi_source();
sink_t *msink = create_multi_sink();
source_t *source1 = create_file_source("../../benchmark/data/AarhusTrafficData182955.bin", 4);
source_t *source2 = create_file_source("../../benchmark/data/AarhusTrafficData158505.bin", 4);
sink_t *sink = create_file_sink();

window_params_t wparams = {255, 255, source1};
operator_t window_op = {
.type = WINDOW,
.left = nullptr,
.right = nullptr,
.params = {.window = wparams}
};

window_params_t wparams2 = {255, 255, source2};
operator_t window_op2 = {
.type = WINDOW,
.left = nullptr,
.right = nullptr,
.params = {.window = wparams2}
};

multi_source_add(msource, source1);
multi_source_add(msource, source2);

filter_check_t obs_prop[1] = {filter_obs_prop};
operator_t select_obs_prop = {
operator_t filter_obs_prop = {
.type = FILTER,
.left = nullptr,
.left = &window_op,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = obs_prop}}
};

filter_check_t has_value[1] = {filter_has_value};
operator_t select_has_value = {
operator_t filter_has_value = {
.type = FILTER,
.left = nullptr,
.left = &window_op,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = has_value}}
};

join_check_t cond[1] = {natural_join};
operator_t join_val_obs = {
.type = JOIN,
.left = &filter_obs_prop,
.right = &filter_has_value,
.params = {.join = {.size = 1, .checks = cond}}
};

filter_check_t obs_id[1] = {filter_obs_id};
operator_t select_obs_id = {
operator_t filter_obs_id = {
.type = FILTER,
.left = nullptr,
.left = &window_op,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = obs_id}}
};

join_check_t cond[1] = {natural_join};
operator_t join1 = {
filter_check_t _id[1] = {filter_id};
operator_t filter_id = {
.type = FILTER,
.left = &window_op,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = _id}}
};

operator_t join_obs_id_id = {
.type = JOIN,
.left = &select_obs_prop,
.right = &select_has_value,
.left = &filter_id,
.right = &filter_obs_id,
.params = {.join = {.size = 1, .checks = cond}}
};

operator_t join2 = {
operator_t join_stream1 = {
.type = JOIN,
.left = &join1,
.right = &select_obs_id,
.left = &join_obs_id_id,
.right = &join_val_obs,
.params = {.join = {.size = 1, .checks = cond}}
};

query_t query = {.root = &join2};
// STREAM 2
operator_t filter_obs_prop2 = {
.type = FILTER,
.left = &window_op2,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = obs_prop}}
};

operator_t filter_has_value2 = {
.type = FILTER,
.left = &window_op2,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = has_value}}
};

operator_t join_val_obs2 = {
.type = JOIN,
.left = &filter_obs_prop2,
.right = &filter_has_value2,
.params = {.join = {.size = 1, .checks = cond}}
};

operator_t filter_obs_id2 = {
.type = FILTER,
.left = &window_op2,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = obs_id}}
};

operator_t filter_id2 = {
.type = FILTER,
.left = &window_op2,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = _id}}
};

operator_t join_obs_id_id2 = {
.type = JOIN,
.left = &filter_id2,
.right = &filter_obs_id2,
.params = {.join = {.size = 1, .checks = cond}}
};

operator_t join_stream2 = {
.type = JOIN,
.left = &join_obs_id_id2,
.right = &join_val_obs2,
.params = {.join = {.size = 1, .checks = cond}}
};

// JOIN THE 2 STREAMS
join_check_t cond_main[2] = {check_join_main1, natural_join};
operator_t join_main = {
.type = JOIN,
.left = &join_stream1,
.right = &join_stream2,
.params = {.join = {.size = 2, .checks = cond_main}}
};

query_t query = {.root = &join_main};

for (auto _ : state) {
execute_query(&query, msource, msink);
execute_query(&query, sink);
}

free_multi_sink(msink);
free_multi_source(msource);
free_file_source(source1);
free_file_source(source2);
free_file_sink(sink);
}

BENCHMARK(query1);
92 changes: 59 additions & 33 deletions benchmark/QueryBenchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "data/traffic_data.hpp"

extern "C" {
#include "defs.h"
#include "generator.h"
#include "query.h"
#include "file_source.h"
Expand Down Expand Up @@ -46,6 +45,19 @@ bool check_filter5(const triple_t in)

static void BM_ExecuteQuery(benchmark::State& state)
{
query_t query;
// Create generator source and sink
source_t *source = create_generator_source(3);
sink_t *sink = create_generator_sink();

window_params_t wparams = {36, 36, source};
operator_t window_op = {
.type = WINDOW,
.left = nullptr,
.right = nullptr,
.params = {.window = wparams}
};

// Setup the query
filter_check_t conditions1[1] = {check_filter};
filter_check_t conditions2[1] = {check_filter3};
Expand All @@ -56,14 +68,14 @@ static void BM_ExecuteQuery(benchmark::State& state)

operator_t filter_has_skill = {
.type = FILTER,
.left = nullptr,
.left = &window_op,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = conditions1}}
};

operator_t filter_req_skill = {
.type = FILTER,
.left = nullptr,
.left = &window_op,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = conditions2}}
};
Expand All @@ -77,7 +89,7 @@ static void BM_ExecuteQuery(benchmark::State& state)

operator_t filter_has_age = {
.type = FILTER,
.left = nullptr,
.left = &window_op,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = conditions4}}
};
Expand All @@ -96,20 +108,16 @@ static void BM_ExecuteQuery(benchmark::State& state)
.params = {.filter = {.size = 1, .checks = conditions6}}
};

query_t query = {.root = &filter_older};

// Create generator source and sink
source_t *gsource = create_generator_source();
sink_t *gsink = create_generator_sink();
query = {.root = &filter_older};

// Benchmark loop
for (auto _ : state) {
execute_query(&query, gsource, gsink);
execute_query(&query, sink);
}

// Clean up
free_generator_source(gsource);
free_generator_sink(gsink);
free_generator_source(source);
free_generator_sink(sink);
}

BENCHMARK(BM_ExecuteQuery);
Expand All @@ -120,51 +128,69 @@ bool check_join3(const triple_t in1, const triple_t in2)
return in1.subject == in2.subject;
}

bool filter_obs_propD(const triple_t in)
{
return in.predicate == SOSA_OBSERVED_PROPERTY;
}

static void BM_traffic_select_join(benchmark::State& state)
bool filter_has_valueD(const triple_t in)
{
uint8_t predicates[1] = {SOSA_OBSERVATION};
uint8_t predicates2[1] = {SOSA_HAS_SIMPLE_RESULT};
join_check_t conditions3[1] = {check_join3};
return in.predicate == SOSA_HAS_SIMPLE_RESULT;
}


operator_t select_obs = {
.type = SELECT,
static void BM_traffic_filter_join(benchmark::State& state)
{
query_t query;

// Create generator source and sink
source_t *source = create_file_source("../../benchmark/data/traffic_triples1.bin", 2);
sink_t *sink = create_file_sink();

window_params_t wparams = {255, 255, source};
operator_t window_op = {
.type = WINDOW,
.left = nullptr,
.right = nullptr,
.params = {.select = {.size = 1, .colums = predicates}}
.params = {.window = wparams}
};

operator_t select_simple_result = {
.type = SELECT,
.left = nullptr,
filter_check_t obs_prop[1] = {filter_obs_propD};
operator_t filter_obs = {
.type = FILTER,
.left = &window_op,
.right = nullptr,
.params = {.filter = {.size = 1, .checks = obs_prop}}
};

filter_check_t has_value[1] = {filter_has_valueD};
operator_t filter_simple_result = {
.type = FILTER,
.left = &window_op,
.right = nullptr,
.params = {.select = {.size = 1, .colums = predicates2}}
.params = {.filter = {.size = 1, .checks = has_value}}
};

join_check_t conditions3[1] = {check_join3};
operator_t join_obs = {
.type = JOIN,
.left = &select_obs,
.right = &select_simple_result,
.left = &filter_obs,
.right = &filter_simple_result,
.params = {.join = {.size = 1, .checks = conditions3}}
};


query_t query = {.root = &join_obs};

// Create generator source and sink
source_t *source = create_file_source("../../benchmark/data/traffic_triples1.bin", 1, 255);
sink_t *sink = create_file_sink();
query = {.root = &join_obs};

// Benchmark loop
for (auto _ : state) {
execute_query(&query, source, sink);
execute_query(&query, sink);
}

// Clean up
free_file_source(source);
free_file_sink(sink);
}

BENCHMARK(BM_traffic_select_join);
BENCHMARK(BM_traffic_filter_join);

BENCHMARK_MAIN();

0 comments on commit 0b3774c

Please sign in to comment.