Skip to content

Commit 32af7b1

Browse files
Add files via upload
1 parent 3b37de7 commit 32af7b1

File tree

2 files changed

+78
-15
lines changed

2 files changed

+78
-15
lines changed

wellcoordination/benchmark/rubis-benchmark.cpp

+38-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
int main(int argc, char* argv[]) {
1818
std::string loc =
19-
"/users/jsaber/binHamband/workload/";
19+
"/home/prithviraj/Documents/Hamband/wellcoordination/workload/";
2020

2121
int nr_procs = static_cast<int>(std::atoi(argv[1]));
2222
int num_ops = static_cast<int>(std::atoi(argv[2]));
@@ -44,7 +44,7 @@ int main(int argc, char* argv[]) {
4444
int queries = num_ops - total_writes;
4545

4646
int num_conflicting_write_methods = 2;
47-
int num_nonconflicting_write_methods = 2;
47+
int num_nonconflicting_write_methods = 3;
4848
int num_read_methods = 0;
4949

5050
std::cout << "ops: " << num_ops << std::endl;
@@ -81,6 +81,10 @@ int main(int argc, char* argv[]) {
8181
expected_nonconflicting_write_calls_per_follower *
8282
num_nonconflicting_write_methods * (nr_procs - 1);
8383

84+
85+
86+
std::vector<std::string>* open = new std::vector<std::string>[nr_procs];
87+
8488
// first allocating writes operations to the nodes
8589
for (int i = 1; i <= num_replicas; i++) {
8690
// first leader
@@ -89,11 +93,12 @@ int main(int argc, char* argv[]) {
8993
int count = 0;
9094
for (; count < expected_calls_per_update_method;) {
9195
// storeBuyNow
96+
// Sell items with id 0 - 99.
9297
std::string callStr;
9398
if (type == 0) {
94-
std::string b_id = std::to_string(1 + std::rand() % 100);
99+
std::string i_id = std::to_string(std::rand() % 100);
95100
std::string value = std::to_string(std::rand() % 1000);
96-
callStr = "1 " + b_id + "-" + value;
101+
callStr = "1 " + i_id + "-" + value;
97102
}
98103
MethodCall call = ReplicatedObject::createCall("id", callStr);
99104
if (test->isPermissible(call)) {
@@ -110,9 +115,10 @@ int main(int argc, char* argv[]) {
110115
int count = 0;
111116
for (; count < expected_calls_per_update_method;) {
112117
// registerUser
118+
// add users from 100 - 199.
113119
std::string callStr;
114120
if (type == 0) {
115-
std::string u_id = std::to_string(1+ std::rand() % 100);
121+
std::string u_id = std::to_string(100 + std::rand() % 100);
116122
callStr = "2 " + u_id;
117123
}
118124
MethodCall call = ReplicatedObject::createCall("id", callStr);
@@ -127,25 +133,38 @@ int main(int argc, char* argv[]) {
127133
// follower
128134
else {
129135
// non-conflicting write method
130-
for (int type = 0; type <= 1; type++) {
136+
for (int type = 0; type <= 2; type++) {
131137
for (int count = 0; count <
132138
expected_nonconflicting_write_calls_per_follower; count++) {
133139
std::string callStr;
134140
if (type == 0) {
135-
// sellitem
136-
std::string s_id = std::to_string(1+ std::rand() % 100);
141+
// sellitem
142+
std::string s_id = std::to_string(100 + std::rand() % 100);
137143
std::string value = std::to_string(std::rand() % 1000);
138144
callStr = "0 " + s_id+ "-"+ value;
139145
}
140146
if (type == 1) {
141147
// placeBid
142-
std::string a_id = std::to_string(1+ std::rand() % 100); //auction id
143-
std::string u_id = std::to_string(1+ std::rand() % 100); //user id
148+
// Bid with user id 0 - 99 and item id 0 - 99
149+
std::string a_id = std::to_string(std::rand() % 100); //auction id
150+
std::string u_id = std::to_string(std::rand() % 100); //user id
144151
std::string value = std::to_string(std::rand() % 1000); //bid value
145152

146153
callStr = "3 " + a_id + "-" + u_id + "-" + value;
147154
}
148155

156+
if (type == 2) {
157+
//Open Auctions
158+
// Open 100 - 199, with different stock values
159+
// Save the opened ids so we can close them after shuffling.
160+
std::string i_id = std::to_string(100 + std::rand() % 100); //auction id
161+
std::string stock = std::to_string(1 + std::rand() % 1000); //stock
162+
163+
open[i - 1].push_back(i_id);
164+
callStr = "4 " + i_id + "-" + stock;
165+
}
166+
167+
149168
MethodCall call = ReplicatedObject::createCall("id", callStr);
150169
test->execute(call);
151170
calls[i - 1].push_back(callStr);
@@ -170,6 +189,15 @@ int main(int argc, char* argv[]) {
170189
calls[i].insert(calls[i].begin(),
171190
std::string("#" + std::to_string(write_calls)));
172191
std::random_shuffle(calls[i].begin() + 1, calls[i].end());
192+
193+
std::string callStr;
194+
if (i != 0 && i != 1)
195+
for (int count = 0; count < expected_nonconflicting_write_calls_per_follower; count++) {
196+
//Close Auction (using the saved values we opened added to the end of the shuffled operations)
197+
callStr = "5 " + open[i][count];
198+
calls[i].push_back(callStr);
199+
}
200+
173201
}
174202

175203
for (int i = 0; i < nr_procs; i++) {

wellcoordination/benchmark/rubis.hpp

+40-5
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ class Rubis : public ReplicatedObject
3030
STORE_BUY_NOW = 1,
3131
REGISTER_USER = 2,
3232
PLACE_BID = 3,
33-
QUERY = 4
33+
OPEN_AUCTION=4,
34+
CLOSE_AUCTION=5,
35+
QUERY = 6
3436
};
35-
std::atomic<int> auction [100][3]={{0}}; //auctionid-quantity-user propsed max value-max value
36-
bool registeredusers [100]={false};
37+
std::atomic<int> auction [200][4]={{0}}; //auctionid-quantity-user propsed max value-max value -valid auction
38+
bool registeredusers [200]={false};
3739
int userscounter=0;
3840
//std::set<std::string> movies;
3941
//std::set<std::string> customers;
@@ -46,11 +48,15 @@ class Rubis : public ReplicatedObject
4648
update_methods.push_back(static_cast<int>(MethodType::STORE_BUY_NOW));
4749
update_methods.push_back(static_cast<int>(MethodType::REGISTER_USER));
4850
update_methods.push_back(static_cast<int>(MethodType::PLACE_BID));
51+
update_methods.push_back(static_cast<int>(MethodType::OPEN_AUCTION));
52+
update_methods.push_back(static_cast<int>(MethodType::CLOSE_AUCTION));
4953

5054
method_args.insert(std::make_pair(static_cast<int>(MethodType::SELL_ITEM), 2));
5155
method_args.insert(std::make_pair(static_cast<int>(MethodType::STORE_BUY_NOW), 2));
5256
method_args.insert(std::make_pair(static_cast<int>(MethodType::REGISTER_USER), 1));
5357
method_args.insert(std::make_pair(static_cast<int>(MethodType::PLACE_BID), 3));
58+
method_args.insert(std::make_pair(static_cast<int>(MethodType::OPEN_AUCTION), 2));
59+
method_args.insert(std::make_pair(static_cast<int>(MethodType::CLOSE_AUCTION), 1));
5460
method_args.insert(std::make_pair(static_cast<int>(MethodType::QUERY), 0));
5561

5662
// conflicts
@@ -62,6 +68,12 @@ class Rubis : public ReplicatedObject
6268
g2.push_back(static_cast<int>(MethodType::REGISTER_USER));
6369
//g2.push_back(static_cast<int>(MethodType::REMOVE_CUSTOMER));
6470
synch_groups.push_back(g2);
71+
72+
for (int i = 0; i < 100; i++) {
73+
auction[i][0] = 1000;
74+
auction[i][3] =1; //auctions that are open.
75+
registeredusers[i] = true;
76+
}
6577
}
6678

6779
Rubis(Rubis &obj) : ReplicatedObject(obj)
@@ -93,7 +105,7 @@ class Rubis : public ReplicatedObject
93105
auction[s_id][0]=auction[s_id][0]-value;
94106
}
95107
// 2
96-
void registeruser(int u_id)
108+
void registerUser(int u_id)
97109
{
98110
registeredusers[u_id]=true;
99111
userscounter++;
@@ -109,6 +121,16 @@ class Rubis : public ReplicatedObject
109121
}
110122
}
111123

124+
void openAction(int a_id, int stock)
125+
{
126+
auction[a_id][0]=stock;
127+
auction[a_id][3]=1;
128+
}
129+
void closeAction(int a_id)
130+
{
131+
auction[a_id][3]=0;
132+
}
133+
112134
Rubis query() { return *this; }
113135

114136

@@ -134,7 +156,7 @@ class Rubis : public ReplicatedObject
134156
}
135157
case MethodType::REGISTER_USER:
136158
{
137-
registeruser(std::stoi(call.arg));
159+
registerUser(std::stoi(call.arg));
138160
break;
139161
}
140162
case MethodType::PLACE_BID:
@@ -148,6 +170,19 @@ class Rubis : public ReplicatedObject
148170
placeBid(a_id, u_id, value);
149171
break;
150172
}
173+
case MethodType::OPEN_AUCTION:
174+
{
175+
size_t index = call.arg.find_first_of('-');
176+
int s_id = std::stoi(call.arg.substr(0, index));
177+
int stock = std::stoi(call.arg.substr(index + 1, call.arg.length()));
178+
openAction(s_id, stock);
179+
break;
180+
}
181+
case MethodType::CLOSE_AUCTION:
182+
{
183+
closeAction(std::stoi(call.arg));
184+
break;
185+
}
151186
case MethodType::QUERY:
152187
{
153188
return this;

0 commit comments

Comments
 (0)