From d1169ee86d07ad016077c5397fc1ba4a32e37f5b Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Mar 2013 16:22:09 -0800 Subject: [PATCH 1/3] Make sure all load sources are named. --- src/cpp/database/SqliteDatabase.cpp | 2 +- src/cpp/ripple/JobQueue.h | 12 ++++++------ src/cpp/ripple/Ledger.cpp | 4 ++-- src/cpp/ripple/LedgerConsensus.cpp | 2 +- src/cpp/ripple/LoadMonitor.h | 5 +++-- src/cpp/ripple/NetworkOPs.cpp | 4 ++-- src/cpp/ripple/OrderBookDB.cpp | 2 +- src/cpp/ripple/Pathfinder.cpp | 2 +- src/cpp/ripple/Peer.cpp | 2 +- src/cpp/ripple/RPCHandler.cpp | 2 +- src/cpp/ripple/ValidationCollection.cpp | 2 +- 11 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/cpp/database/SqliteDatabase.cpp b/src/cpp/database/SqliteDatabase.cpp index e9e70fed4a..1033dcf4e3 100644 --- a/src/cpp/database/SqliteDatabase.cpp +++ b/src/cpp/database/SqliteDatabase.cpp @@ -223,7 +223,7 @@ void SqliteDatabase::doHook(const char *db, int pages) { walRunning = true; if (mWalQ) - mWalQ->addJob(jtWAL, std::string("WAL:") + db, boost::bind(&SqliteDatabase::runWal, this)); + mWalQ->addJob(jtWAL, std::string("WAL:") + mHost, boost::bind(&SqliteDatabase::runWal, this)); else boost::thread(boost::bind(&SqliteDatabase::runWal, this)).detach(); } diff --git a/src/cpp/ripple/JobQueue.h b/src/cpp/ripple/JobQueue.h index 386ccf5ff4..76602678f4 100644 --- a/src/cpp/ripple/JobQueue.h +++ b/src/cpp/ripple/JobQueue.h @@ -66,11 +66,11 @@ public: Job(JobType type, const std::string& name, uint64 index, LoadMonitor& lm, const boost::function& job) : mType(type), mJobIndex(index), mJob(job), mName(name) { - mLoadMonitor = boost::make_shared(boost::ref(lm), false, 1); + mLoadMonitor = boost::make_shared(boost::ref(lm), name, false, 1); } JobType getType() const { return mType; } - void doJob(void) { mLoadMonitor->start(); mJob(*this); mLoadMonitor->setName(mName); } + void doJob(void) { mLoadMonitor->start(); mJob(*this); mLoadMonitor->reName(mName); } void rename(const std::string& n) { mName = n; } bool operator<(const Job& j) const; @@ -110,10 +110,10 @@ public: void shutdown(); void setThreadCount(int c = 0); - LoadEvent::pointer getLoadEvent(JobType t) - { return boost::make_shared(boost::ref(mJobLoads[t]), true, 1); } - LoadEvent::autoptr getLoadEventAP(JobType t) - { return LoadEvent::autoptr(new LoadEvent(mJobLoads[t], true, 1)); } + LoadEvent::pointer getLoadEvent(JobType t, const std::string& name) + { return boost::make_shared(boost::ref(mJobLoads[t]), name, true, 1); } + LoadEvent::autoptr getLoadEventAP(JobType t, const std::string& name) + { return LoadEvent::autoptr(new LoadEvent(mJobLoads[t], name, true, 1)); } int isOverloaded(); Json::Value getJson(int c = 0); diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 3937964eb7..4b21ddd41e 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -1530,8 +1530,8 @@ void Ledger::pendSave(bool fromConsensus) ++sPendingSaves; } - boost::thread(boost::bind(&Ledger::saveAcceptedLedger, shared_from_this(), - fromConsensus, theApp->getJobQueue().getLoadEvent(jtDISK))).detach(); + boost::thread(boost::bind(&Ledger::saveAcceptedLedger, shared_from_this(), fromConsensus, + theApp->getJobQueue().getLoadEvent(jtDISK, fromConsensus ? "Ledger::cSave" : "Ledger::save"))).detach(); } diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index 623cd542fa..dcb7f14712 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -1091,7 +1091,7 @@ void LedgerConsensus::beginAccept(bool synchronous) else { theApp->getIOService().post(boost::bind(&LedgerConsensus::accept, shared_from_this(), consensusSet, - theApp->getJobQueue().getLoadEvent(jtACCEPTLEDGER))); + theApp->getJobQueue().getLoadEvent(jtACCEPTLEDGER, "LedgerConsensus::beginAccept"))); } } diff --git a/src/cpp/ripple/LoadMonitor.h b/src/cpp/ripple/LoadMonitor.h index 4989f1e14d..c1328a7e86 100644 --- a/src/cpp/ripple/LoadMonitor.h +++ b/src/cpp/ripple/LoadMonitor.h @@ -64,7 +64,8 @@ protected: boost::posix_time::ptime mStartTime; public: - LoadEvent(LoadMonitor& monitor, bool shouldStart, int count) : mMonitor(monitor), mRunning(false), mCount(count) + LoadEvent(LoadMonitor& monitor, const std::string& name, bool shouldStart, int count) : + mMonitor(monitor), mRunning(false), mCount(count), mName(name) { mStartTime = boost::posix_time::microsec_clock::universal_time(); if (shouldStart) @@ -77,7 +78,7 @@ public: stop(); } - void setName(const std::string& name) + void reName(const std::string& name) { mName = name; } diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 93b87b0869..d2c8d974ec 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -259,7 +259,7 @@ void NetworkOPs::runTransactionQueue() return; { - LoadEvent::autoptr ev = theApp->getJobQueue().getLoadEventAP(jtTXN_PROC); + LoadEvent::autoptr ev = theApp->getJobQueue().getLoadEventAP(jtTXN_PROC, "runTxnQ"); boost::recursive_mutex::scoped_lock sl(theApp->getMasterLock()); @@ -328,7 +328,7 @@ void NetworkOPs::runTransactionQueue() Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, stCallback callback) { - LoadEvent::autoptr ev = theApp->getJobQueue().getLoadEventAP(jtTXN_PROC); + LoadEvent::autoptr ev = theApp->getJobQueue().getLoadEventAP(jtTXN_PROC, "ProcessTXN"); int newFlags = theApp->getSuppression().getFlags(trans->getID()); if ((newFlags & SF_BAD) != 0) diff --git a/src/cpp/ripple/OrderBookDB.cpp b/src/cpp/ripple/OrderBookDB.cpp index b17c98ab96..61a1ef0c97 100644 --- a/src/cpp/ripple/OrderBookDB.cpp +++ b/src/cpp/ripple/OrderBookDB.cpp @@ -26,7 +26,7 @@ void OrderBookDB::setup(Ledger::ref ledger) return; mSeq = ledger->getLedgerSeq(); - LoadEvent::autoptr ev = theApp->getJobQueue().getLoadEventAP(jtOB_SETUP); + LoadEvent::autoptr ev = theApp->getJobQueue().getLoadEventAP(jtOB_SETUP, "OrderBookDB::setup"); mXRPOrders.clear(); mIssuerMap.clear(); diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 1a2edc8bec..8548081b16 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -141,7 +141,7 @@ Pathfinder::Pathfinder(Ledger::ref ledger, theApp->getOrderBookDB().setup(mLedger); - mLoadMonitor = theApp->getJobQueue().getLoadEvent(jtPATH_FIND); + mLoadMonitor = theApp->getJobQueue().getLoadEvent(jtPATH_FIND, "FindPath"); // Construct the default path for later comparison. diff --git a/src/cpp/ripple/Peer.cpp b/src/cpp/ripple/Peer.cpp index e8a8b88154..122228323a 100644 --- a/src/cpp/ripple/Peer.cpp +++ b/src/cpp/ripple/Peer.cpp @@ -424,7 +424,7 @@ void Peer::processReadBuffer() // std::cerr << "Peer::processReadBuffer: " << mIpPort.first << " " << mIpPort.second << std::endl; - LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtPEER)); + LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtPEER, "Peer::read")); boost::recursive_mutex::scoped_lock sl(theApp->getMasterLock()); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index aef20331b5..be26949a61 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -2879,7 +2879,7 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole) cLog(lsTRACE) << "COMMAND:" << strCommand; cLog(lsTRACE) << "REQUEST:" << jvRequest; - LoadEvent::autoptr le(theApp->getJobQueue().getLoadEventAP(jtRPC)); + LoadEvent::autoptr le(theApp->getJobQueue().getLoadEventAP(jtRPC, "RPC")); mRole = iRole; diff --git a/src/cpp/ripple/ValidationCollection.cpp b/src/cpp/ripple/ValidationCollection.cpp index 699dc8afb4..c67d1aa8b9 100644 --- a/src/cpp/ripple/ValidationCollection.cpp +++ b/src/cpp/ripple/ValidationCollection.cpp @@ -299,7 +299,7 @@ void ValidationCollection::condWrite() void ValidationCollection::doWrite(Job&) { - LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtDISK)); + LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtDISK, "ValidationWrite")); static boost::format insVal("INSERT INTO Validations " "(LedgerHash,NodePubKey,SignTime,RawData) VALUES ('%s','%s','%u',%s);"); From b8fdb3b65934c84348540513a9d18a70a1546e4c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Mar 2013 18:12:33 -0800 Subject: [PATCH 2/3] Cleanups. --- src/cpp/ripple/Pathfinder.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 8548081b16..1be85e3d4b 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -285,15 +285,18 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax continue; } - cLog(lsTRACE) << "findPaths: finish? account: " << (speEnd.mAccountID == mDstAccountID); - cLog(lsTRACE) << "findPaths: finish? currency: " << (speEnd.mCurrencyID == mDstAmount.getCurrency()); - cLog(lsTRACE) << "findPaths: finish? issuer: " - << RippleAddress::createHumanAccountID(speEnd.mIssuerID) - << " / " - << RippleAddress::createHumanAccountID(mDstAmount.getIssuer()) - << " / " - << RippleAddress::createHumanAccountID(mDstAccountID); - cLog(lsDEBUG) << "findPaths: finish? issuer is desired: " << (speEnd.mIssuerID == mDstAmount.getIssuer()); + if (tLog(lsTRACE) + { + cLog(lsTRACE) << "findPaths: finish? account: " << (speEnd.mAccountID == mDstAccountID); + cLog(lsTRACE) << "findPaths: finish? currency: " << (speEnd.mCurrencyID == mDstAmount.getCurrency()); + cLog(lsTRACE) << "findPaths: finish? issuer: " + << RippleAddress::createHumanAccountID(speEnd.mIssuerID) + << " / " + << RippleAddress::createHumanAccountID(mDstAmount.getIssuer()) + << " / " + << RippleAddress::createHumanAccountID(mDstAccountID); + cLog(lsTRACE) << "findPaths: finish? issuer is desired: " << (speEnd.mIssuerID == mDstAmount.getIssuer()); + } // YYY Allows going through self. Is this wanted? if (speEnd.mAccountID == mDstAccountID // Tail is destination account. @@ -343,7 +346,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax { // Path is at maximum size. Don't want to add more. - cLog(lsDEBUG) + cLog(lsTRACE) << boost::str(boost::format("findPaths: dropping: path would exceed max steps")); continue; From ce401dffb6894df8187950d90c40b012d3d80483 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Mar 2013 18:57:44 -0800 Subject: [PATCH 3/3] Speed up path finding by about 35%. --- src/cpp/ripple/AccountItems.h | 1 + src/cpp/ripple/Pathfinder.cpp | 13 ++++++++++--- src/cpp/ripple/RPCHandler.cpp | 2 +- src/cpp/ripple/RippleCalc.cpp | 2 +- src/cpp/ripple/RippleState.cpp | 6 +++--- src/cpp/ripple/RippleState.h | 8 ++++---- src/cpp/ripple/SHAMap.cpp | 3 ++- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/cpp/ripple/AccountItems.h b/src/cpp/ripple/AccountItems.h index 3382dff265..f72e9f558a 100644 --- a/src/cpp/ripple/AccountItems.h +++ b/src/cpp/ripple/AccountItems.h @@ -35,6 +35,7 @@ class AccountItems void fillItems(const uint160& accountID, Ledger::ref ledger); public: + typedef boost::shared_ptr pointer; AccountItems(const uint160& accountID, Ledger::ref ledger, AccountItem::pointer ofType); diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 1be85e3d4b..fbcd7ce3e2 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -205,6 +205,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax } LedgerEntrySet lesActive(mLedger); + boost::unordered_map aiMap; SLE::pointer sleSrc = lesActive.entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(mSrcAccountID)); if (!sleSrc) @@ -285,7 +286,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax continue; } - if (tLog(lsTRACE) + if (sLog(lsTRACE)) { cLog(lsTRACE) << "findPaths: finish? account: " << (speEnd.mAccountID == mDstAccountID); cLog(lsTRACE) << "findPaths: finish? currency: " << (speEnd.mCurrencyID == mDstAmount.getCurrency()); @@ -387,7 +388,13 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax // Last element is for non-XRP, continue by adding ripple lines and order books. // Create new paths for each outbound account not already in the path. - AccountItems rippleLines(speEnd.mAccountID, mLedger, AccountItem::pointer(new RippleState())); + boost::unordered_map::iterator it = aiMap.find(speEnd.mAccountID); + if (it == aiMap.end()) + it = aiMap.insert(std::make_pair(speEnd.mAccountID, + boost::make_shared( + boost::cref(speEnd.mAccountID), boost::cref(mLedger), AccountItem::pointer(new RippleState())))).first; + AccountItems& rippleLines = *it->second; + SLE::pointer sleEnd = lesActive.entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(speEnd.mAccountID)); tLog(!sleEnd, lsDEBUG) @@ -403,7 +410,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems()) { RippleState* rspEntry = (RippleState*) item.get(); - const uint160 uPeerID = rspEntry->getAccountIDPeer().getAccountID(); + const uint160 uPeerID = rspEntry->getAccountIDPeer(); if (spPath.hasSeen(uPeerID, speEnd.mCurrencyID, uPeerID)) { diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index be26949a61..0e7b9a949a 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -929,7 +929,7 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest) Json::Value jPeer = Json::Value(Json::objectValue); - jPeer["account"] = line->getAccountIDPeer().humanAccountID(); + jPeer["account"] = RippleAddress::createHumanAccountID(line->getAccountIDPeer()); // Amount reported is positive if current account holds other account's IOUs. // Amount reported is negative if other account holds current account's IOUs. jPeer["balance"] = saBalance.getText(); diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index a6fa7d7440..3ec5f8b578 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -2521,7 +2521,7 @@ cLog(lsDEBUG) << boost::str(boost::format("rippleCalc: Build direct: status: %s" } } - cLog(lsINFO) << "rippleCalc: Paths in set: " << spsPaths.size(); + cLog(lsTRACE) << "rippleCalc: Paths in set: " << spsPaths.size(); int iIndex = 0; BOOST_FOREACH(const STPath& spPath, spsPaths) diff --git a/src/cpp/ripple/RippleState.cpp b/src/cpp/ripple/RippleState.cpp index 1ec6ebdaf8..65facb7f11 100644 --- a/src/cpp/ripple/RippleState.cpp +++ b/src/cpp/ripple/RippleState.cpp @@ -19,8 +19,8 @@ RippleState::RippleState(SerializedLedgerEntry::ref ledgerEntry) : AccountItem(l mLowLimit = mLedgerEntry->getFieldAmount(sfLowLimit); mHighLimit = mLedgerEntry->getFieldAmount(sfHighLimit); - mLowID = RippleAddress::createAccountID(mLowLimit.getIssuer()); - mHighID = RippleAddress::createAccountID(mHighLimit.getIssuer()); + mLowID = mLowLimit.getIssuer(); + mHighID = mHighLimit.getIssuer(); mLowQualityIn = mLedgerEntry->getFieldU32(sfLowQualityIn); mLowQualityOut = mLedgerEntry->getFieldU32(sfLowQualityOut); @@ -35,7 +35,7 @@ RippleState::RippleState(SerializedLedgerEntry::ref ledgerEntry) : AccountItem(l void RippleState::setViewAccount(const uint160& accountID) { - bool bViewLowestNew = mLowID.getAccountID() == accountID; + bool bViewLowestNew = mLowID == accountID; if (bViewLowestNew != mViewLowest) { diff --git a/src/cpp/ripple/RippleState.h b/src/cpp/ripple/RippleState.h index ac79673368..df8b7fdc56 100644 --- a/src/cpp/ripple/RippleState.h +++ b/src/cpp/ripple/RippleState.h @@ -19,8 +19,8 @@ public: private: uint32 mFlags; - RippleAddress mLowID; - RippleAddress mHighID; + uint160 mLowID; + uint160 mHighID; STAmount mLowLimit; STAmount mHighLimit; @@ -44,8 +44,8 @@ public: void setViewAccount(const uint160& accountID); - const RippleAddress getAccountID() const { return mViewLowest ? mLowID : mHighID; } - const RippleAddress getAccountIDPeer() const { return !mViewLowest ? mLowID : mHighID; } + const uint160& getAccountID() const { return mViewLowest ? mLowID : mHighID; } + const uint160& getAccountIDPeer() const { return !mViewLowest ? mLowID : mHighID; } bool getAuth() const { return isSetBit(mFlags, mViewLowest ? lsfLowAuth : lsfHighAuth); } bool getAuthPeer() const { return isSetBit(mFlags, !mViewLowest ? lsfLowAuth : lsfHighAuth); } diff --git a/src/cpp/ripple/SHAMap.cpp b/src/cpp/ripple/SHAMap.cpp index 77051f17ff..89874875af 100644 --- a/src/cpp/ripple/SHAMap.cpp +++ b/src/cpp/ripple/SHAMap.cpp @@ -194,7 +194,8 @@ SHAMapTreeNode* SHAMap::walkToPointer(const uint256& id) { int branch = inNode->selectBranch(id); const uint256& nextHash = inNode->getChildHash(branch); - if (nextHash.isZero()) return NULL; + if (nextHash.isZero()) + return NULL; inNode = getNodePointer(inNode->getChildNodeID(branch), nextHash); assert(inNode); }