Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d265a0d
Slightly modified a comment
Bokai-Bi Jun 14, 2023
3e0e834
included unordered_map in proclet_mgr.cpp to print out header contents
Bokai-Bi Jun 14, 2023
cee513a
bug fix
Bokai-Bi Jun 14, 2023
b626fee
Compiler error fixes
Bokai-Bi Jun 14, 2023
d4c2132
Unit disabling
Bokai-Bi Jun 14, 2023
d47708a
Update proclet.ipp
Bokai-Bi Jun 14, 2023
88acf58
Unit testing
Bokai-Bi Jun 14, 2023
4360667
new debugging checkpoints
Bokai-Bi Jun 14, 2023
aee42a5
initialized map
Bokai-Bi Jun 15, 2023
6f4652f
Bug fixes
Bokai-Bi Jun 15, 2023
c010341
no-error solution that doesn't handle migration
Bokai-Bi Jun 16, 2023
7b6bf77
Finished impl v1, logging benchmark WIP
Bokai-Bi Jun 21, 2023
0ede345
Finished benchmark test
Bokai-Bi Jun 21, 2023
ffd35a8
prepare repository for multi-machine test
Jun 26, 2023
48f1a26
changed benchmark to non-distributed
Jun 27, 2023
a5bb778
pinned proclets in benchmark
Bokai-Bi Jun 27, 2023
a4e9680
Prepare for pull request, comments and code cleanup
Bokai-Bi Jun 28, 2023
1d39a24
Update test.sh to original settings
Bokai-Bi Jun 29, 2023
451c080
Update proclet_mgr.cpp
Bokai-Bi Jun 29, 2023
0ba7d56
Cleaned proclet.ipp for pull request
Bokai-Bi Jun 29, 2023
dea0f56
Update proclet_mgr.hpp
Bokai-Bi Jun 29, 2023
820d081
Reverted comments to test_condvar.cpp
Bokai-Bi Jun 29, 2023
1a1b9a7
Deleted start_controller.sh for pull request
Bokai-Bi Jun 29, 2023
1028464
Update proclet_mgr.hpp to change NodeIP to ProcletID in logging remot…
Bokai-Bi Jul 6, 2023
58632e6
Update proclet.ipp to use ProcletID instead of NodeIP as key
Bokai-Bi Jul 6, 2023
dc66aa2
Update proclet_mgr.cpp to reflect changing NodeIP to Proclet ID
Bokai-Bi Jul 7, 2023
9bc2bd0
Updated benchmark for multithreaded proclet logging performance
Jul 10, 2023
72f27e0
reduced thread number
Jul 10, 2023
949d147
Added instrumentation and test for compute intensity; slightly tweake…
Jul 14, 2023
879c75d
Updated compute intensity benchmark
Jul 17, 2023
61a41ff
Update bench_proclet_logging.cpp for maximum lock contention
Bokai-Bi Jul 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ bench_cpu_overloaded_src = bench/bench_cpu_overloaded.cpp
bench_cpu_overloaded_obj = $(bench_cpu_overloaded_src:.cpp=.o)
bench_compute_intensity_src = bench/bench_compute_intensity.cpp
bench_compute_intensity_obj = $(bench_compute_intensity_src:.cpp=.o)
bench_proclet_logging_src = bench/bench_proclet_logging.cpp
bench_proclet_logging_obj = $(bench_proclet_logging_src:.cpp=.o)
bench_compute_intensity_src = bench/bench_compute_intensity.cpp
bench_compute_intensity_obj = $(bench_compute_intensity_src:.cpp=.o)

ctrl_main_src = src/ctrl_main.cpp
ctrl_main_obj = $(ctrl_main_src:.cpp=.o)
Expand All @@ -114,7 +118,7 @@ bin/test_rem_shared_ptr bin/bench_fragmentation bin/test_perf bin/bench_real_mem
bin/bench_real_cpu_pressure bin/test_cpu_load bin/test_tcp_poll bin/test_thread \
bin/test_fast_path bin/test_slow_path bin/ctrl_main bin/test_max_num_proclets \
bin/bench_controller bin/test_cereal bin/bench_proclet_call_bw bin/bench_cpu_overloaded \
bin/test_continuous_migrate
bin/test_continuous_migrate bin/bench_proclet_logging bin/bench_compute_intensity

