From 32af7b1dc524a436a4f0126b28700d46b6729649 Mon Sep 17 00:00:00 2001 From: Javad Saberlatibari <76922325+javadsaberlatibari@users.noreply.github.com> Date: Wed, 27 Mar 2024 01:12:23 -0700 Subject: [PATCH] Add files via upload --- .../benchmark/rubis-benchmark.cpp | 48 +++++++++++++++---- wellcoordination/benchmark/rubis.hpp | 45 +++++++++++++++-- 2 files changed, 78 insertions(+), 15 deletions(-) diff --git a/wellcoordination/benchmark/rubis-benchmark.cpp b/wellcoordination/benchmark/rubis-benchmark.cpp index 6abaef7..d7c311e 100644 --- a/wellcoordination/benchmark/rubis-benchmark.cpp +++ b/wellcoordination/benchmark/rubis-benchmark.cpp @@ -16,7 +16,7 @@ int main(int argc, char* argv[]) { std::string loc = - "/users/jsaber/binHamband/workload/"; + "/home/prithviraj/Documents/Hamband/wellcoordination/workload/"; int nr_procs = static_cast(std::atoi(argv[1])); int num_ops = static_cast(std::atoi(argv[2])); @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) { int queries = num_ops - total_writes; int num_conflicting_write_methods = 2; - int num_nonconflicting_write_methods = 2; + int num_nonconflicting_write_methods = 3; int num_read_methods = 0; std::cout << "ops: " << num_ops << std::endl; @@ -81,6 +81,10 @@ int main(int argc, char* argv[]) { expected_nonconflicting_write_calls_per_follower * num_nonconflicting_write_methods * (nr_procs - 1); + + + std::vector* open = new std::vector[nr_procs]; + // first allocating writes operations to the nodes for (int i = 1; i <= num_replicas; i++) { // first leader @@ -89,11 +93,12 @@ int main(int argc, char* argv[]) { int count = 0; for (; count < expected_calls_per_update_method;) { // storeBuyNow + // Sell items with id 0 - 99. std::string callStr; if (type == 0) { - std::string b_id = std::to_string(1 + std::rand() % 100); + std::string i_id = std::to_string(std::rand() % 100); std::string value = std::to_string(std::rand() % 1000); - callStr = "1 " + b_id + "-" + value; + callStr = "1 " + i_id + "-" + value; } MethodCall call = ReplicatedObject::createCall("id", callStr); if (test->isPermissible(call)) { @@ -110,9 +115,10 @@ int main(int argc, char* argv[]) { int count = 0; for (; count < expected_calls_per_update_method;) { // registerUser + // add users from 100 - 199. std::string callStr; if (type == 0) { - std::string u_id = std::to_string(1+ std::rand() % 100); + std::string u_id = std::to_string(100 + std::rand() % 100); callStr = "2 " + u_id; } MethodCall call = ReplicatedObject::createCall("id", callStr); @@ -127,25 +133,38 @@ int main(int argc, char* argv[]) { // follower else { // non-conflicting write method - for (int type = 0; type <= 1; type++) { + for (int type = 0; type <= 2; type++) { for (int count = 0; count < expected_nonconflicting_write_calls_per_follower; count++) { std::string callStr; if (type == 0) { - // sellitem - std::string s_id = std::to_string(1+ std::rand() % 100); + // sellitem + std::string s_id = std::to_string(100 + std::rand() % 100); std::string value = std::to_string(std::rand() % 1000); callStr = "0 " + s_id+ "-"+ value; } if (type == 1) { // placeBid - std::string a_id = std::to_string(1+ std::rand() % 100); //auction id - std::string u_id = std::to_string(1+ std::rand() % 100); //user id + // Bid with user id 0 - 99 and item id 0 - 99 + std::string a_id = std::to_string(std::rand() % 100); //auction id + std::string u_id = std::to_string(std::rand() % 100); //user id std::string value = std::to_string(std::rand() % 1000); //bid value callStr = "3 " + a_id + "-" + u_id + "-" + value; } + if (type == 2) { + //Open Auctions + // Open 100 - 199, with different stock values + // Save the opened ids so we can close them after shuffling. + std::string i_id = std::to_string(100 + std::rand() % 100); //auction id + std::string stock = std::to_string(1 + std::rand() % 1000); //stock + + open[i - 1].push_back(i_id); + callStr = "4 " + i_id + "-" + stock; + } + + MethodCall call = ReplicatedObject::createCall("id", callStr); test->execute(call); calls[i - 1].push_back(callStr); @@ -170,6 +189,15 @@ int main(int argc, char* argv[]) { calls[i].insert(calls[i].begin(), std::string("#" + std::to_string(write_calls))); std::random_shuffle(calls[i].begin() + 1, calls[i].end()); + + std::string callStr; + if (i != 0 && i != 1) + for (int count = 0; count < expected_nonconflicting_write_calls_per_follower; count++) { + //Close Auction (using the saved values we opened added to the end of the shuffled operations) + callStr = "5 " + open[i][count]; + calls[i].push_back(callStr); + } + } for (int i = 0; i < nr_procs; i++) { diff --git a/wellcoordination/benchmark/rubis.hpp b/wellcoordination/benchmark/rubis.hpp index b7059ba..040c694 100644 --- a/wellcoordination/benchmark/rubis.hpp +++ b/wellcoordination/benchmark/rubis.hpp @@ -30,10 +30,12 @@ class Rubis : public ReplicatedObject STORE_BUY_NOW = 1, REGISTER_USER = 2, PLACE_BID = 3, - QUERY = 4 + OPEN_AUCTION=4, + CLOSE_AUCTION=5, + QUERY = 6 }; - std::atomic auction [100][3]={{0}}; //auctionid-quantity-user propsed max value-max value - bool registeredusers [100]={false}; + std::atomic auction [200][4]={{0}}; //auctionid-quantity-user propsed max value-max value -valid auction + bool registeredusers [200]={false}; int userscounter=0; //std::set movies; //std::set customers; @@ -46,11 +48,15 @@ class Rubis : public ReplicatedObject update_methods.push_back(static_cast(MethodType::STORE_BUY_NOW)); update_methods.push_back(static_cast(MethodType::REGISTER_USER)); update_methods.push_back(static_cast(MethodType::PLACE_BID)); + update_methods.push_back(static_cast(MethodType::OPEN_AUCTION)); + update_methods.push_back(static_cast(MethodType::CLOSE_AUCTION)); method_args.insert(std::make_pair(static_cast(MethodType::SELL_ITEM), 2)); method_args.insert(std::make_pair(static_cast(MethodType::STORE_BUY_NOW), 2)); method_args.insert(std::make_pair(static_cast(MethodType::REGISTER_USER), 1)); method_args.insert(std::make_pair(static_cast(MethodType::PLACE_BID), 3)); + method_args.insert(std::make_pair(static_cast(MethodType::OPEN_AUCTION), 2)); + method_args.insert(std::make_pair(static_cast(MethodType::CLOSE_AUCTION), 1)); method_args.insert(std::make_pair(static_cast(MethodType::QUERY), 0)); // conflicts @@ -62,6 +68,12 @@ class Rubis : public ReplicatedObject g2.push_back(static_cast(MethodType::REGISTER_USER)); //g2.push_back(static_cast(MethodType::REMOVE_CUSTOMER)); synch_groups.push_back(g2); + + for (int i = 0; i < 100; i++) { + auction[i][0] = 1000; + auction[i][3] =1; //auctions that are open. + registeredusers[i] = true; + } } Rubis(Rubis &obj) : ReplicatedObject(obj) @@ -93,7 +105,7 @@ class Rubis : public ReplicatedObject auction[s_id][0]=auction[s_id][0]-value; } // 2 - void registeruser(int u_id) + void registerUser(int u_id) { registeredusers[u_id]=true; userscounter++; @@ -109,6 +121,16 @@ class Rubis : public ReplicatedObject } } + void openAction(int a_id, int stock) + { + auction[a_id][0]=stock; + auction[a_id][3]=1; + } + void closeAction(int a_id) + { + auction[a_id][3]=0; + } + Rubis query() { return *this; } @@ -134,7 +156,7 @@ class Rubis : public ReplicatedObject } case MethodType::REGISTER_USER: { - registeruser(std::stoi(call.arg)); + registerUser(std::stoi(call.arg)); break; } case MethodType::PLACE_BID: @@ -148,6 +170,19 @@ class Rubis : public ReplicatedObject placeBid(a_id, u_id, value); break; } + case MethodType::OPEN_AUCTION: + { + size_t index = call.arg.find_first_of('-'); + int s_id = std::stoi(call.arg.substr(0, index)); + int stock = std::stoi(call.arg.substr(index + 1, call.arg.length())); + openAction(s_id, stock); + break; + } + case MethodType::CLOSE_AUCTION: + { + closeAction(std::stoi(call.arg)); + break; + } case MethodType::QUERY: { return this;