Skip to content

Commit

Permalink
Multi-threaded proxy fully working version
Browse files Browse the repository at this point in the history
  • Loading branch information
sharathvemula committed Feb 27, 2023
1 parent 4d6ab5a commit 6fda6d9
Show file tree
Hide file tree
Showing 116 changed files with 1,468,360 additions and 73 deletions.
Binary file modified waffleClient/bin/proxy_benchmark
Binary file not shown.
Binary file modified waffleClient/bin/proxy_server
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20,573 changes: 20,573 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2703:54/1

Large diffs are not rendered by default.

62,066 changes: 62,066 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2703:58/1

Large diffs are not rendered by default.

20,460 changes: 20,460 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2704:02/1

Large diffs are not rendered by default.

68,630 changes: 68,630 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2704:03/1

Large diffs are not rendered by default.

6,628 changes: 6,628 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2704:06/1

Large diffs are not rendered by default.

3,308 changes: 3,308 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2704:07/1

Large diffs are not rendered by default.

32,820 changes: 32,820 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2704:09/1

Large diffs are not rendered by default.

37,723 changes: 37,723 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2704:12/1

Large diffs are not rendered by default.

39,162 changes: 39,162 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2713:02/1

Large diffs are not rendered by default.

Empty file.
36,745 changes: 36,745 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2713:06/1

Large diffs are not rendered by default.

32,665 changes: 32,665 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2713:09/1

Large diffs are not rendered by default.

26,256 changes: 26,256 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2713:10/1

Large diffs are not rendered by default.

13,769 changes: 13,769 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2713:12/1

Large diffs are not rendered by default.

574 changes: 574 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2713:19/1

Large diffs are not rendered by default.

Empty file.
575 changes: 575 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2713:29/1

Large diffs are not rendered by default.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
26,772 changes: 26,772 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2714:03/1

Large diffs are not rendered by default.

26,643 changes: 26,643 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2714:06/1

Large diffs are not rendered by default.

Empty file.
35,521 changes: 35,521 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2714:10/1

Large diffs are not rendered by default.

Empty file.
38,317 changes: 38,317 additions & 0 deletions waffleClient/data/BST_Latency_MonFeb2714:13/1

Large diffs are not rendered by default.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
22,518 changes: 22,518 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2620:57/1

Large diffs are not rendered by default.

17,764 changes: 17,764 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2621:00/1

Large diffs are not rendered by default.

61,312 changes: 61,312 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2621:04/1

Large diffs are not rendered by default.

2,773 changes: 2,773 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2621:08/1

Large diffs are not rendered by default.

8,313 changes: 8,313 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2621:09/1

Large diffs are not rendered by default.

16,711 changes: 16,711 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2621:19/1

Large diffs are not rendered by default.

42,487 changes: 42,487 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2621:24/1

Large diffs are not rendered by default.

575 changes: 575 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2621:32/1

Large diffs are not rendered by default.

Empty file.
566 changes: 566 additions & 0 deletions waffleClient/data/BST_Latency_SunFeb2621:57/1

Large diffs are not rendered by default.

1,675 changes: 1,675 additions & 0 deletions waffleClient/data/MonFeb2703:54/1

Large diffs are not rendered by default.

4,906 changes: 4,906 additions & 0 deletions waffleClient/data/MonFeb2703:58/1

Large diffs are not rendered by default.

5,538 changes: 5,538 additions & 0 deletions waffleClient/data/MonFeb2704:03/1

Large diffs are not rendered by default.

2,665 changes: 2,665 additions & 0 deletions waffleClient/data/MonFeb2704:09/1

Large diffs are not rendered by default.

3,028 changes: 3,028 additions & 0 deletions waffleClient/data/MonFeb2704:12/1

Large diffs are not rendered by default.

3,129 changes: 3,129 additions & 0 deletions waffleClient/data/MonFeb2713:02/1

Large diffs are not rendered by default.

2,948 changes: 2,948 additions & 0 deletions waffleClient/data/MonFeb2713:06/1

Large diffs are not rendered by default.

2,631 changes: 2,631 additions & 0 deletions waffleClient/data/MonFeb2713:09/1

