From b6b455ab3730987fc5f4a231027ac02b82f96afb Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 17 May 2013 03:16:04 -0700 Subject: [PATCH 1/8] Release master lock while getting nodes from a mutable ledger for a peer. --- src/cpp/ripple/Peer.cpp | 14 ++++++++++---- src/cpp/ripple/Peer.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cpp/ripple/Peer.cpp b/src/cpp/ripple/Peer.cpp index 8f9dbd5287..869a7dee80 100644 --- a/src/cpp/ripple/Peer.cpp +++ b/src/cpp/ripple/Peer.cpp @@ -438,7 +438,7 @@ void Peer::processReadBuffer() LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtPEER, "Peer::read")); - boost::recursive_mutex::scoped_lock sl(theApp->getMasterLock()); + ScopedLock sl(theApp->getMasterLock()); // If connected and get a mtHELLO or if not connected and get a non-mtHELLO, wrong message was sent. if (mHelloed == (type == ripple::mtHELLO)) @@ -601,7 +601,7 @@ void Peer::processReadBuffer() event->reName("Peer::getledger"); ripple::TMGetLedger msg; if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) - recvGetLedger(msg); + recvGetLedger(msg, sl); else cLog(lsWARNING) << "parse error: " << type; } @@ -866,7 +866,6 @@ static void checkTransaction(Job&, int flags, SerializedTransaction::pointer stx void Peer::recvTransaction(ripple::TMTransaction& packet) { - Transaction::pointer tx; #ifndef TRUST_NETWORK try @@ -1417,7 +1416,7 @@ void Peer::recvStatus(ripple::TMStatusChange& packet) mMaxLedger = packet.lastseq(); } -void Peer::recvGetLedger(ripple::TMGetLedger& packet) +void Peer::recvGetLedger(ripple::TMGetLedger& packet, ScopedLock& MasterLockHolder) { SHAMap::pointer map; ripple::TMLedgerData reply; @@ -1545,6 +1544,13 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet) return; } + if (ledger->isImmutable()) + MasterLockHolder.unlock(); + else + { + cLog(lsWARNING) << "Request for data from mutable ledger"; + } + // Fill out the reply uint256 lHash = ledger->getHash(); reply.set_ledgerhash(lHash.begin(), lHash.size()); diff --git a/src/cpp/ripple/Peer.h b/src/cpp/ripple/Peer.h index d7bf83834d..8d279583d0 100644 --- a/src/cpp/ripple/Peer.h +++ b/src/cpp/ripple/Peer.h @@ -100,7 +100,7 @@ protected: void recvSearchTransaction(ripple::TMSearchTransaction& packet); void recvGetAccount(ripple::TMGetAccount& packet); void recvAccount(ripple::TMAccount& packet); - void recvGetLedger(ripple::TMGetLedger& packet); + void recvGetLedger(ripple::TMGetLedger& packet, ScopedLock& MasterLockHolder); void recvLedger(const boost::shared_ptr& packet); void recvStatus(ripple::TMStatusChange& packet); void recvPropose(const boost::shared_ptr& packet); From cb9eff134a3bc8dd3317bf53313128982ce83fdf Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 20 May 2013 07:43:21 -0700 Subject: [PATCH 2/8] Update .gitattributes for annoying files that keep changing --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitattributes b/.gitattributes index cde0638659..e60f766261 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,10 @@ # Set default behaviour, in case users don't have core.autocrlf set. * text=auto +# These annoying files +rippled.1 binary +LICENSE binary + # Visual Studio *.sln text eol=crlf *.vcproj text eol=crlf From a6bbef47188eb63b5248809a77020f46d6d691d0 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 21 May 2013 15:39:35 -0700 Subject: [PATCH 3/8] Let 'isValid' inline. --- src/cpp/ripple/RippleAddress.cpp | 5 ----- src/cpp/ripple/RippleAddress.h | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/cpp/ripple/RippleAddress.cpp b/src/cpp/ripple/RippleAddress.cpp index 5914c115b6..4c01574225 100644 --- a/src/cpp/ripple/RippleAddress.cpp +++ b/src/cpp/ripple/RippleAddress.cpp @@ -35,11 +35,6 @@ RippleAddress::RippleAddress() : mIsValid(false) nVersion = VER_NONE; } -bool RippleAddress::isValid() const -{ - return mIsValid; -} - void RippleAddress::clear() { nVersion = VER_NONE; diff --git a/src/cpp/ripple/RippleAddress.h b/src/cpp/ripple/RippleAddress.h index eb19e60d94..d4f916b4f9 100644 --- a/src/cpp/ripple/RippleAddress.h +++ b/src/cpp/ripple/RippleAddress.h @@ -28,7 +28,7 @@ public: RippleAddress(); // For public and private key, checks if they are legal. - bool isValid() const; + bool isValid() const { return mIsValid; } void clear(); bool isSet() const; From 23eafaab8528b13aaf66419a3fdfe042ed9fbb35 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 21 May 2013 15:40:44 -0700 Subject: [PATCH 4/8] doAccountLines micro-optimization. --- src/cpp/ripple/RPCHandler.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 0ec133cf74..a790dd4fa8 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1071,9 +1071,6 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL { jvResult["account"] = raAccount.humanAccountID(); - // XXX This is wrong, we do access the current ledger and do need to worry about changes. - // We access a committed ledger and need not worry about changes. - AccountItems rippleLines(raAccount.getAccountID(), lpLedger, AccountItem::pointer(new RippleState())); Json::Value& jsonLines = (jvResult["lines"] = Json::arrayValue); @@ -1083,9 +1080,9 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL if (!raPeer.isValid() || raPeer.getAccountID() == line->getAccountIDPeer()) { - STAmount saBalance = line->getBalance(); - STAmount saLimit = line->getLimit(); - STAmount saLimitPeer = line->getLimitPeer(); + const STAmount& saBalance = line->getBalance(); + const STAmount& saLimit = line->getLimit(); + const STAmount& saLimitPeer = line->getLimitPeer(); Json::Value& jPeer = jsonLines.append(Json::objectValue); @@ -2610,6 +2607,7 @@ Json::Value RPCHandler::lookupLedger(Json::Value jvRequest, Ledger::pointer& lpL case LEDGER_CURRENT: lpLedger = mNetOps->getCurrentSnapshot(); iLedgerIndex = lpLedger->getLedgerSeq(); + assert(lpLedger->isImmutable() && !lpLedger->isClosed()); break; case LEDGER_CLOSED: From 51ec5787d57a5a08062f9892277d8e7a1ade8460 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 21 May 2013 16:10:23 -0700 Subject: [PATCH 5/8] Track TaggedCache hit rates. --- src/cpp/ripple/TaggedCache.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/cpp/ripple/TaggedCache.h b/src/cpp/ripple/TaggedCache.h index f71f135d01..0058c87a22 100644 --- a/src/cpp/ripple/TaggedCache.h +++ b/src/cpp/ripple/TaggedCache.h @@ -63,16 +63,21 @@ protected: cache_type mCache; // Hold strong reference to recent objects int mLastSweep; + uint64 mHits, mMisses; + public: TaggedCache(const char *name, int size, int age) - : mName(name), mTargetSize(size), mTargetAge(age), mCacheCount(0), mLastSweep(upTime()) { ; } + : mName(name), mTargetSize(size), mTargetAge(age), mCacheCount(0), mLastSweep(upTime()), + mHits(0), mMisses(0) + { ; } int getTargetSize() const; int getTargetAge() const; int getCacheSize(); int getTrackSize(); - int getSweepAge(); + float getHitRate(); + void clearStats(); void setTargetSize(int size); void setTargetAge(int age); @@ -129,6 +134,19 @@ template int TaggedCache::getTra return mCache.size(); } +template float TaggedCache::getHitRate() +{ + boost::recursive_mutex::scoped_lock sl(mLock); + return (static_cast(mHits) * 100) / (1.0 + mHits + mMisses); +} + +template float TaggedCache::clearStats() +{ + boost::recursive_mutex::scoped_lock sl(mLock); + mHits = 0; + mMisses = 0; +} + template void TaggedCache::clear() { boost::recursive_mutex::scoped_lock sl(mLock); @@ -302,20 +320,27 @@ boost::shared_ptr TaggedCache::fetch(const key_type& key) cache_iterator cit = mCache.find(key); if (cit == mCache.end()) + { + ++mMisses; return data_ptr(); + } cache_entry& entry = cit->second; entry.touch(); if (entry.isCached()) + { + ++mHits; return entry.ptr; + } entry.ptr = entry.lock(); if (entry.isCached()) - { + { // independent of cache size, so not counted as a hit ++mCacheCount; return entry.ptr; } mCache.erase(cit); + ++mMisses; return data_ptr(); } From 6b2a6ea03e25666aa5673a94ae0c3919d41d75d6 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 21 May 2013 16:10:51 -0700 Subject: [PATCH 6/8] Report cache hit rates. --- src/cpp/ripple/AcceptedLedger.h | 2 ++ src/cpp/ripple/HashedObject.h | 4 +++- src/cpp/ripple/LedgerHistory.h | 1 + src/cpp/ripple/LedgerMaster.h | 5 +++-- src/cpp/ripple/RPCHandler.cpp | 5 +++++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cpp/ripple/AcceptedLedger.h b/src/cpp/ripple/AcceptedLedger.h index f8de687399..25adc64f86 100644 --- a/src/cpp/ripple/AcceptedLedger.h +++ b/src/cpp/ripple/AcceptedLedger.h @@ -70,6 +70,8 @@ public: int getLedgerSeq() const { return mLedger->getLedgerSeq(); } int getTxnCount() const { return mMap.size(); } + static float getCacheHitRate() { return ALCache.getHitRate(); } + ALTransaction::pointer getTxn(int) const; }; diff --git a/src/cpp/ripple/HashedObject.h b/src/cpp/ripple/HashedObject.h index cfc712f131..7c2ac27f16 100644 --- a/src/cpp/ripple/HashedObject.h +++ b/src/cpp/ripple/HashedObject.h @@ -65,7 +65,9 @@ public: HashedObjectStore(int cacheSize, int cacheAge); - bool isLevelDB() { return mLevelDB; } + bool isLevelDB() { return mLevelDB; } + + float getCacheHitRate() { return mCache.getHitRate(); } bool store(HashedObjectType type, uint32 index, const std::vector& data, const uint256& hash) diff --git a/src/cpp/ripple/LedgerHistory.h b/src/cpp/ripple/LedgerHistory.h index 9ee0ed9e87..cfb9239c4e 100644 --- a/src/cpp/ripple/LedgerHistory.h +++ b/src/cpp/ripple/LedgerHistory.h @@ -15,6 +15,7 @@ public: void addLedger(Ledger::pointer ledger); void addAcceptedLedger(Ledger::pointer ledger, bool fromConsensus); + float getCacheHitRate() { return mLedgersByHash.getHitRate(); } uint256 getLedgerHash(uint32 index); Ledger::pointer getLedgerBySeq(uint32 index); Ledger::pointer getLedgerByHash(const uint256& hash); diff --git a/src/cpp/ripple/LedgerMaster.h b/src/cpp/ripple/LedgerMaster.h index dddffaa42e..33b6344934 100644 --- a/src/cpp/ripple/LedgerMaster.h +++ b/src/cpp/ripple/LedgerMaster.h @@ -157,8 +157,9 @@ public: void resumeAcquiring(); - void tune(int size, int age) { mLedgerHistory.tune(size, age); } - void sweep(void) { mLedgerHistory.sweep(); } + void tune(int size, int age) { mLedgerHistory.tune(size, age); } + void sweep() { mLedgerHistory.sweep(); } + float getCacheHitRate() { return mLedgerHistory.getCacheHitRate(); } void addValidateCallback(callback& c) { mOnValidate.push_back(c); } diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index a790dd4fa8..cf94b00993 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -2304,6 +2304,11 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest, int& cost, ScopedLock ret["write_load"] = theApp->getHashedObjectStore().getWriteLoad(); + ret["SLE_hit_rate"] = theApp->getSLECache().getHitRate(); + ret["node_hit_rate"] = theApp->getHashedObjectStore().getCacheHitRate(); + ret["ledger_hit_rate"] = theApp->getLedgerMaster().getCacheHitRate(); + ret["AL_hit_rate"] = AcceptedLedger::getCacheHitRate(); + std::string uptime; int s = upTime(); textTime(uptime, s, "year", 365*24*60*60); From 72f6d51015f8efefeb15d967fc947e679179d9b3 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 22 May 2013 00:10:02 -0700 Subject: [PATCH 7/8] wrong return type. --- src/cpp/ripple/TaggedCache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/ripple/TaggedCache.h b/src/cpp/ripple/TaggedCache.h index 0058c87a22..53e48a9ace 100644 --- a/src/cpp/ripple/TaggedCache.h +++ b/src/cpp/ripple/TaggedCache.h @@ -140,7 +140,7 @@ template float TaggedCache::getH return (static_cast(mHits) * 100) / (1.0 + mHits + mMisses); } -template float TaggedCache::clearStats() +template void TaggedCache::clearStats() { boost::recursive_mutex::scoped_lock sl(mLock); mHits = 0; From e3efd510cb53ff3865dcc0f35c4a63bfd08cbbf6 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 22 May 2013 07:50:50 -0700 Subject: [PATCH 8/8] Fix double to float conversion warning --- src/cpp/ripple/TaggedCache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/ripple/TaggedCache.h b/src/cpp/ripple/TaggedCache.h index 53e48a9ace..8b05e30e07 100644 --- a/src/cpp/ripple/TaggedCache.h +++ b/src/cpp/ripple/TaggedCache.h @@ -137,7 +137,7 @@ template int TaggedCache::getTra template float TaggedCache::getHitRate() { boost::recursive_mutex::scoped_lock sl(mLock); - return (static_cast(mHits) * 100) / (1.0 + mHits + mMisses); + return (static_cast(mHits) * 100) / (1.0f + mHits + mMisses); } template void TaggedCache::clearStats()