Remove the JSONCache. It was basically a failed experiment.

This commit is contained in:
JoelKatz
2013-06-28 16:07:32 -07:00
parent 27c761aa9c
commit ca4a2ad104
9 changed files with 1 additions and 327 deletions

View File

@@ -860,12 +860,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\ripple_data\ripple_data.cpp" />
<ClCompile Include="..\..\modules\ripple_data\utility\ripple_JSONCache.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\ripple_json\json\json_reader.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

View File

@@ -486,9 +486,6 @@
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializedObjectTemplate.cpp">
<Filter>1. Modules\ripple_data\protocol</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\ripple_data\utility\ripple_JSONCache.cpp">
<Filter>1. Modules\ripple_data\utility</Filter>
</ClCompile>
<ClCompile Include="..\..\src\cpp\ripple\ripple_SHAMapDelta.cpp">
<Filter>1. Modules\ripple_app\refactored\shamap</Filter>
</ClCompile>
@@ -1340,9 +1337,6 @@
<ClInclude Include="..\..\modules\ripple_data\utility\ripple_UptimeTimerAdapter.h">
<Filter>1. Modules\ripple_data\utility</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\ripple_data\utility\ripple_JSONCache.h">
<Filter>1. Modules\ripple_data\utility</Filter>
</ClInclude>
<ClInclude Include="..\..\src\cpp\ripple\ripple_SHAMapTreeNode.h">
<Filter>1. Modules\ripple_app\refactored\shamap</Filter>
</ClInclude>

View File

@@ -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

View File

@@ -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"
}

View File

@@ -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 <std::size_t> (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 <float> (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 <Key, data_t>::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_t> (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 <Key, data_t>::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 ();
}

View File

@@ -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 <Json::Value> 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 <Key, data_t> 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

View File

@@ -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<uint32> (-1)),
mFetchPack ("FetchPack", 2048, 20), mLastFetchPack (0), mFetchSeq (static_cast<uint32> (-1)),
mLastLoadBase (256), mLastLoadFactor (256)
{
}
@@ -2219,7 +2219,6 @@ void NetworkOPs::makeFetchPack (Job&, boost::weak_ptr<Peer> wPeer,
void NetworkOPs::sweepFetchPack ()
{
mFetchPack.sweep ();
mJSONCache.sweep ();
}
void NetworkOPs::addFetchPack (uint256 const& hash, boost::shared_ptr< Blob >& data)

View File

@@ -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 <Json::Value>& data)
{
mJSONCache.storeEntry (kind, ledger, object, data);
}
boost::shared_ptr<Json::Value> 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;

View File

@@ -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 ();