%.d: %.cpp
@$(CXX) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
Expand Down Expand Up @@ -174,6 +178,10 @@ bin/bench_proclet_call_tput: $(bench_proclet_call_tput_obj) $(librt_libs) $(RUNT
$(LDXX) -o $@ $(bench_proclet_call_tput_obj) $(lib_obj) $(librt_libs) $(RUNTIME_LIBS) $(LDFLAGS)
bin/bench_proclet_call_bw: $(bench_proclet_call_bw_obj) $(librt_libs) $(RUNTIME_DEPS) $(lib_obj)
$(LDXX) -o $@ $(bench_proclet_call_bw_obj) $(lib_obj) $(librt_libs) $(RUNTIME_LIBS) $(LDFLAGS)
bin/bench_proclet_logging: $(bench_proclet_logging_obj) $(librt_libs) $(RUNTIME_DEPS) $(lib_obj)
$(LDXX) -o $@ $(bench_proclet_logging_obj) $(lib_obj) $(librt_libs) $(RUNTIME_LIBS) $(LDFLAGS)
bin/bench_compute_intensity: $(bench_compute_intensity_obj) $(librt_libs) $(RUNTIME_DEPS) $(lib_obj)
$(LDXX) -o $@ $(bench_compute_intensity_obj) $(lib_obj) $(librt_libs) $(RUNTIME_LIBS) $(LDFLAGS)
bin/bench_proclet_call_lat: $(bench_proclet_call_lat_obj) $(librt_libs) $(RUNTIME_DEPS) $(lib_obj)
$(LDXX) -o $@ $(bench_proclet_call_lat_obj) $(lib_obj) $(librt_libs) $(RUNTIME_LIBS) $(LDFLAGS)
bin/bench_thread: $(bench_thread_obj) $(librt_libs) $(RUNTIME_DEPS) $(lib_obj)
Expand Down
158 changes: 158 additions & 0 deletions bench/bench_compute_intensity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#include <iostream>
#include <vector>
#include <memory>
#include <cassert>

#include "nu/proclet.hpp"
#include "nu/runtime.hpp"
#include "nu/dis_hash_table.hpp"

using namespace nu;
using namespace std;

constexpr static uint32_t kNumProclets = 2;
constexpr static uint32_t kNumTableEntries = 1000000;
constexpr static uint32_t kObjSize = 100;
constexpr static uint32_t kBufSize = 102400;
constexpr static uint32_t kNumInvocationsPerProclet = 10;
constexpr static uint32_t kNumThreadsPerProclet = 10;

struct Obj {
uint8_t data[kObjSize];
};

using Buf = std::vector<Obj>;


class TableDB {
public:
void put(int64_t key, int64_t value){
_map[key] = value;
}
int64_t get(int64_t key){
return _map[key];
}
private:
std::unordered_map<int64_t, int64_t> _map;
};


class LowIntensityWorker {
public:
LowIntensityWorker(Proclet<TableDB> tabledb)
: _tabledb(std::move(tabledb)){}

bool foo(uint32_t kNumTableEntries) {
std::vector<nu::Thread> threads;
threads.reserve(kNumThreadsPerProclet);

for (uint32_t i = 0; i < kNumThreadsPerProclet; i++) {
threads.emplace_back([&, kNumTableEntries] {
for (int64_t i = 0; i < kNumTableEntries; i++){
int64_t v = _tabledb.run(&TableDB::get, i);
if (v != i){
std::cout << "BADRESULT" << v;
BUG_ON(true);
}
}
});
}

for (auto &thread : threads) {
thread.join();
}

return true;
}
private:
Proclet<TableDB> _tabledb;
};

class HighIntensityWorker {
public:
HighIntensityWorker(Proclet<TableDB> tabledb)
: _tabledb(std::move(tabledb)){}

bool foo(uint32_t kNumTableEntries) {
std::vector<nu::Thread> threads;
threads.reserve(kNumThreadsPerProclet);

for (uint32_t t = 0; t < kNumThreadsPerProclet; t++) {
threads.emplace_back([&, kNumTableEntries] {
for (int64_t i = 0; i < kNumTableEntries; i++){
int64_t v = _tabledb.run(&TableDB::get, i);
if (v != i){
std::cout << "BADRESULT" << v;
BUG_ON(true);
}
}
auto start_time = microtime();
while (true){
if (microtime() - start_time > 1000000){
break;
}
}
});
}

for (auto &thread : threads) {
thread.join();
}

return true;
}
private:
Proclet<TableDB> _tabledb;
};



void do_work() {
// only works when main server is started with ip 18.18.1.3, remote server started with 18.18.1.2
NodeIP localip = 303169795;
NodeIP remoteip = 303169794;
auto dis_hash = make_proclet<TableDB>(true, std::nullopt, localip);

for (int64_t i = 0; i < kNumTableEntries; i++) {
dis_hash.run(&TableDB::put, i, i);
}
auto low_proclet = make_proclet<LowIntensityWorker>(
std::forward_as_tuple(dis_hash), true, std::nullopt, remoteip
);
auto high_proclet = make_proclet<HighIntensityWorker>(
std::forward_as_tuple(dis_hash), true, std::nullopt, remoteip
);

std::vector<rt::Thread> ths;
ths.emplace_back([worker = std::move(low_proclet)]() mutable {
for (uint32_t j = 0; j < kNumInvocationsPerProclet; j++) {
bool result = worker.run(&LowIntensityWorker::foo, kNumProclets);
BUG_ON(!result);
}
});
ths.emplace_back([worker = std::move(high_proclet)]() mutable {
for (uint32_t j = 0; j < kNumInvocationsPerProclet; j++) {
bool result = worker.run(&HighIntensityWorker::foo, kNumProclets);
BUG_ON(!result);
}
});

auto t0 = microtime();
for (auto &th : ths) {
th.Join();
}
auto t1 = microtime();
auto us = t1 - t0;
//auto size =
// static_cast<uint64_t>(kBufSize) * kNumInvocationsPerProclet * kNumProclets;
auto size = sizeof(int64_t) * kNumProclets * kNumProclets + (kNumProclets * (1 + sizeof(int64_t)));
auto mbs = size / us;



std::cout << t1 - t0 << " us, " << mbs << " MB/s" << std::endl;
}

int main(int argc, char **argv) {
return runtime_main_init(argc, argv, [](int, char **) { do_work(); });
}
125 changes: 125 additions & 0 deletions bench/bench_proclet_logging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include <iostream>
#include <vector>
#include <memory>
#include <cassert>

#include "nu/proclet.hpp"
#include "nu/runtime.hpp"
#include "nu/dis_hash_table.hpp"

using namespace nu;
using namespace std;

constexpr static uint32_t kNumProclets = 1;
constexpr static uint32_t kNumTableEntries = 100000;
constexpr static uint32_t kObjSize = 100;
constexpr static uint32_t kBufSize = 102400;
constexpr static uint32_t kNumInvocationsPerProclet = 10;
constexpr static uint32_t kNumThreadsPerProclet = 50;

struct Obj {
uint8_t data[kObjSize];
};

using Buf = std::vector<Obj>;


class TableDB {
public:
void put(int64_t key, int64_t value){
_map[key] = value;
}
int64_t get(int64_t key){
return _map[key];
}
private:
std::unordered_map<int64_t, int64_t> _map;
};


class Worker {
public:
Worker(Proclet<TableDB> tabledb)
: _tabledb(std::move(tabledb)){}

bool foo(uint32_t kNumTableEntries, uint32_t kNumInvocationsPerProclet) {
std::vector<nu::Thread> threads;
threads.reserve(kNumThreadsPerProclet);
for (uint32_t j = 0; j < kNumInvocationsPerProclet; j++){

for (uint32_t i = 0; i < kNumThreadsPerProclet; i++) {
threads.emplace_back([&, kNumTableEntries] {
for (int64_t i = 0; i < kNumTableEntries; i++){
int64_t v = _tabledb.run(&TableDB::get, i);
if (v != i){
std::cout << "BADRESULT" << v;
BUG_ON(true);
}
}
});
}

for (auto &thread : threads) {
thread.join();
}
threads.clear();
}
return true;
}
private:
Proclet<TableDB> _tabledb;
};



void do_work() {
std::vector<Proclet<Worker>> workers;
// only works when main server is started with ip 18.18.1.3, remote server started with 18.18.1.2
NodeIP localip = 303169795;
NodeIP remoteip = 303169794;
auto dis_hash = make_proclet<TableDB>(true, std::nullopt, localip);

for (int64_t i = 0; i < kNumTableEntries; i++) {
dis_hash.run(&TableDB::put, i, i);
}
for (int64_t i = 0; i < kNumProclets; i++) {
workers.emplace_back(make_proclet<Worker>(
std::forward_as_tuple(dis_hash), true, std::nullopt, remoteip
));
}

std::vector<rt::Thread> ths;
for (uint32_t i = 0; i < kNumProclets; i++) {
ths.emplace_back([worker = std::move(workers[i])]() mutable {
//Buf buf;
//buf.resize(kBufSize / kObjSize);
for (uint32_t j = 0; j < kNumInvocationsPerProclet; j++) {
bool result = worker.run(&Worker::foo, kNumProclets);
BUG_ON(!result);
//if (!result){
//std::cout << "Wrong output from foo" << std::endl;
//}
}
//std::cout << "Finished execution for worker " << i << std::endl;
});
}

auto t0 = microtime();
for (auto &th : ths) {
th.Join();
}
auto t1 = microtime();
auto us = t1 - t0;
//auto size =
// static_cast<uint64_t>(kBufSize) * kNumInvocationsPerProclet * kNumProclets;
auto size = sizeof(int64_t) * kNumProclets * kNumProclets + (kNumProclets * (1 + sizeof(int64_t)));
auto mbs = size / us;



std::cout << t1 - t0 << " us, " << mbs << " MB/s" << std::endl;
}

int main(int argc, char **argv) {
return runtime_main_init(argc, argv, [](int, char **) { do_work(); });
}
8 changes: 8 additions & 0 deletions inc/nu/impl/cpu_load.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ inline float CPULoad::get_load() const {
return cpu_load_;
}

inline uint64_t CPULoad::get_total_cycles() const {
uint64_t ret = 0;
for (uint32_t i = 0; i < kNumCores; i++){
ret += cycles_[i].c;
}
return ret;
}

inline bool CPULoad::is_monitoring() const {
return get_runtime()->caladan()->thread_monitored();
}
Expand Down
Loading