path peer profiling

propagate introsets better
pull/15/head
Jeff Becker 6 years ago
parent 354df88367
commit f5b8d552e1
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -283,18 +283,19 @@ namespace llarp
}
void
NewTX(const TXOwner& owner, const K& k, TX< K, V >* t)
NewTX(const TXOwner& owner, const K& k, TX< K, V >* t,
bool forceStart = false)
{
tx.emplace(owner, std::unique_ptr< TX< K, V > >(t));
auto n = waiting.count(k);
waiting.insert(std::make_pair(k, owner));
auto itr = timeouts.find(k);
if(itr == timeouts.end())
{
timeouts.insert(
std::make_pair(k, llarp_time_now_ms() + requestTimeoutMS));
if(n == 0)
}
if(forceStart)
t->Start(owner);
}

@ -262,17 +262,7 @@ namespace llarp
}
void
EnterState(PathStatus st)
{
if(st == ePathTimeout)
llarp::LogInfo("path ", Name(), " has timed out");
else if(st == ePathBuilding)
{
llarp::LogInfo("path ", Name(), " is building");
buildStarted = llarp_time_now_ms();
}
_status = st;
}
EnterState(PathStatus st);
llarp_time_t
ExpireTime() const

@ -3,6 +3,7 @@
#include <llarp/bencode.hpp>
#include <llarp/threading.hpp>
#include <llarp/router_id.hpp>
#include <llarp/path.hpp>
#include <map>
@ -10,9 +11,11 @@ namespace llarp
{
struct RouterProfile : public IBEncodeMessage
{
static constexpr size_t MaxSize = 128;
static constexpr size_t MaxSize = 256;
uint64_t connectTimeoutCount = 0;
uint64_t connectGoodCount = 0;
uint64_t pathSuccessCount = 0;
uint64_t pathFailCount = 0;
RouterProfile() : IBEncodeMessage(){};
~RouterProfile(){};
@ -24,7 +27,7 @@ namespace llarp
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf);
bool
IsGood() const;
IsGood(uint64_t chances) const;
};
struct Profiling : public IBEncodeMessage
@ -35,7 +38,7 @@ namespace llarp
}
bool
IsBad(const RouterID& r);
IsBad(const RouterID& r, uint64_t chances = 8);
void
MarkSuccess(const RouterID& r);
@ -55,6 +58,12 @@ namespace llarp
bool
Save(const char* fname);
void
MarkPathFail(path::Path* p);
void
MarkPathSuccess(path::Path* p);
private:
typedef llarp::util::Lock lock_t;
typedef llarp::util::Mutex mtx_t;

@ -512,8 +512,8 @@ namespace llarp
TXOwner peer(tellpeer, ++ids);
service::Address addr = introset.A.Addr();
pendingIntrosetLookups.NewTX(
asker, addr,
new PublishServiceJob(asker, introset, this, S, exclude));
asker, addr, new PublishServiceJob(asker, introset, this, S, exclude),
true);
}
void

@ -381,6 +381,21 @@ namespace llarp
return hops[0].rc.pubkey;
}
void
Path::EnterState(PathStatus st)
{
if(st == ePathTimeout)
{
llarp::LogInfo("path ", Name(), " has timed out");
}
else if(st == ePathBuilding)
{
llarp::LogInfo("path ", Name(), " is building");
buildStarted = llarp_time_now_ms();
}
_status = st;
}
void
Path::Tick(llarp_time_t now, llarp_router* r)
{
@ -394,7 +409,7 @@ namespace llarp
auto dlt = now - buildStarted;
if(dlt >= PATH_BUILD_TIMEOUT)
{
llarp::LogInfo("timed out with ", dlt, " ms");
r->routerProfiling.MarkPathFail(this);
EnterState(ePathTimeout);
return;
}
@ -417,10 +432,16 @@ namespace llarp
if(m_CheckForDead)
{
if(m_CheckForDead(this, dlt))
{
r->routerProfiling.MarkPathFail(this);
EnterState(ePathTimeout);
}
}
else if(dlt >= 10000)
{
r->routerProfiling.MarkPathFail(this);
EnterState(ePathTimeout);
}
}
}
@ -548,6 +569,8 @@ namespace llarp
m_BuiltHook(this);
m_BuiltHook = nullptr;
r->routerProfiling.MarkPathSuccess(this);
// persist session with upstream router until the path is done
r->PersistSessionUntil(Upstream(), intro.expiresAt);

@ -11,6 +11,10 @@ namespace llarp
if(!BEncodeWriteDictInt("g", connectGoodCount, buf))
return false;
if(!BEncodeWriteDictInt("p", pathSuccessCount, buf))
return false;
if(!BEncodeWriteDictInt("s", pathFailCount, buf))
return false;
if(!BEncodeWriteDictInt("t", connectTimeoutCount, buf))
return false;
if(!BEncodeWriteDictInt("v", version, buf))
@ -29,23 +33,29 @@ namespace llarp
return false;
if(!BEncodeMaybeReadDictInt("v", version, read, k, buf))
return false;
if(!BEncodeMaybeReadDictInt("s", pathFailCount, read, k, buf))
return false;
if(!BEncodeMaybeReadDictInt("p", pathSuccessCount, read, k, buf))
return false;
return read;
}
bool
RouterProfile::IsGood() const
RouterProfile::IsGood(uint64_t chances) const
{
return connectTimeoutCount <= connectGoodCount;
return connectTimeoutCount <= connectGoodCount
/// 4 hops + N chances
&& (pathSuccessCount * 4 * chances) >= (pathFailCount / chances);
}
bool
Profiling::IsBad(const RouterID& r)
Profiling::IsBad(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.IsGood();
return !itr->second.IsGood(chances);
}
void
@ -62,6 +72,27 @@ namespace llarp
m_Profiles[r].connectGoodCount += 1;
}
void
Profiling::MarkPathFail(path::Path* p)
{
lock_t lock(m_ProfilesMutex);
for(const auto& hop : p->hops)
{
// TODO: also mark bad?
m_Profiles[hop.rc.pubkey].pathFailCount += 1;
}
}
void
Profiling::MarkPathSuccess(path::Path* p)
{
lock_t lock(m_ProfilesMutex);
for(const auto& hop : p->hops)
{
m_Profiles[hop.rc.pubkey].pathSuccessCount += 1;
}
}
bool
Profiling::Save(const char* fname)
{

@ -692,6 +692,7 @@ namespace llarp
}
}
llarp::LogError(Name(), " has no more usable intros");
UpdateIntroSet();
}
return true;
}

Loading…
Cancel
Save