mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 13:35:54 +00:00
Be smarter about when we grab fetch packs.
This commit is contained in:
@@ -284,7 +284,7 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theApp->getOPs().shouldFetchPack() && (ledgerSeq > 40000))
|
if (theApp->getOPs().shouldFetchPack(ledgerSeq) && (ledgerSeq > 40000))
|
||||||
{ // refill our fetch pack
|
{ // refill our fetch pack
|
||||||
Ledger::pointer nextLedger = mLedgerHistory.getLedgerBySeq(ledgerSeq + 1);
|
Ledger::pointer nextLedger = mLedgerHistory.getLedgerBySeq(ledgerSeq + 1);
|
||||||
if (nextLedger)
|
if (nextLedger)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ NetworkOPs::NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedge
|
|||||||
mMode(omDISCONNECTED), mNeedNetworkLedger(false), mProposing(false), mValidating(false),
|
mMode(omDISCONNECTED), mNeedNetworkLedger(false), mProposing(false), mValidating(false),
|
||||||
mNetTimer(io_service), mLedgerMaster(pLedgerMaster), mCloseTimeOffset(0), mLastCloseProposers(0),
|
mNetTimer(io_service), mLedgerMaster(pLedgerMaster), mCloseTimeOffset(0), mLastCloseProposers(0),
|
||||||
mLastCloseConvergeTime(1000 * LEDGER_IDLE_INTERVAL), mLastValidationTime(0),
|
mLastCloseConvergeTime(1000 * LEDGER_IDLE_INTERVAL), mLastValidationTime(0),
|
||||||
mFetchPack("FetchPack", 2048, 30), mLastFetchPack(0),
|
mFetchPack("FetchPack", 2048, 30), mLastFetchPack(0), mFetchSeq(static_cast<uint32>(-1)),
|
||||||
mLastLoadBase(256), mLastLoadFactor(256)
|
mLastLoadBase(256), mLastLoadFactor(256)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -2091,13 +2091,19 @@ bool NetworkOPs::getFetchPack(const uint256& hash, std::vector<unsigned char>& d
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkOPs::shouldFetchPack()
|
bool NetworkOPs::shouldFetchPack(uint32 seq)
|
||||||
{
|
{
|
||||||
uint32 now = getNetworkTimeNC();
|
uint32 now = getNetworkTimeNC();
|
||||||
if ((mLastFetchPack == now) || ((mLastFetchPack + 1) == now))
|
if ((mLastFetchPack == now) || ((mLastFetchPack + 1) == now))
|
||||||
return false;
|
return false;
|
||||||
mFetchPack.sweep();
|
if (seq < mFetchSeq) // fetch pack has only data for ledgers ahead of where we are
|
||||||
if (mFetchPack.getCacheSize() > 384)
|
mFetchPack.clear();
|
||||||
|
else
|
||||||
|
mFetchPack.sweep();
|
||||||
|
int size = mFetchPack.getCacheSize();
|
||||||
|
if (size == 0)
|
||||||
|
mFetchSeq = static_cast<uint32>(-1);
|
||||||
|
else if (mFetchPack.getCacheSize() > 384)
|
||||||
return false;
|
return false;
|
||||||
mLastFetchPack = now;
|
mLastFetchPack = now;
|
||||||
return true;
|
return true;
|
||||||
@@ -2108,9 +2114,10 @@ int NetworkOPs::getFetchSize()
|
|||||||
return mFetchPack.getCacheSize();
|
return mFetchPack.getCacheSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkOPs::gotFetchPack(bool progress)
|
void NetworkOPs::gotFetchPack(bool progress, uint32 seq)
|
||||||
{
|
{
|
||||||
mLastFetchPack = 0;
|
mLastFetchPack = 0;
|
||||||
|
mFetchSeq = seq; // earliest pack we have data on
|
||||||
theApp->getJobQueue().addJob(jtLEDGER_DATA, "gotFetchPack",
|
theApp->getJobQueue().addJob(jtLEDGER_DATA, "gotFetchPack",
|
||||||
boost::bind(&LedgerAcquireMaster::gotFetchPack, &theApp->getMasterLedgerAcquire(), _1));
|
boost::bind(&LedgerAcquireMaster::gotFetchPack, &theApp->getMasterLedgerAcquire(), _1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ protected:
|
|||||||
|
|
||||||
TaggedCache< uint256, std::vector<unsigned char> > mFetchPack;
|
TaggedCache< uint256, std::vector<unsigned char> > mFetchPack;
|
||||||
uint32 mLastFetchPack;
|
uint32 mLastFetchPack;
|
||||||
|
uint32 mFetchSeq;
|
||||||
|
|
||||||
uint32 mLastLoadBase;
|
uint32 mLastLoadBase;
|
||||||
uint32 mLastLoadFactor;
|
uint32 mLastLoadFactor;
|
||||||
@@ -262,8 +263,8 @@ public:
|
|||||||
bool stillNeedTXSet(const uint256& hash);
|
bool stillNeedTXSet(const uint256& hash);
|
||||||
void makeFetchPack(Job&, boost::weak_ptr<Peer> peer, boost::shared_ptr<ripple::TMGetObjectByHash> request,
|
void makeFetchPack(Job&, boost::weak_ptr<Peer> peer, boost::shared_ptr<ripple::TMGetObjectByHash> request,
|
||||||
Ledger::pointer wantLedger, Ledger::pointer haveLedger);
|
Ledger::pointer wantLedger, Ledger::pointer haveLedger);
|
||||||
bool shouldFetchPack();
|
bool shouldFetchPack(uint32 seq);
|
||||||
void gotFetchPack(bool progress);
|
void gotFetchPack(bool progress, uint32 seq);
|
||||||
void addFetchPack(const uint256& hash, boost::shared_ptr< std::vector<unsigned char> >& data);
|
void addFetchPack(const uint256& hash, boost::shared_ptr< std::vector<unsigned char> >& data);
|
||||||
bool getFetchPack(const uint256& hash, std::vector<unsigned char>& data);
|
bool getFetchPack(const uint256& hash, std::vector<unsigned char>& data);
|
||||||
int getFetchSize();
|
int getFetchSize();
|
||||||
|
|||||||
@@ -1274,7 +1274,7 @@ void Peer::recvGetObjectByHash(const boost::shared_ptr<ripple::TMGetObjectByHash
|
|||||||
}
|
}
|
||||||
tLog(pLDo && (pLSeq != 0), lsDEBUG) << "Received partial fetch pack for " << pLSeq;
|
tLog(pLDo && (pLSeq != 0), lsDEBUG) << "Received partial fetch pack for " << pLSeq;
|
||||||
if (packet.type() == ripple::TMGetObjectByHash::otFETCH_PACK)
|
if (packet.type() == ripple::TMGetObjectByHash::otFETCH_PACK)
|
||||||
theApp->getOPs().gotFetchPack(progress);
|
theApp->getOPs().gotFetchPack(progress, pLSeq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public:
|
|||||||
void setTargetSize(int size);
|
void setTargetSize(int size);
|
||||||
void setTargetAge(int age);
|
void setTargetAge(int age);
|
||||||
void sweep();
|
void sweep();
|
||||||
|
void clear();
|
||||||
|
|
||||||
bool touch(const key_type& key);
|
bool touch(const key_type& key);
|
||||||
bool del(const key_type& key, bool valid);
|
bool del(const key_type& key, bool valid);
|
||||||
@@ -128,6 +129,12 @@ template<typename c_Key, typename c_Data> int TaggedCache<c_Key, c_Data>::getTra
|
|||||||
return mCache.size();
|
return mCache.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename c_Key, typename c_Data> void TaggedCache<c_Key, c_Data>::clear()
|
||||||
|
{
|
||||||
|
mCache.clear();
|
||||||
|
mCacheCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename c_Key, typename c_Data> void TaggedCache<c_Key, c_Data>::sweep()
|
template<typename c_Key, typename c_Data> void TaggedCache<c_Key, c_Data>::sweep()
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
|
|||||||
Reference in New Issue
Block a user