better profiling

pull/523/head
Jeff Becker 5 years ago
parent e41bec4247
commit a45d6db0e0
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -217,7 +217,7 @@ namespace llarp
[&](const ILinkSession* s, bool) {
const PubKey k(s->GetPubKey());
if(got || router->IsBootstrapNode(k)
|| router->routerProfiling().IsBad(k))
|| router->routerProfiling().IsBadForConnect(k))
return;
cur = s->GetRemoteRC();
got = true;
@ -232,7 +232,7 @@ namespace llarp
--tries;
if(db->select_random_hop_excluding(cur, exclude))
{
if(!router->routerProfiling().IsBad(cur.pubkey))
if(!router->routerProfiling().IsBadForPath(cur.pubkey))
return true;
exclude.insert(cur.pubkey);
}
@ -276,6 +276,8 @@ namespace llarp
bool
Builder::ShouldBuildMore(llarp_time_t now) const
{
if(IsStopped())
return false;
if(llarp::randint() % 3 >= 1)
return PathSet::ShouldBuildMore(now) && !BuildCooldownHit(now);
return false;

@ -13,7 +13,7 @@ namespace llarp
namespace path
{
// milliseconds waiting between builds on a path
constexpr llarp_time_t MIN_PATH_BUILD_INTERVAL = 5 * 1000;
constexpr llarp_time_t MIN_PATH_BUILD_INTERVAL = 1000;
struct Builder : public PathSet, public util::IStateful
{

@ -76,6 +76,47 @@ namespace llarp
return (pathSuccessCount * chances) > pathFailCount;
}
static bool constexpr checkIsGood(uint64_t fails, uint64_t success, uint64_t chances)
{
if(fails > 0)
return success / fails > chances;
if(success == 0)
return fails < chances;
return true;
}
bool
RouterProfile::IsGoodForConnect(uint64_t chances) const
{
return checkIsGood(connectTimeoutCount, connectGoodCount, chances);
}
bool
RouterProfile::IsGoodForPath(uint64_t chances) const
{
return checkIsGood(pathFailCount, pathSuccessCount, chances);
}
bool
Profiling::IsBadForConnect(const RouterID & r, uint64_t chances)
{
lock_t lock(&m_ProfilesMutex);
auto itr = m_Profiles.find(r);
if(itr == m_Profiles.end())
return false;
return !itr->second.IsGoodForConnect(chances);
}
bool
Profiling::IsBadForPath(const RouterID & r, uint64_t chances)
{
lock_t lock(&m_ProfilesMutex);
auto itr = m_Profiles.find(r);
if(itr == m_Profiles.end())
return false;
return !itr->second.IsGoodForPath(chances);
}
bool
Profiling::IsBad(const RouterID& r, uint64_t chances)
{

@ -33,6 +33,12 @@ namespace llarp
bool
IsGood(uint64_t chances) const;
bool
IsGoodForConnect(uint64_t chances) const;
bool
IsGoodForPath(uint64_t chances) const;
/// decay stats
void
Decay();
@ -52,10 +58,21 @@ namespace llarp
{
}
/// generic variant
bool
IsBad(const RouterID& r, uint64_t chances = 8)
LOCKS_EXCLUDED(m_ProfilesMutex);
/// check if this rotuer should have paths built over it
bool
IsBadForPath(const RouterID & r, uint64_t chances = 8)
LOCK_RETURNED(m_ProfilesMutex);
/// check if this router should be connected directly to
bool
IsBadForConnect(const RouterID & r, uint64_t chances = 8)
LOCKS_EXCLUDED(m_ProfilesMutex);
void
MarkTimeout(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex);

@ -639,7 +639,7 @@ namespace llarp
// try connecting async
TryConnectAsync(rc, 5);
}
else if(IsServiceNode() || !routerProfiling().IsBad(remote))
else if(IsServiceNode())
{
if(dht()->impl->HasRouterLookup(remote))
return;

@ -113,7 +113,7 @@ namespace llarp
m_IntroSet.I.clear();
for(const auto& intro : I)
{
if(router->routerProfiling().IsBad(intro.router))
if(router->routerProfiling().IsBadForPath(intro.router))
continue;
m_IntroSet.I.push_back(intro);
}
@ -1431,7 +1431,7 @@ namespace llarp
if(c)
c->UpdateIntroSet(true);
},
5000, false);
5000, true);
}
bool
@ -1445,13 +1445,7 @@ namespace llarp
{
if(hop == 0)
{
// first hop
if(router->NumberOfConnectedRouters())
{
if(!router->GetRandomConnectedRouter(hops[0]))
return false;
}
else
if(!SelectHop(nodedb, hops[0], hops[0], 0, path::ePathRoleAny))
return false;
}
else if(hop == numHops - 1)
@ -1466,10 +1460,10 @@ namespace llarp
size_t tries = 5;
do
{
nodedb->select_random_hop(hops[hop - 1], hops[hop], hop);
nodedb->select_random_hop_excluding(hops[hop], {hops[hop - 1].pubkey, remote});
--tries;
} while(
m_Endpoint->Router()->routerProfiling().IsBad(hops[hop].pubkey)
m_Endpoint->Router()->routerProfiling().IsBadForPath(hops[hop].pubkey)
&& tries > 0);
return tries > 0;
}
@ -1492,7 +1486,7 @@ namespace llarp
{
if(intro.ExpiresSoon(now))
continue;
if(router->routerProfiling().IsBad(intro.router))
if(router->routerProfiling().IsBadForPath(intro.router))
continue;
auto itr = m_BadIntros.find(intro);
if(itr == m_BadIntros.end() && intro.router == m_NextIntro.router)

Loading…
Cancel
Save