mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 19:45:53 +00:00
JSON cache for account offers and account lines.
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "src/cpp/ripple/ripple_InfoSub.h"
|
||||
|
||||
// Order and indentation reflect the hierarchy of dependencies
|
||||
#include "src/cpp/ripple/JSONCache.h"
|
||||
#include "src/cpp/ripple/ripple_HashedObject.h"
|
||||
#include "src/cpp/ripple/ripple_SHAMapItem.h"
|
||||
#include "src/cpp/ripple/ripple_SHAMapNode.h"
|
||||
|
||||
@@ -185,6 +185,7 @@
|
||||
#include "src/cpp/ripple/LedgerEntrySet.h"
|
||||
#include "src/cpp/ripple/TransactionEngine.h"
|
||||
#include "src/cpp/ripple/ripple_CanonicalTXSet.h"
|
||||
#include "src/cpp/ripple/JSONCache.h"
|
||||
|
||||
#include "src/cpp/ripple/ripple_LedgerHistory.h"
|
||||
#include "src/cpp/ripple/LedgerMaster.h"
|
||||
|
||||
@@ -17,7 +17,7 @@ NetworkOPs::NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedge
|
||||
mFeatureBlocked(false),
|
||||
mNetTimer(io_service), mLedgerMaster(pLedgerMaster), mCloseTimeOffset(0), mLastCloseProposers(0),
|
||||
mLastCloseConvergeTime(1000 * LEDGER_IDLE_INTERVAL), mLastCloseTime(0), mLastValidationTime(0),
|
||||
mFetchPack("FetchPack", 2048, 20), mLastFetchPack(0), mFetchSeq(static_cast<uint32>(-1)),
|
||||
mJSONCache(120), mFetchPack("FetchPack", 2048, 20), mLastFetchPack(0), mFetchSeq(static_cast<uint32>(-1)),
|
||||
mLastLoadBase(256), mLastLoadFactor(256)
|
||||
{
|
||||
}
|
||||
@@ -2074,6 +2074,7 @@ 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)
|
||||
|
||||
@@ -176,6 +176,16 @@ public:
|
||||
int getFetchSize();
|
||||
void sweepFetchPack();
|
||||
|
||||
float getJSONHitRate() { return mJSONCache.getHitRate(); }
|
||||
int getJSONEntries() { return mJSONCache.getCount(); }
|
||||
|
||||
void storeJSONCache(int operation, const uint256& ledger, const uint160& object,
|
||||
const boost::shared_ptr<Json::Value>& data)
|
||||
{ mJSONCache.storeEntry(operation, ledger, object, data); }
|
||||
|
||||
boost::shared_ptr<Json::Value> getJSONCache(int operation, const uint256& ledger, const uint160& object)
|
||||
{ return mJSONCache.getEntry(operation, 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
|
||||
@@ -303,6 +313,8 @@ private:
|
||||
subMapType mSubTransactions; // all accepted transactions
|
||||
subMapType mSubRTTransactions; // all proposed and accepted transactions
|
||||
|
||||
JSONCache<UptimeTimerAdapter> mJSONCache;
|
||||
|
||||
TaggedCache< uint256, Blob , UptimeTimerAdapter > mFetchPack;
|
||||
uint32 mLastFetchPack;
|
||||
uint32 mFetchSeq;
|
||||
|
||||
@@ -1049,8 +1049,12 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
bool bUnlocked = false;
|
||||
if (lpLedger->isImmutable())
|
||||
{
|
||||
MasterLockHolder.unlock();
|
||||
bUnlocked = true;
|
||||
}
|
||||
|
||||
if (!jvRequest.isMember("account"))
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
@@ -1088,9 +1092,16 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL
|
||||
{
|
||||
jvResult["account"] = raAccount.humanAccountID();
|
||||
|
||||
boost::shared_ptr<Json::Value> jvsLines =
|
||||
theApp->getOPs().getJSONCache(JC_OP_ACCOUNT_LINES, lpLedger->getHash(), raAccount.getAccountID());
|
||||
|
||||
if (!jvsLines)
|
||||
{
|
||||
jvsLines = boost::make_shared<Json::Value>(Json::arrayValue);
|
||||
Json::Value& jsonLines = *jvsLines;
|
||||
|
||||
AccountItems rippleLines(raAccount.getAccountID(), lpLedger, AccountItem::pointer(new RippleState()));
|
||||
|
||||
Json::Value& jsonLines = (jvResult["lines"] = Json::arrayValue);
|
||||
BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems())
|
||||
{
|
||||
RippleState* line=(RippleState*)item.get();
|
||||
@@ -1114,6 +1125,14 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL
|
||||
jPeer["quality_out"] = static_cast<Json::UInt>(line->getQualityOut());
|
||||
}
|
||||
}
|
||||
|
||||
theApp->getOPs().storeJSONCache(JC_OP_ACCOUNT_LINES, lpLedger->getHash(),
|
||||
raAccount.getAccountID(), jvsLines);
|
||||
}
|
||||
if (!bUnlocked)
|
||||
MasterLockHolder.unlock();
|
||||
|
||||
jvResult["lines"] = *jvsLines;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1149,8 +1168,12 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest, int& cost, Scoped
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
bool bUnlocked = false;
|
||||
if (lpLedger->isImmutable())
|
||||
{
|
||||
MasterLockHolder.unlock();
|
||||
bUnlocked = true;
|
||||
}
|
||||
|
||||
if (!jvRequest.isMember("account"))
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
@@ -1172,11 +1195,22 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest, int& cost, Scoped
|
||||
if (bIndex)
|
||||
jvResult["account_index"] = iIndex;
|
||||
|
||||
if (lpLedger->hasAccount(raAccount))
|
||||
lpLedger->visitAccountItems(raAccount.getAccountID(),
|
||||
BIND_TYPE(&offerAdder, boost::ref(jvResult["offers"] = Json::arrayValue), P_1));
|
||||
else
|
||||
jvResult = rpcError(rpcACT_NOT_FOUND);
|
||||
if (!lpLedger->hasAccount(raAccount))
|
||||
return rpcError(rpcACT_NOT_FOUND);
|
||||
|
||||
boost::shared_ptr<Json::Value> jvsOffers =
|
||||
theApp->getOPs().getJSONCache(JC_OP_ACCOUNT_OFFERS, lpLedger->getHash(), raAccount.getAccountID());
|
||||
|
||||
if (!jvsOffers)
|
||||
{
|
||||
jvsOffers = boost::make_shared<Json::Value>(Json::arrayValue);
|
||||
lpLedger->visitAccountItems(raAccount.getAccountID(), BIND_TYPE(&offerAdder, boost::ref(*jvsOffers), P_1));
|
||||
theApp->getOPs().storeJSONCache(JC_OP_ACCOUNT_OFFERS, lpLedger->getHash(), raAccount.getAccountID(), jvsOffers);
|
||||
}
|
||||
if (!bUnlocked)
|
||||
MasterLockHolder.unlock();
|
||||
|
||||
jvResult["offers"] = *jvsOffers;
|
||||
|
||||
return jvResult;
|
||||
}
|
||||
@@ -2343,6 +2377,8 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest, int& cost, ScopedLock
|
||||
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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user