Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
javadsaberlatibari authored Mar 27, 2024
1 parent 3b37de7 commit 32af7b1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 15 deletions.
48 changes: 38 additions & 10 deletions wellcoordination/benchmark/rubis-benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(std::atoi(argv[1]));
int num_ops = static_cast<int>(std::atoi(argv[2]));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string>* open = new std::vector<std::string>[nr_procs];

// first allocating writes operations to the nodes
for (int i = 1; i <= num_replicas; i++) {
// first leader
Expand All @@ -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)) {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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++) {
Expand Down
45 changes: 40 additions & 5 deletions wellcoordination/benchmark/rubis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> auction [100][3]={{0}}; //auctionid-quantity-user propsed max value-max value
bool registeredusers [100]={false};
std::atomic<int> auction [200][4]={{0}}; //auctionid-quantity-user propsed max value-max value -valid auction
bool registeredusers [200]={false};
int userscounter=0;
//std::set<std::string> movies;
//std::set<std::string> customers;
Expand All @@ -46,11 +48,15 @@ class Rubis : public ReplicatedObject
update_methods.push_back(static_cast<int>(MethodType::STORE_BUY_NOW));
update_methods.push_back(static_cast<int>(MethodType::REGISTER_USER));
update_methods.push_back(static_cast<int>(MethodType::PLACE_BID));
update_methods.push_back(static_cast<int>(MethodType::OPEN_AUCTION));
update_methods.push_back(static_cast<int>(MethodType::CLOSE_AUCTION));

method_args.insert(std::make_pair(static_cast<int>(MethodType::SELL_ITEM), 2));
method_args.insert(std::make_pair(static_cast<int>(MethodType::STORE_BUY_NOW), 2));
method_args.insert(std::make_pair(static_cast<int>(MethodType::REGISTER_USER), 1));
method_args.insert(std::make_pair(static_cast<int>(MethodType::PLACE_BID), 3));
method_args.insert(std::make_pair(static_cast<int>(MethodType::OPEN_AUCTION), 2));
method_args.insert(std::make_pair(static_cast<int>(MethodType::CLOSE_AUCTION), 1));
method_args.insert(std::make_pair(static_cast<int>(MethodType::QUERY), 0));

// conflicts
Expand All @@ -62,6 +68,12 @@ class Rubis : public ReplicatedObject
g2.push_back(static_cast<int>(MethodType::REGISTER_USER));
//g2.push_back(static_cast<int>(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)
Expand Down Expand Up @@ -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++;
Expand All @@ -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; }


Expand All @@ -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:
Expand All @@ -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;
Expand Down

0 comments on commit 32af7b1

Please sign in to comment.