mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-27 15:47:30 -04:00
tried to improve DHT size estimation code
This commit is contained in:
parent
b77e895691
commit
9f9c34ca13
2 changed files with 43 additions and 48 deletions
|
@ -1024,6 +1024,11 @@ int bdSpace::getDhtBucket(const int idx, bdBucket &bucket)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t bdSpace::calcNetworkSize()
|
uint32_t bdSpace::calcNetworkSize()
|
||||||
|
{
|
||||||
|
return calcNetworkSizeWithFlag(~0u) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t bdSpace::calcNetworkSizeWithFlag(uint32_t withFlag)
|
||||||
{
|
{
|
||||||
std::vector<bdBucket>::iterator it;
|
std::vector<bdBucket>::iterator it;
|
||||||
|
|
||||||
|
@ -1031,76 +1036,66 @@ uint32_t bdSpace::calcNetworkSize()
|
||||||
unsigned long long sum = 0;
|
unsigned long long sum = 0;
|
||||||
unsigned long long no_peers = 0;
|
unsigned long long no_peers = 0;
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
bool doPrint = false;
|
// bool doPrint = false;
|
||||||
bool doAvg = false;
|
// bool doAvg = false;
|
||||||
|
|
||||||
|
std::cerr << "Estimating DHT network size. Flags=" << std::hex << withFlag << std::dec << std::endl;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(it = buckets.begin(); it != buckets.end(); it++, i++)
|
for(it = buckets.begin(); it != buckets.end(); it++, i++)
|
||||||
{
|
{
|
||||||
int size = it->entries.size();
|
int size = 0;
|
||||||
|
std::list<bdPeer>::iterator lit;
|
||||||
|
for(lit = it->entries.begin(); lit != it->entries.end(); lit++)
|
||||||
|
if (withFlag & lit->mPeerFlags)
|
||||||
|
size++;
|
||||||
|
|
||||||
int shift = BITDHT_KEY_BITLEN - i;
|
int shift = BITDHT_KEY_BITLEN - i;
|
||||||
bool toBig = false;
|
|
||||||
|
|
||||||
if (shift > BITDHT_ULLONG_BITS - mFns->bdBucketBitSize() - 1)
|
if (shift > BITDHT_ULLONG_BITS - mFns->bdBucketBitSize() - 1)
|
||||||
{
|
continue ;
|
||||||
toBig = true;
|
|
||||||
shift = BITDHT_ULLONG_BITS - mFns->bdBucketBitSize() - 1;
|
|
||||||
}
|
|
||||||
unsigned long long no_nets = ((unsigned long long) 1 << shift);
|
unsigned long long no_nets = ((unsigned long long) 1 << shift);
|
||||||
|
|
||||||
/* use doPrint so it acts as a single switch */
|
// /* use doPrint so it acts as a single switch */
|
||||||
if (size && !doAvg && !doPrint)
|
// if (size && !doAvg && !doPrint)
|
||||||
{
|
// doAvg = true;
|
||||||
doAvg = true;
|
//
|
||||||
}
|
// if (size && !doPrint)
|
||||||
|
// doPrint = true;
|
||||||
|
|
||||||
if (size && !doPrint)
|
// if (size == 0)
|
||||||
{
|
// {
|
||||||
doPrint = true;
|
// /* reset counters - if empty slot - to discount outliers in average */
|
||||||
}
|
// sum = 0;
|
||||||
|
// no_peers = 0;
|
||||||
|
// count = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
if (size == 0)
|
|
||||||
{
|
|
||||||
/* reset counters - if empty slot - to discount outliers in average */
|
|
||||||
sum = 0;
|
|
||||||
no_peers = 0;
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!toBig)
|
|
||||||
{
|
|
||||||
no_peers = no_nets * size;
|
no_peers = no_nets * size;
|
||||||
}
|
|
||||||
|
|
||||||
if (doPrint && doAvg && !toBig)
|
if(size < mFns->bdNodesPerBucket() && size > 0)
|
||||||
{
|
|
||||||
if (size == mFns->bdNodesPerBucket())
|
|
||||||
{
|
|
||||||
/* last average */
|
|
||||||
doAvg = false;
|
|
||||||
}
|
|
||||||
if (no_peers != 0)
|
|
||||||
{
|
{
|
||||||
sum += no_peers;
|
sum += no_peers;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
std::cerr << " Bucket " << shift << ": " << size << " / " << mFns->bdNodesPerBucket() << " peers. no_nets=" << no_nets << ". no_peers=" << no_peers << "." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t NetSize = 0;
|
uint32_t NetSize = 0;
|
||||||
if (count != 0)
|
if (count != 0)
|
||||||
{
|
|
||||||
NetSize = sum / count;
|
NetSize = sum / count;
|
||||||
}
|
|
||||||
|
std::cerr << "Estimated net size: " << NetSize << ". Old style estimate: " << calcNetworkSizeWithFlag_old(withFlag) << std::endl;
|
||||||
|
|
||||||
//std::cerr << "bdSpace::calcNetworkSize() : " << NetSize;
|
//std::cerr << "bdSpace::calcNetworkSize() : " << NetSize;
|
||||||
//std::cerr << std::endl;
|
//std::cerr << std::endl;
|
||||||
|
|
||||||
return NetSize;
|
return NetSize;
|
||||||
}
|
}
|
||||||
|
uint32_t bdSpace::calcNetworkSizeWithFlag_old(uint32_t withFlag)
|
||||||
uint32_t bdSpace::calcNetworkSizeWithFlag(uint32_t withFlag)
|
|
||||||
{
|
{
|
||||||
std::vector<bdBucket>::iterator it;
|
std::vector<bdBucket>::iterator it;
|
||||||
|
|
||||||
|
@ -1190,7 +1185,6 @@ uint32_t bdSpace::calcNetworkSizeWithFlag(uint32_t withFlag)
|
||||||
return NetSize;
|
return NetSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t bdSpace::calcSpaceSize()
|
uint32_t bdSpace::calcSpaceSize()
|
||||||
{
|
{
|
||||||
std::vector<bdBucket>::iterator it;
|
std::vector<bdBucket>::iterator it;
|
||||||
|
|
|
@ -184,6 +184,7 @@ int getDhtBucket(const int idx, bdBucket &bucket);
|
||||||
|
|
||||||
uint32_t calcNetworkSize();
|
uint32_t calcNetworkSize();
|
||||||
uint32_t calcNetworkSizeWithFlag(uint32_t withFlag);
|
uint32_t calcNetworkSizeWithFlag(uint32_t withFlag);
|
||||||
|
uint32_t calcNetworkSizeWithFlag_old(uint32_t withFlag);
|
||||||
uint32_t calcSpaceSize();
|
uint32_t calcSpaceSize();
|
||||||
uint32_t calcSpaceSizeWithFlag(uint32_t withFlag);
|
uint32_t calcSpaceSizeWithFlag(uint32_t withFlag);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue