From ca4a2ad10480780679a44e17c5aee72e6c4d20cd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 28 Jun 2013 16:07:32 -0700 Subject: [PATCH] Remove the JSONCache. It was basically a failed experiment. --- Builds/VisualStudio2012/RippleD.vcxproj | 6 - .../VisualStudio2012/RippleD.vcxproj.filters | 6 - modules/ripple_data/ripple_data.cpp | 2 - modules/ripple_data/ripple_data.h | 1 - .../ripple_data/utility/ripple_JSONCache.cpp | 186 ------------------ .../ripple_data/utility/ripple_JSONCache.h | 98 --------- src/cpp/ripple/NetworkOPs.cpp | 3 +- src/cpp/ripple/NetworkOPs.h | 24 --- src/cpp/ripple/RPCHandler.cpp | 2 - 9 files changed, 1 insertion(+), 327 deletions(-) delete mode 100644 modules/ripple_data/utility/ripple_JSONCache.cpp delete mode 100644 modules/ripple_data/utility/ripple_JSONCache.h diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index 2c8ef11bb7..14bac284f5 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -860,12 +860,6 @@ true - - true - true - true - true - true true diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 41be37895d..55195202c4 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -486,9 +486,6 @@ 1. Modules\ripple_data\protocol - - 1. Modules\ripple_data\utility - 1. Modules\ripple_app\refactored\shamap @@ -1340,9 +1337,6 @@ 1. Modules\ripple_data\utility - - 1. Modules\ripple_data\utility - 1. Modules\ripple_app\refactored\shamap diff --git a/modules/ripple_data/ripple_data.cpp b/modules/ripple_data/ripple_data.cpp index 0f5ebce4ad..8a8c37f618 100644 --- a/modules/ripple_data/ripple_data.cpp +++ b/modules/ripple_data/ripple_data.cpp @@ -88,8 +88,6 @@ static const uint64 tenTo17m1 = tenTo17 - 1; #include "protocol/ripple_STAmount.cpp" #include "protocol/ripple_STAmountRound.cpp" -#include "utility/ripple_JSONCache.cpp" - } // These must be outside the namespace because of boost diff --git a/modules/ripple_data/ripple_data.h b/modules/ripple_data/ripple_data.h index bc2a2e8a36..80851a40d5 100644 --- a/modules/ripple_data/ripple_data.h +++ b/modules/ripple_data/ripple_data.h @@ -53,7 +53,6 @@ namespace ripple #include "protocol/ripple_TxFormat.h" #include "protocol/ripple_TxFormats.h" -#include "utility/ripple_JSONCache.h" #include "utility/ripple_UptimeTimerAdapter.h" } diff --git a/modules/ripple_data/utility/ripple_JSONCache.cpp b/modules/ripple_data/utility/ripple_JSONCache.cpp deleted file mode 100644 index 1eaed909cb..0000000000 --- a/modules/ripple_data/utility/ripple_JSONCache.cpp +++ /dev/null @@ -1,186 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -JSONCache::Key::Key (int op, uint256 const& ledger, uint160 const& object, int lastUse) - : mLedger (ledger) - , mObject (object) - , mOperation (op) - , mLastUse (lastUse) -{ - mHash = static_cast (mOperation); - - mLedger.hash_combine (mHash); - - mObject.hash_combine (mHash); -} - -int JSONCache::Key::compare (Key const& other) const -{ - if (mHash < other.mHash) return -1; - - if (mHash > other.mHash) return 1; - - if (mOperation < other.mOperation) return -1; - - if (mOperation > other.mOperation) return 1; - - if (mLedger < other.mLedger) return -1; - - if (mLedger > other.mLedger) return 1; - - if (mObject < other.mObject) return -1; - - if (mObject > other.mObject) return 1; - - return 0; -} - -bool JSONCache::Key::operator< (Key const& rhs) const -{ - return compare (rhs) < 0; -} -bool JSONCache::Key::operator> (Key const& rhs) const -{ - return compare (rhs) > 0; -} -bool JSONCache::Key::operator<= (Key const& rhs) const -{ - return compare (rhs) <= 0; -} -bool JSONCache::Key::operator>= (Key const& rhs) const -{ - return compare (rhs) >= 0; -} -bool JSONCache::Key::operator!= (Key const& rhs) const -{ - return compare (rhs) != 0; -} -bool JSONCache::Key::operator== (Key const& rhs) const -{ - return compare (rhs) == 0; -} - -void JSONCache::Key::touch (Key const& key) const -{ - mLastUse = key.mLastUse; -} - -bool JSONCache::Key::isExpired (int expireTimeSeconds) const -{ - return mLastUse < expireTimeSeconds; -} - -std::size_t JSONCache::Key::getHash () const -{ - return mHash; -} - -//------------------------------------------------------------------------------ - -JSONCache::JSONCache (int expirationTimeInSeconds) - : m_expirationTime (expirationTimeInSeconds) - , mHits (0) - , mMisses (0) -{ -} - -//------------------------------------------------------------------------------ - -float JSONCache::getHitRate () -{ - boost::recursive_mutex::scoped_lock sl (m_lock); - - return (static_cast (mHits) * 100.f) / (1.0f + mHits + mMisses); -} - -//------------------------------------------------------------------------------ - -int JSONCache::getNumberOfEntries () -{ - boost::recursive_mutex::scoped_lock sl (m_lock); - - return m_cache.size (); -} - -//------------------------------------------------------------------------------ - -JSONCache::data_t JSONCache::getEntry (Kind kind, LedgerHash const& ledger, uint160 const& object) -{ - JSONCache::data_t result; // default constructor indicates not found - - Key key (kind, ledger, object, getUptime ()); - - { - boost::recursive_mutex::scoped_lock sl (m_lock); - - boost::unordered_map ::iterator it = m_cache.find (key); - - if (it != m_cache.end ()) - { - ++mHits; - - it->first.touch (key); - - result = it->second; - } - else - { - ++mMisses; - } - } - - return result; -} - -//------------------------------------------------------------------------------ - -void JSONCache::storeEntry (Kind kind, uint256 const& ledger, uint160 const& object, data_t const& data) -{ - Key key (kind, ledger, object, getUptime ()); - - { - boost::recursive_mutex::scoped_lock sl (m_lock); - - m_cache.insert (std::pair (key, data)); - } -} - -//------------------------------------------------------------------------------ - -void JSONCache::sweep () -{ - int sweepTime = getUptime (); - - if (sweepTime >= m_expirationTime) - { - sweepTime -= m_expirationTime; - - { - boost::recursive_mutex::scoped_lock sl (m_lock); - - boost::unordered_map ::iterator it = m_cache.begin (); - - while (it != m_cache.end ()) - { - if (it->first.isExpired (sweepTime)) - { - it = m_cache.erase (it); - } - else - { - ++it; - } - } - } - } -} - -//------------------------------------------------------------------------------ - -int JSONCache::getUptime () const -{ - return UptimeTimer::getInstance ().getElapsedSeconds (); -} diff --git a/modules/ripple_data/utility/ripple_JSONCache.h b/modules/ripple_data/utility/ripple_JSONCache.h deleted file mode 100644 index b86bdc150e..0000000000 --- a/modules/ripple_data/utility/ripple_JSONCache.h +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -#ifndef RIPPLE_JSCONCACHE_H -#define RIPPLE_JSCONCACHE_H - -/** A simple cache for JSON. - - @note All member functions are thread-safe. -*/ -class JSONCache -{ -public: - class Key - { - public: - Key (int op, const uint256& ledger, const uint160& object, int lastUse); - int compare (const Key& k) const; - bool operator< (const Key& k) const; - bool operator> (const Key& k) const; - bool operator<= (const Key& k) const; - bool operator>= (const Key& k) const; - bool operator!= (const Key& k) const; - bool operator== (const Key& k) const; - - void touch (Key const& key) const; - bool isExpired (int expireTime) const; - - std::size_t getHash () const; - - private: - uint256 mLedger; - uint160 mObject; - int mOperation; - mutable int mLastUse; - std::size_t mHash; - }; - -public: - typedef boost::shared_ptr data_t; - -public: - enum Kind - { - kindLines, - kindOffers - }; - - /** Construct the cache. - - @param expirationTimeInSeconds The time until cached items expire, in seconds. - */ - explicit JSONCache (int expirationTimeInSeconds); - - /** Return the fraction of cache hits. - */ - float getHitRate (); - - /** Return the number of cached items. - */ - int getNumberOfEntries (); - - /** Retrieve a cached item. - - @return The item, or a default constructed container if it was not found. - */ - data_t getEntry (Kind kind, LedgerHash const& ledger, uint160 const& object); - - /** Store an item in the cache. - */ - void storeEntry (Kind kind, LedgerHash const& ledger, uint160 const& object, data_t const& data); - - /** Purge expired items. - - This must be called periodically. - */ - void sweep (); - -private: - int getUptime () const; - -private: - int const m_expirationTime; - boost::unordered_map m_cache; - boost::recursive_mutex m_lock; - uint64 mHits; - uint64 mMisses; -}; - -inline std::size_t hash_value (JSONCache::Key const& key) -{ - return key.getHash (); -} - -#endif diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index cbdbcdd6c7..798658bbe5 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -23,7 +23,7 @@ NetworkOPs::NetworkOPs (boost::asio::io_service& io_service, LedgerMaster* pLedg mFeatureBlocked (false), mNetTimer (io_service), mLedgerMaster (pLedgerMaster), mCloseTimeOffset (0), mLastCloseProposers (0), mLastCloseConvergeTime (1000 * LEDGER_IDLE_INTERVAL), mLastCloseTime (0), mLastValidationTime (0), - mJSONCache (120), mFetchPack ("FetchPack", 2048, 20), mLastFetchPack (0), mFetchSeq (static_cast (-1)), + mFetchPack ("FetchPack", 2048, 20), mLastFetchPack (0), mFetchSeq (static_cast (-1)), mLastLoadBase (256), mLastLoadFactor (256) { } @@ -2219,7 +2219,6 @@ void NetworkOPs::makeFetchPack (Job&, boost::weak_ptr wPeer, void NetworkOPs::sweepFetchPack () { mFetchPack.sweep (); - mJSONCache.sweep (); } void NetworkOPs::addFetchPack (uint256 const& hash, boost::shared_ptr< Blob >& data) diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 329acbb35a..b86a0eef9d 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -225,28 +225,6 @@ public: int getFetchSize (); void sweepFetchPack (); - float getJSONHitRate () - { - return mJSONCache.getHitRate (); - } - - // VFALCO TODO Rename this to getNumberOfCachedJSONItems or something similar - int getJSONEntries () - { - return mJSONCache.getNumberOfEntries (); - } - - void storeJSONCache (JSONCache::Kind kind, const uint256& ledger, const uint160& object, - const boost::shared_ptr & data) - { - mJSONCache.storeEntry (kind, ledger, object, data); - } - - boost::shared_ptr getJSONCache (JSONCache::Kind kind, const uint256& ledger, const uint160& object) - { - return mJSONCache.getEntry (kind, ledger, object); - } - // network state machine void checkState (const boost::system::error_code& result); void switchLastClosedLedger (Ledger::pointer newLedger, bool duringConsensus); // Used for the "jump" case @@ -417,8 +395,6 @@ private: subMapType mSubTransactions; // all accepted transactions subMapType mSubRTTransactions; // all proposed and accepted transactions - JSONCache mJSONCache; - TaggedCache< uint256, Blob , UptimeTimerAdapter > mFetchPack; uint32 mLastFetchPack; uint32 mFetchSeq; diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 395fc71d3c..b5787c0a6a 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -2412,8 +2412,6 @@ Json::Value RPCHandler::doGetCounts (Json::Value params, LoadType* loadType, Sco ret["node_hit_rate"] = theApp->getHashedObjectStore ().getCacheHitRate (); ret["ledger_hit_rate"] = theApp->getLedgerMaster ().getCacheHitRate (); ret["AL_hit_rate"] = AcceptedLedger::getCacheHitRate (); - ret["JC_hit_rate"] = theApp->getOPs ().getJSONHitRate (); - ret["JC_size"] = theApp->getOPs ().getJSONEntries (); ret["fullbelow_size"] = SHAMap::getFullBelowSize ();