From f1cdae06179c9963086a390e4625956abf922582 Mon Sep 17 00:00:00 2001 From: Marin Tomic Date: Mon, 19 Feb 2018 16:52:27 +0100 Subject: [PATCH] Add teps and pointwise lookup scenarios Reviewers: mculinovic Reviewed By: mculinovic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1211 --- .../clients/card_fraud_client.cpp | 50 +++++++++++++++---- .../clients/long_running_common.hpp | 2 +- .../groups/card_fraud/point_lookup.run.json | 3 ++ .../groups/card_fraud/teps.run.json | 3 ++ 4 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 tests/macro_benchmark/groups/card_fraud/point_lookup.run.json create mode 100644 tests/macro_benchmark/groups/card_fraud/teps.run.json diff --git a/tests/macro_benchmark/clients/card_fraud_client.cpp b/tests/macro_benchmark/clients/card_fraud_client.cpp index 730985b2a..3b3be37eb 100644 --- a/tests/macro_benchmark/clients/card_fraud_client.cpp +++ b/tests/macro_benchmark/clients/card_fraud_client.cpp @@ -19,12 +19,20 @@ BOOST_CLASS_EXPORT(stats::BatchStatsRes); class CardFraudClient : public TestClient { public: - CardFraudClient(int id, int num_pos, nlohmann::json config) - : TestClient(), rg_(id), num_pos_(num_pos), config_(config) {} + CardFraudClient(int id, int num_pos, int num_cards, int num_transactions, + nlohmann::json config) + : TestClient(), + rg_(id), + num_pos_(num_pos), + num_cards_(num_cards), + num_transactions_(num_transactions), + config_(config) {} private: std::mt19937 rg_; int num_pos_; + int num_cards_; + int num_transactions_; nlohmann::json config_; auto GetFraudulentTransactions() { @@ -53,6 +61,15 @@ class CardFraudClient : public TestClient { {{"id", id}}); } + auto GetTransaction(int id) { + return Execute("MATCH (t:Transaction {id: $id}) RETURN (t)", {{"id", id}}); + } + + auto TepsQuery() { + auto result = Execute("MATCH (u)--(v) RETURN count(1)", {}); + DCHECK(result.records[0][0].ValueInt() == num_transactions_ * 2); + } + auto CompromisePos(int id) { return Execute( "MATCH (p:Pos {id: $id}) " @@ -77,15 +94,21 @@ class CardFraudClient : public TestClient { CompromisePos(pos_id); GetFraudulentTransactions(); ResolvePos(pos_id); + } else if (config_["scenario"] == "teps") { + TepsQuery(); + } else if (config_["scenario"] == "point_lookup") { + std::uniform_int_distribution dist(0, num_transactions_ - 1); + int tx_id = dist(rg_); + GetTransaction(tx_id); } else { LOG(FATAL) << "Should not get here!"; } } }; -int64_t NumPos(BoltClient &client) { - auto result = ExecuteNTimesTillSuccess( - client, "MATCH (n :Pos) RETURN COUNT(n) as cnt;", {}, MAX_RETRIES); +int64_t NumNodesWithLabel(BoltClient &client, std::string label) { + std::string query = fmt::format("MATCH (u :{}) RETURN COUNT(u)", label); + auto result = ExecuteNTimesTillSuccess(client, query, {}, MAX_RETRIES); return result.records[0][0].ValueInt(); } @@ -115,16 +138,23 @@ int main(int argc, char **argv) { std::cin >> config; BoltClient client(FLAGS_address, FLAGS_port, FLAGS_username, FLAGS_password); - int num_pos = NumPos(client); - CreateIndex(client, "Card", "id"); - CreateIndex(client, "Pos", "id"); - CreateIndex(client, "Transaction", "fraud_reported"); + int num_pos = NumNodesWithLabel(client, "Pos"); + int num_cards = NumNodesWithLabel(client, "Card"); + int num_transactions = NumNodesWithLabel(client, "Transaction"); + + CreateIndex(client, "Pos", "id"); + CreateIndex(client, "Card", "id"); + CreateIndex(client, "Transaction", "fraud_reported"); + CreateIndex(client, "Transaction", "id"); LOG(INFO) << "Done building indexes."; + client.Close(); + std::vector> clients; for (int i = 0; i < FLAGS_num_workers; ++i) { - clients.emplace_back(std::make_unique(i, num_pos, config)); + clients.emplace_back(std::make_unique( + i, num_pos, num_cards, num_transactions, config)); } RunMultithreadedTest(clients); diff --git a/tests/macro_benchmark/clients/long_running_common.hpp b/tests/macro_benchmark/clients/long_running_common.hpp index ec5cbf1fc..55eccca9f 100644 --- a/tests/macro_benchmark/clients/long_running_common.hpp +++ b/tests/macro_benchmark/clients/long_running_common.hpp @@ -150,7 +150,7 @@ void RunMultithreadedTest(std::vector> &clients) { auto it = aggregated_query_stats.insert({stat.first, DecodedValue(0.0)}) .first; it->second = - (it->second.ValueDouble() * old_count + stat.second * new_count) / + (it->second.ValueDouble() * old_count + stat.second) / (old_count + new_count); } } diff --git a/tests/macro_benchmark/groups/card_fraud/point_lookup.run.json b/tests/macro_benchmark/groups/card_fraud/point_lookup.run.json new file mode 100644 index 000000000..df7cb6f59 --- /dev/null +++ b/tests/macro_benchmark/groups/card_fraud/point_lookup.run.json @@ -0,0 +1,3 @@ +{ + "scenario": "point_lookup" +} diff --git a/tests/macro_benchmark/groups/card_fraud/teps.run.json b/tests/macro_benchmark/groups/card_fraud/teps.run.json new file mode 100644 index 000000000..5c30fa972 --- /dev/null +++ b/tests/macro_benchmark/groups/card_fraud/teps.run.json @@ -0,0 +1,3 @@ +{ + "scenario": "teps" +}