From 38a157808ec7d97a3ef8e01f931f28e296b70fba Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 28 Mar 2022 18:11:47 -0400 Subject: [PATCH 1/3] Cache best paths determined by GetPathByRouter to reduce cpu usage --- llarp/path/pathbuilder.cpp | 7 ++++--- llarp/path/pathset.cpp | 27 ++++++++++++++++++++++++++- llarp/path/pathset.hpp | 5 ++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 7800a12d4..2b7f4be39 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -191,10 +191,11 @@ namespace llarp lastBuild = 0s; } - void Builder::Tick(llarp_time_t) + void + Builder::Tick(llarp_time_t now) { - const auto now = llarp::time_now_ms(); - + PathSet::Tick(now); + now = llarp::time_now_ms(); m_router->pathBuildLimiter().Decay(now); ExpirePaths(now, m_router); diff --git a/llarp/path/pathset.cpp b/llarp/path/pathset.cpp index 75cecff39..50a40ef75 100644 --- a/llarp/path/pathset.cpp +++ b/llarp/path/pathset.cpp @@ -66,13 +66,31 @@ namespace llarp PathSet::TickPaths(AbstractRouter* r) { const auto now = llarp::time_now_ms(); - Lock_t l(m_PathsMutex); + Lock_t l{m_PathsMutex}; for (auto& item : m_Paths) { item.second->Tick(now, r); } } + void PathSet::Tick(llarp_time_t) + { + std::unordered_set endpoints; + for (auto& item : m_Paths) + { + endpoints.emplace(item.second->Endpoint()); + } + + m_PathCache.clear(); + for (const auto& ep : endpoints) + { + if (auto path = GetPathByRouter(ep)) + { + m_PathCache[ep] = path->weak_from_this(); + } + } + } + void PathSet::ExpirePaths(llarp_time_t now, AbstractRouter* router) { @@ -150,6 +168,13 @@ namespace llarp { Lock_t l(m_PathsMutex); Path_ptr chosen = nullptr; + if (roles == ePathRoleAny) + { + if (auto itr = m_PathCache.find(id); itr != m_PathCache.end()) + { + return itr->second.lock(); + } + } auto itr = m_Paths.begin(); while (itr != m_Paths.end()) { diff --git a/llarp/path/pathset.hpp b/llarp/path/pathset.hpp index 8457441b2..5bef0a643 100644 --- a/llarp/path/pathset.hpp +++ b/llarp/path/pathset.hpp @@ -130,7 +130,7 @@ namespace llarp /// tick owned paths virtual void - Tick(llarp_time_t now) = 0; + Tick(llarp_time_t now); /// count the number of paths that will exist at this timestamp in future size_t @@ -320,6 +320,9 @@ namespace llarp using PathMap_t = std::unordered_map, Path_ptr>; mutable Mtx_t m_PathsMutex; PathMap_t m_Paths; + + private: + std::unordered_map> m_PathCache; }; } // namespace path From 77bf2f4af96165bf645d7e268e2c38d90bee6a8e Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 30 Mar 2022 17:35:45 -0400 Subject: [PATCH 2/3] disable building fat liblokinet.so on bionic because lto is broken on bionoic still --- .drone.jsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index ef062f1e2..2bb81c2cc 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -367,7 +367,7 @@ local docs_pipeline(name, image, extra_cmds=[], allow_fail=false) = { '-DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8 ' + '-DCMAKE_CXX_FLAGS="-march=x86-64 -mtune=haswell" ' + '-DCMAKE_C_FLAGS="-march=x86-64 -mtune=haswell" ' + - '-DNATIVE_BUILD=OFF -DWITH_SYSTEMD=OFF -DWITH_BOOTSTRAP=OFF', + '-DNATIVE_BUILD=OFF -DWITH_SYSTEMD=OFF -DWITH_BOOTSTRAP=OFF -DBUILD_LIBLOKINET=OFF', extra_cmds=[ '../contrib/ci/drone-check-static-libs.sh', '../contrib/ci/drone-static-upload.sh', From 17687e300efb4d4c6f750b59d5aa85b118c2d060 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 30 Mar 2022 19:38:41 -0400 Subject: [PATCH 3/3] drone-ci image name fix, use -builder images --- .drone.jsonnet | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 2bb81c2cc..afbf6dc0e 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -393,11 +393,11 @@ local docs_pipeline(name, image, extra_cmds=[], allow_fail=false) = { cmake_extra='-DWITH_HIVE=ON'), // Deb builds: - deb_builder(docker_base + 'debian-sid-debhelper', 'sid', 'debian/sid'), - deb_builder(docker_base + 'debian-bullseye-debhelper', 'bullseye', 'debian/bullseye'), - deb_builder(docker_base + 'ubuntu-impish-debhelper', 'impish', 'ubuntu/impish'), - deb_builder(docker_base + 'ubuntu-focal-debhelper', 'focal', 'ubuntu/focal'), - deb_builder(docker_base + 'debian-sid-debhelper', 'sid', 'debian/sid', arch='arm64'), + deb_builder(docker_base + 'debian-sid-builder', 'sid', 'debian/sid'), + deb_builder(docker_base + 'debian-bullseye-builder', 'bullseye', 'debian/bullseye'), + deb_builder(docker_base + 'ubuntu-impish-builder', 'impish', 'ubuntu/impish'), + deb_builder(docker_base + 'ubuntu-focal-builder', 'focal', 'ubuntu/focal'), + deb_builder(docker_base + 'debian-sid-builder', 'sid', 'debian/sid', arch='arm64'), // Macos builds: mac_builder('macOS (Release)'),