Add tx creation scenario
Summary: ^^ Reviewers: buda, mculinovic Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1225
This commit is contained in:
parent
2a99b9c80e
commit
604ebf9d1e
@ -17,23 +17,16 @@ BOOST_CLASS_EXPORT(stats::StatsRes);
|
|||||||
BOOST_CLASS_EXPORT(stats::BatchStatsReq);
|
BOOST_CLASS_EXPORT(stats::BatchStatsReq);
|
||||||
BOOST_CLASS_EXPORT(stats::BatchStatsRes);
|
BOOST_CLASS_EXPORT(stats::BatchStatsRes);
|
||||||
|
|
||||||
|
std::atomic<int> num_pos;
|
||||||
|
std::atomic<int> num_cards;
|
||||||
|
std::atomic<int> num_transactions;
|
||||||
|
|
||||||
class CardFraudClient : public TestClient {
|
class CardFraudClient : public TestClient {
|
||||||
public:
|
public:
|
||||||
CardFraudClient(int id, int num_pos, int num_cards, int num_transactions,
|
CardFraudClient(int id) : TestClient(), rg_(id) {}
|
||||||
nlohmann::json config)
|
|
||||||
: TestClient(),
|
|
||||||
rg_(id),
|
|
||||||
num_pos_(num_pos),
|
|
||||||
num_cards_(num_cards),
|
|
||||||
num_transactions_(num_transactions),
|
|
||||||
config_(config) {}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mt19937 rg_;
|
std::mt19937 rg_;
|
||||||
int num_pos_;
|
|
||||||
int num_cards_;
|
|
||||||
int num_transactions_;
|
|
||||||
nlohmann::json config_;
|
|
||||||
|
|
||||||
auto GetFraudulentTransactions() {
|
auto GetFraudulentTransactions() {
|
||||||
return Execute(
|
return Execute(
|
||||||
@ -67,7 +60,7 @@ class CardFraudClient : public TestClient {
|
|||||||
|
|
||||||
auto TepsQuery() {
|
auto TepsQuery() {
|
||||||
auto result = Execute("MATCH (u)--(v) RETURN count(1)", {});
|
auto result = Execute("MATCH (u)--(v) RETURN count(1)", {});
|
||||||
DCHECK(result.records[0][0].ValueInt() == num_transactions_ * 2);
|
DCHECK(result.records[0][0].ValueInt() == num_transactions * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto CompromisePos(int id) {
|
auto CompromisePos(int id) {
|
||||||
@ -79,29 +72,56 @@ class CardFraudClient : public TestClient {
|
|||||||
{{"id", id}});
|
{{"id", id}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto CreateTransaction(int pos_id, int card_id) {
|
||||||
|
return Execute(
|
||||||
|
"MATCH (p:Pos {id: $pos_id}), (c:Card {id: $card_id}) "
|
||||||
|
"CREATE (t:Transaction {id: $tx_id, fraud_reported: false}) "
|
||||||
|
"CREATE (c)<-[:Using]-(t)-[:At]->(p)",
|
||||||
|
{{"pos_id", pos_id},
|
||||||
|
{"card_id", card_id},
|
||||||
|
{"tx_id", num_transactions++}});
|
||||||
|
}
|
||||||
|
|
||||||
|
auto CreateTransactionWithoutEdge(int pos_id, int card_id) {
|
||||||
|
return Execute(
|
||||||
|
"MATCH (p:Pos {id: $pos_id}), (c:Card {id: $card_id}) "
|
||||||
|
"CREATE (t:Transaction {id: $tx_id, fraud_reported: false})",
|
||||||
|
{{"pos_id", pos_id},
|
||||||
|
{"card_id", card_id},
|
||||||
|
{"tx_id", num_transactions++}});
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Step() override {
|
virtual void Step() override {
|
||||||
if (config_["scenario"] == "read_only") {
|
if (FLAGS_scenario == "read_only") {
|
||||||
std::uniform_int_distribution<int> dist(0, 1);
|
std::uniform_int_distribution<int> dist(0, 1);
|
||||||
if (dist(rg_)) {
|
if (dist(rg_)) {
|
||||||
GetFraudulentTransactions();
|
GetFraudulentTransactions();
|
||||||
} else {
|
} else {
|
||||||
GetCompromisedPos();
|
GetCompromisedPos();
|
||||||
}
|
}
|
||||||
} else if (config_["scenario"] == "read_write") {
|
} else if (FLAGS_scenario == "read_write") {
|
||||||
std::uniform_int_distribution<int> dist(0, num_pos_ - 1);
|
std::uniform_int_distribution<int> dist(0, num_pos - 1);
|
||||||
int pos_id = dist(rg_);
|
int pos_id = dist(rg_);
|
||||||
CompromisePos(pos_id);
|
CompromisePos(pos_id);
|
||||||
GetFraudulentTransactions();
|
GetFraudulentTransactions();
|
||||||
ResolvePos(pos_id);
|
ResolvePos(pos_id);
|
||||||
} else if (config_["scenario"] == "teps") {
|
} else if (FLAGS_scenario == "teps") {
|
||||||
TepsQuery();
|
TepsQuery();
|
||||||
} else if (config_["scenario"] == "point_lookup") {
|
} else if (FLAGS_scenario == "point_lookup") {
|
||||||
std::uniform_int_distribution<int> dist(0, num_transactions_ - 1);
|
std::uniform_int_distribution<int> dist(0, num_transactions - 1);
|
||||||
int tx_id = dist(rg_);
|
int tx_id = dist(rg_);
|
||||||
GetTransaction(tx_id);
|
GetTransaction(tx_id);
|
||||||
|
} else if (FLAGS_scenario == "create_tx") {
|
||||||
|
std::uniform_int_distribution<int> dist_pos(0, num_pos - 1);
|
||||||
|
std::uniform_int_distribution<int> dist_card(0, num_cards - 1);
|
||||||
|
CreateTransaction(dist_pos(rg_), dist_card(rg_));
|
||||||
|
} else if (FLAGS_scenario == "create_tx_without_edge") {
|
||||||
|
std::uniform_int_distribution<int> dist_pos(0, num_pos - 1);
|
||||||
|
std::uniform_int_distribution<int> dist_card(0, num_cards - 1);
|
||||||
|
CreateTransactionWithoutEdge(dist_pos(rg_), dist_card(rg_));
|
||||||
} else {
|
} else {
|
||||||
LOG(FATAL) << "Should not get here!";
|
LOG(FATAL) << "Should not get here: unknown scenario!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -134,14 +154,11 @@ int main(int argc, char **argv) {
|
|||||||
stats::InitStatsLogging(
|
stats::InitStatsLogging(
|
||||||
fmt::format("client.long_running.{}.{}", FLAGS_group, FLAGS_scenario));
|
fmt::format("client.long_running.{}.{}", FLAGS_group, FLAGS_scenario));
|
||||||
|
|
||||||
nlohmann::json config;
|
|
||||||
std::cin >> config;
|
|
||||||
|
|
||||||
BoltClient client(FLAGS_address, FLAGS_port, FLAGS_username, FLAGS_password);
|
BoltClient client(FLAGS_address, FLAGS_port, FLAGS_username, FLAGS_password);
|
||||||
|
|
||||||
int num_pos = NumNodesWithLabel(client, "Pos");
|
num_pos.store(NumNodesWithLabel(client, "Pos"));
|
||||||
int num_cards = NumNodesWithLabel(client, "Card");
|
num_cards.store(NumNodesWithLabel(client, "Card"));
|
||||||
int num_transactions = NumNodesWithLabel(client, "Transaction");
|
num_transactions.store(NumNodesWithLabel(client, "Transaction"));
|
||||||
|
|
||||||
CreateIndex(client, "Pos", "id");
|
CreateIndex(client, "Pos", "id");
|
||||||
CreateIndex(client, "Card", "id");
|
CreateIndex(client, "Card", "id");
|
||||||
@ -153,8 +170,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::vector<std::unique_ptr<TestClient>> clients;
|
std::vector<std::unique_ptr<TestClient>> clients;
|
||||||
for (int i = 0; i < FLAGS_num_workers; ++i) {
|
for (int i = 0; i < FLAGS_num_workers; ++i) {
|
||||||
clients.emplace_back(std::make_unique<CardFraudClient>(
|
clients.emplace_back(std::make_unique<CardFraudClient>(i));
|
||||||
i, num_pos, num_cards, num_transactions, config));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RunMultithreadedTest(clients);
|
RunMultithreadedTest(clients);
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"scenario": "point_lookup"
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"scenario": "read_only"
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"scenario": "read_write"
|
|
||||||
}
|
|
1
tests/macro_benchmark/groups/card_fraud/run.json
Normal file
1
tests/macro_benchmark/groups/card_fraud/run.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"scenario": "teps"
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user