Large diffs are not rendered by default.

2,144 changes: 2,144 additions & 0 deletions waffleClient/data/MonFeb2713:11/1

Large diffs are not rendered by default.

1,011 changes: 1,011 additions & 0 deletions waffleClient/data/MonFeb2713:13/1

Large diffs are not rendered by default.

2,143 changes: 2,143 additions & 0 deletions waffleClient/data/MonFeb2714:04/1

Large diffs are not rendered by default.

2,140 changes: 2,140 additions & 0 deletions waffleClient/data/MonFeb2714:06/1

Large diffs are not rendered by default.

2,854 changes: 2,854 additions & 0 deletions waffleClient/data/MonFeb2714:10/1

Large diffs are not rendered by default.

3,115 changes: 3,115 additions & 0 deletions waffleClient/data/MonFeb2714:13/1

Large diffs are not rendered by default.

22,419 changes: 22,419 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2703:54/1

Large diffs are not rendered by default.

62,903 changes: 62,903 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2703:58/1

Large diffs are not rendered by default.

20,238 changes: 20,238 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2704:02/1

Large diffs are not rendered by default.

71,108 changes: 71,108 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2704:03/1

Large diffs are not rendered by default.

7,657 changes: 7,657 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2704:06/1

Large diffs are not rendered by default.

3,827 changes: 3,827 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2704:07/1

Large diffs are not rendered by default.

32,795 changes: 32,795 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2704:09/1

Large diffs are not rendered by default.

37,982 changes: 37,982 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2704:12/1

Large diffs are not rendered by default.

39,640 changes: 39,640 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2713:02/1

Large diffs are not rendered by default.

Empty file.
38,213 changes: 38,213 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2713:06/1

Large diffs are not rendered by default.

33,334 changes: 33,334 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2713:09/1

Large diffs are not rendered by default.

26,793 changes: 26,793 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2713:10/1

Large diffs are not rendered by default.

14,747 changes: 14,747 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2713:12/1

Large diffs are not rendered by default.

524 changes: 524 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2713:19/1

Large diffs are not rendered by default.

519 changes: 519 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2713:23/1

Large diffs are not rendered by default.

510 changes: 510 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2713:29/1

Large diffs are not rendered by default.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
26,798 changes: 26,798 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2714:03/1

Large diffs are not rendered by default.

27,346 changes: 27,346 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2714:06/1

Large diffs are not rendered by default.

Empty file.
36,026 changes: 36,026 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2714:10/1

Large diffs are not rendered by default.

Empty file.
39,945 changes: 39,945 additions & 0 deletions waffleClient/data/Redis_Latency_MonFeb2714:13/1

Large diffs are not rendered by default.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
22,405 changes: 22,405 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2620:57/1

Large diffs are not rendered by default.

16,956 changes: 16,956 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2621:00/1

Large diffs are not rendered by default.

61,809 changes: 61,809 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2621:04/1

Large diffs are not rendered by default.

2,734 changes: 2,734 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2621:08/1

Large diffs are not rendered by default.

8,751 changes: 8,751 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2621:09/1

Large diffs are not rendered by default.

16,876 changes: 16,876 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2621:19/1

Large diffs are not rendered by default.

42,118 changes: 42,118 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2621:24/1

Large diffs are not rendered by default.

547 changes: 547 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2621:32/1

Large diffs are not rendered by default.

Empty file.
546 changes: 546 additions & 0 deletions waffleClient/data/Redis_Latency_SunFeb2621:57/1

Large diffs are not rendered by default.

1,823 changes: 1,823 additions & 0 deletions waffleClient/data/SunFeb2620:57/1

Large diffs are not rendered by default.

4,892 changes: 4,892 additions & 0 deletions waffleClient/data/SunFeb2621:04/1

Large diffs are not rendered by default.

3,413 changes: 3,413 additions & 0 deletions waffleClient/data/SunFeb2621:24/1

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions waffleClient/proxy/src/FrequencySmoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,3 @@ std::set<std::pair<std::string, int>, decltype(&freqCmp)>::iterator FrequencySmo
std::mutex& FrequencySmoother::getMutex() {
return m_mutex_;
}

