omg optimize

pull/1/head
Jeff Becker 6 years ago
parent a4abfc0e9d
commit b949e61752
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

4
.gitignore vendored

@ -9,4 +9,6 @@
llarpd llarpd
*.test *.test
*.bin *.bin
callgrind.*

@ -65,11 +65,13 @@ $(REPO)/test/%.cpp.bin: $(REPO)/test/%.cpp
$(CXX) $(REQUIRED_CXXFLAGS) $< -o $<.bin $(TEST_LDFLAGS) $(CXX) $(REQUIRED_CXXFLAGS) $< -o $<.bin $(TEST_LDFLAGS)
mv $<.bin $<.test mv $<.bin $<.test
$<.test $<.test
valgrind --tool=callgrind $<.test
$(REPO)/test/%.c.bin: $(REPO)/test/%.c $(REPO)/test/%.c.bin: $(REPO)/test/%.c
$(CC) $(REQUIRED_CFLAGS) $< -o $<.bin $(TEST_LDFLAGS) $(CC) $(REQUIRED_CFLAGS) $< -o $<.bin $(TEST_LDFLAGS)
mv $<.bin $<.test mv $<.bin $<.test
$<.test $<.test
valgrind --tool=callgrind $<.test
$(EXE): $(DAEMON_OBJ) $(STATIC_LIB) $(EXE): $(DAEMON_OBJ) $(STATIC_LIB)
$(CXX) $(DAEMON_OBJ) $(STATIC_LIB) $(LIB_LDFLAGS) -o $(EXE) $(CXX) $(DAEMON_OBJ) $(STATIC_LIB) $(LIB_LDFLAGS) -o $(EXE)

@ -5,6 +5,7 @@
#include <mutex> #include <mutex>
#include <queue> #include <queue>
struct llarp_ev_caller { struct llarp_ev_caller {
static void *operator new(size_t sz) { static void *operator new(size_t sz) {
return llarp::Alloc<llarp_ev_caller>(); return llarp::Alloc<llarp_ev_caller>();
@ -21,37 +22,34 @@ struct llarp_ev_caller {
bool appendCall(void *user) { bool appendCall(void *user) {
std::unique_lock<std::mutex> lock(access); std::unique_lock<std::mutex> lock(access);
bool should = pending.size() == 0; pending.emplace_back(std::move(llarp_ev_async_call{loop, this, user, this->work}));
llarp_ev_async_call *call = return true;
new llarp_ev_async_call{loop, this, user, this->work};
pending.push(call);
return should;
} }
bool appendManyCalls(void **users, size_t n) { bool appendManyCalls(void **users, size_t n) {
std::unique_lock<std::mutex> lock(access); std::unique_lock<std::mutex> lock(access);
bool should = pending.size() == 0;
while (n--) { while (n--) {
pending.push(new llarp_ev_async_call{loop, this, *users, this->work}); pending.emplace_back(std::move(llarp_ev_async_call{loop, this, *users, this->work}));
users++; users++;
} }
return should; return true;
} }
void Call() { void Call() {
std::unique_lock<std::mutex> lock(access); std::unique_lock<std::mutex> lock(access);
while (pending.size() > 0) { auto sz = pending.size();
while (sz > 0) {
auto &front = pending.front(); auto &front = pending.front();
front->work(front); front.work(&front);
pending.pop(); pending.pop_front();
delete front; --sz;
} }
} }
std::mutex access; std::mutex access;
struct llarp_ev_loop *loop; struct llarp_ev_loop *loop;
uv_async_t async; uv_async_t async;
std::queue<llarp_ev_async_call *> pending; std::deque<llarp_ev_async_call> pending;
llarp_ev_work_func work; llarp_ev_work_func work;
}; };

@ -35,14 +35,14 @@ int main(int argc, char *argv[]) {
struct bench_main b_main; struct bench_main b_main;
struct llarp_threadpool *tp; struct llarp_threadpool *tp;
llarp_mem_jemalloc(); llarp_mem_std();
llarp_crypto_libsodium_init(&b_main.crypto); llarp_crypto_libsodium_init(&b_main.crypto);
llarp_ev_loop_alloc(&b_main.ev); llarp_ev_loop_alloc(&b_main.ev);
tp = llarp_init_threadpool(2); tp = llarp_init_threadpool(2);
b_main.num = 10000000; b_main.num = 100000;
b_main.jobs = 10000; b_main.jobs = 1000;
b_main.completed = 0; b_main.completed = 0;
llarp_sharedkey_t key; llarp_sharedkey_t key;
b_main.crypto.randbytes(key, sizeof(llarp_sharedkey_t)); b_main.crypto.randbytes(key, sizeof(llarp_sharedkey_t));

Loading…
Cancel
Save