// template<typename Func>
// void iterateAccessTree(Func func) {
// std::lock_guard<std::mutex> lock(m_mutex_);
// func(it);
// }

// void FrequencySmoother::printFreqs() {
// std::cout << "Printing frequencies ";
// for(auto& it: accessFreqs) {
// std::cout << "Key: " << it.first << " Value: " << it.second << " ";
// }
// std::cout << std::endl;
// }
4 changes: 0 additions & 4 deletions waffleClient/proxy/src/FrequencySmoother.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <mutex>
#include <memory>

//#include "CloudDB.hpp"

bool freqCmp(std::pair<std::string, int> a, std::pair<std::string, int> b);

Expand All @@ -32,9 +31,6 @@ class FrequencySmoother {
std::mutex& getMutex();
mutable std::mutex m_mutex_;

// template<typename Func>
// void iterateAccessTree(Func func);

};

#endif
63 changes: 11 additions & 52 deletions waffleClient/proxy/src/waffle_proxy.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//
// Created by Lloyd Brown on 9/24/19.
//

#include "waffle_proxy.h"

void randomize_map(const std::unordered_map<std::string, std::string>& input_map, std::vector<std::string>& keys, std::vector<std::string>& values) {
Expand Down Expand Up @@ -102,7 +98,8 @@ void waffle_proxy::init(const std::vector<std::string> &keys, const std::vector<

id_to_client_ = *(static_cast<std::shared_ptr<thrift_response_client_map>*>(args[0]));
//int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
int num_cores = 3;
std::cout << "max cores is " << sysconf(_SC_NPROCESSORS_ONLN) << std::endl;
int num_cores = 12;
std::vector<std::thread> threads;
for (int i = 0; i < num_cores; i++) {
auto q = std::make_shared<queue<std::pair<operation, std::shared_ptr<std::promise<std::string>>>>>();
Expand All @@ -121,7 +118,7 @@ void waffle_proxy::init(const std::vector<std::string> &keys, const std::vector<
}

// Initialising Cache
size_t cacheCapacity = 10*B;
size_t cacheCapacity = 8*B;
std::unordered_set<std::string> temp;
std::vector<std::string> valuesCache;
while(keysCacheUnencrypted.size() < cacheCapacity) {
Expand All @@ -137,7 +134,7 @@ void waffle_proxy::init(const std::vector<std::string> &keys, const std::vector<
}
}

cache = Cache(keysCacheUnencrypted, valuesCache, cacheCapacity+B);
cache = Cache(keysCacheUnencrypted, valuesCache, cacheCapacity*10);

for(int i=0; i < D; ) {
auto fakeKey = gen_random(rand()%10);
Expand Down Expand Up @@ -225,14 +222,6 @@ void waffle_proxy::create_security_batch(std::shared_ptr<queue <std::pair<operat
auto currentKey = operation_promise_pair.first.key;
if(operation_promise_pair.first.value == "") {
// It's a GET request
// if(cache.checkIfKeyExists(currentKey) == true) {
// operation_promise_pair.second->set_value(cache.getValueWithoutPositionChange(currentKey));
// } else {
// if(keyToPromiseMap.find(currentKey) == keyToPromiseMap.end()) {
// storage_batch.push_back(operation_promise_pair.first);
// }
// keyToPromiseMap[currentKey].push_back(operation_promise_pair.second);
// }
bool isPresentInCache = false;
auto val = cache.getValueWithoutPositionChangeNew(currentKey, isPresentInCache);
if(isPresentInCache == true) {
Expand All @@ -245,13 +234,6 @@ void waffle_proxy::create_security_batch(std::shared_ptr<queue <std::pair<operat
}
} else {
// It's a PUT request
// if(cache.checkIfKeyExists(currentKey) == false) {
// if(keyToPromiseMap.find(currentKey) == keyToPromiseMap.end()) {
// storage_batch.push_back(operation_promise_pair.first);
// }
// }
// cache.insertIntoCache(currentKey, operation_promise_pair.first.value);
// operation_promise_pair.second->set_value(cache.getValueWithoutPositionChange(currentKey));
if(cache.checkIfKeyExists(currentKey) == false) {
auto isPresentInRunningKeys = runningKeys.insertIfNotPresent(currentKey);
if(isPresentInRunningKeys == false) {
Expand All @@ -264,7 +246,7 @@ void waffle_proxy::create_security_batch(std::shared_ptr<queue <std::pair<operat
}
};

void waffle_proxy::execute_batch(const std::vector<operation> &operations, std::unordered_map<std::string, std::vector<std::shared_ptr<std::promise<std::string>>>> &keyToPromiseMap, std::shared_ptr<storage_interface> storage_interface, encryption_engine *enc_engine) {
void waffle_proxy::execute_batch(const std::vector<operation> &operations, std::unordered_map<std::string, std::vector<std::shared_ptr<std::promise<std::string>>>> &keyToPromiseMap, std::shared_ptr<storage_interface> storage_interface, encryption_engine *enc_engine, int id) {
// Storage_keys is same as readBatch
std::vector<std::string> storage_keys;
std::vector<std::string> writeBatchKeys;
Expand All @@ -277,25 +259,16 @@ void waffle_proxy::execute_batch(const std::vector<operation> &operations, std::
rdtscllProxy(start);
}

// std::cout << "Execution batch is called " << std::endl;
// std::cout << "execute_batch encryption string is " << enc_engine->getencryption_string_() << std::endl;

// std::cout << "r is " << operations.size() << std::endl;
for(int i = 0; i < operations.size(); i++){
// std::cout << "Execution batch is called line " << __LINE__ << std::endl;
std::string key = operations[i].key;
// std::cout << "Execution batch is called key is " << key << " line " << __LINE__ << std::endl;
auto stKey = enc_engine->prf(key + "#" + std::to_string(realBst.getFrequency(key)));
readBatchMap[stKey] = key;
storage_keys.push_back(stKey);
// std::cout << "Execution batch is called line " << __LINE__ << std::endl;
realBst.incrementFrequency(key);
}

// std::cout << "Execution batch is called line " << __LINE__ << std::endl;
// std::cout << "execute_batch encryption string is " << enc_engin
std::vector<std::string> realKeysNotInCache;
//auto BSTIterator = [](auto it) {
auto& bstMutex = realBst.getMutex();
{
std::lock_guard<std::mutex> lock(bstMutex);
Expand All @@ -311,13 +284,7 @@ void waffle_proxy::execute_batch(const std::vector<operation> &operations, std::
++it;
}
}
// };

// realBst.iterateAccessTree(BSTIterator);


// std::cout << "Execution batch is called line " << __LINE__ << std::endl;
// std::cout << "realKeysNotInCache size is " << realKeysNotInCache.size() << std::endl;

for(auto& iter: realKeysNotInCache) {
auto stKey = enc_engine->prf(iter + "#" + std::to_string(realBst.getFrequency(iter)));
Expand All @@ -326,7 +293,6 @@ void waffle_proxy::execute_batch(const std::vector<operation> &operations, std::
realBst.incrementFrequency(iter);
}

// std::cout << "Execution batch is called line " << __LINE__ << std::endl;
for(int i=0;i<F;) {
auto fakeMinKey = fakeBst.getKeyWithMinFrequency();
auto isPresentInRunningKeys = runningKeys.insertIfNotPresent(fakeMinKey);
Expand All @@ -339,7 +305,6 @@ void waffle_proxy::execute_batch(const std::vector<operation> &operations, std::
}
}

// std::cout << "Execution batch is called line " << __LINE__ << std::endl;

if (latency) {
rdtscllProxy(end);
Expand All @@ -351,23 +316,18 @@ void waffle_proxy::execute_batch(const std::vector<operation> &operations, std::
}

auto responses = storage_interface->get_batch(storage_keys);
//std::cout << "Got key value pairs" << std::endl;
// std::cout << "Execution batch is called line " << __LINE__ << std::endl;
for(int i = 0 ; i < storage_keys.size(); i++){
if(i < (operations.size() + realKeysNotInCache.size())) {
// This means ith request is for real key
auto kv_pair = cache.evictLRElementFromCache();
writeBatchKeys.push_back(enc_engine->prf(kv_pair[0] + "#" + std::to_string(realBst.getFrequency(kv_pair[0]))));
writeBatchValues.push_back(enc_engine->encryptNonDeterministic(kv_pair[1]));
// writeBatchKeys.push_back(enc_engine->prf(kv_pair[0] + "#" + std::to_string(realBst.getFrequency(kv_pair[0]))));
// writeBatchValues.push_back(enc_engine->encryptNonDeterministic(kv_pair[1]));

auto writeBatchKey = enc_engine->prf(kv_pair[0] + "#" + std::to_string(realBst.getFrequency(kv_pair[0])));
auto writeBatchValue = enc_engine->encryptNonDeterministic(kv_pair[1]);
storage_interface_->put(writeBatchKey, writeBatchValue);
auto keyAboutToGoToCache = readBatchMap[storage_keys[i]];
// std::cout << "Extracted key which is about to go to Cache is " << keyAboutToGoToCache << std::endl;
std::string valueAboutToGoToCache = enc_engine->decryptNonDeterministic(responses[i]);
// if(keyToPromiseMap.find(keyAboutToGoToCache) != keyToPromiseMap.end()) {
// for(auto& it: keyToPromiseMap[keyAboutToGoToCache]) {
// it->set_value(valueAboutToGoToCache);
// }
// }
promiseSatisfy[keyAboutToGoToCache] = valueAboutToGoToCache;
if(cache.checkIfKeyExists(keyAboutToGoToCache) == true) {
valueAboutToGoToCache = cache.getValueWithoutPositionChange(keyAboutToGoToCache);
Expand All @@ -386,7 +346,6 @@ void waffle_proxy::execute_batch(const std::vector<operation> &operations, std::
runningKeys.clearPromises(it.first, it.second);
}
keysNotUsed.push(storage_keys);
// std::cout << "Execution batch is called line " << __LINE__ << std::endl;

if (latency) {
rdtscllProxy(end);
Expand Down Expand Up @@ -544,7 +503,7 @@ void waffle_proxy::consumer_thread(int id, encryption_engine *enc_engine){
++i;
}
}
execute_batch(storage_batch, keyToPromiseMap, storage_interface_, enc_engine);
execute_batch(storage_batch, keyToPromiseMap, storage_interface_, enc_engine, id);
}

};
Expand Down
5 changes: 2 additions & 3 deletions waffleClient/proxy/src/waffle_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class waffle_proxy : public proxy {
int key_size_ = 16;
int server_count_ = 1;
std::string server_type_ = "redis";
int p_threads_ = 1;
int p_threads_ = 20;
int storage_batch_size_ = 5;
int core_ = 0;
bool is_static_ = true;
Expand All @@ -96,14 +96,13 @@ class waffle_proxy : public proxy {
int redisBulkLength = 524287;
std::unordered_map<std::string, std::string> keyValueMap;
ThreadSafeUnorderedMap<std::promise<std::string>> runningKeys;


private:
void create_security_batch(std::shared_ptr<queue <std::pair<operation, std::shared_ptr<std::promise<std::string>>>>> &op_queue,
std::vector<operation> &storage_batch,
std::unordered_map<std::string, std::vector<std::shared_ptr<std::promise<std::string>>>> &keyToPromiseMap);

void execute_batch(const std::vector<operation> &operations, std::unordered_map<std::string, std::vector<std::shared_ptr<std::promise<std::string>>>> &keyToPromiseMap, std::shared_ptr<storage_interface> storage_interface, encryption_engine *enc_engine);
void execute_batch(const std::vector<operation> &operations, std::unordered_map<std::string, std::vector<std::shared_ptr<std::promise<std::string>>>> &keyToPromiseMap, std::shared_ptr<storage_interface> storage_interface, encryption_engine *enc_engine, int id);
void consumer_thread(int id, encryption_engine *enc_engine);
void responder_thread();
void clearThread();
Expand Down

0 comments on commit 6fda6d9

Please sign in to comment.