From bdba947c42add7d4ea6750f574aad0c67c0416d8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 30 May 2013 12:54:40 -0700 Subject: [PATCH 1/4] Enlarge the immutable SLE cache. --- src/cpp/ripple/Config.cpp | 9 +++++++++ src/cpp/ripple/Config.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/cpp/ripple/Config.cpp b/src/cpp/ripple/Config.cpp index 6a0d3a488..b695650af 100644 --- a/src/cpp/ripple/Config.cpp +++ b/src/cpp/ripple/Config.cpp @@ -510,14 +510,23 @@ void Config::load() int Config::getSize(SizedItemName item) { SizedItem sizeTable[] = { // tiny small medium large huge + { siSweepInterval, { 10, 30, 60, 90, 120 } }, + { siLedgerFetch, { 2, 2, 3, 3, 3 } }, + { siValidationsSize, { 256, 256, 512, 1024, 1024 } }, { siValidationsAge, { 500, 500, 500, 500, 500 } }, + { siNodeCacheSize, { 8192, 65536, 262144, 2097152, 0 } }, { siNodeCacheAge, { 30, 60, 90, 300, 900 } }, + + { siSLECacheSize, { 4096, 8192, 16384, 65536, 0 } }, + { siSLECacheAge, { 30, 60, 90, 120, 300 } }, + { siLedgerSize, { 32, 128, 256, 2048, 0 } }, { siLedgerAge, { 30, 90, 180, 300, 900 } }, + { siHashNodeDBCache, { 4, 12, 24, 32, 64 } }, { siTxnDBCache, { 4, 12, 24, 32, 32 } }, { siLgrDBCache, { 4, 8, 16, 16, 16 } }, diff --git a/src/cpp/ripple/Config.h b/src/cpp/ripple/Config.h index 501d7aa52..581c7126e 100644 --- a/src/cpp/ripple/Config.h +++ b/src/cpp/ripple/Config.h @@ -56,6 +56,8 @@ enum SizedItemName siValidationsAge, siNodeCacheSize, siNodeCacheAge, + siSLECacheSize, + siSLECacheAge, siLedgerSize, siLedgerAge, siLedgerFetch, From 38abc08e1803c42c947a4728b8e7c3534de286ad Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 30 May 2013 13:07:38 -0700 Subject: [PATCH 2/4] Tune SLE cache size. --- src/cpp/ripple/Application.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index a2dcdf469..fe0664624 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -241,6 +241,9 @@ void Application::setup() mValidations.tune(theConfig.getSize(siValidationsSize), theConfig.getSize(siValidationsAge)); mHashedObjectStore.tune(theConfig.getSize(siNodeCacheSize), theConfig.getSize(siNodeCacheAge)); mLedgerMaster.tune(theConfig.getSize(siLedgerSize), theConfig.getSize(siLedgerAge)); + mSLECache.setTargetSize(theConfig.getSize(siSLECacheSize)); + mSLECache.setTargetAge(theConfig.getSize(siSLECacheAge)); + mLedgerMaster.setMinValidations(theConfig.VALIDATION_QUORUM); #ifdef USE_LEVELDB From fdea361dd743e60f224c5ccb7dca927c68c89c09 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 30 May 2013 13:07:53 -0700 Subject: [PATCH 3/4] Add 'visitAccountItems' function. --- src/cpp/ripple/Ledger.cpp | 25 +++++++++++++++++++++++++ src/cpp/ripple/Ledger.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index c2ea6aa91..227f350eb 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -1020,6 +1020,31 @@ SLE::pointer Ledger::getSLEi(const uint256& uId) return ret; } +void Ledger::visitAccountItems(const uint160& accountID, FUNCTION_TYPE func) +{ // Visit each item in this account's owner directory + uint256 rootIndex = Ledger::getOwnerDirIndex(accountID); + uint256 currentIndex = rootIndex; + + while (1) + { + SLE::pointer ownerDir = getSLEi(currentIndex); + if (!ownerDir || (ownerDir->getType() != ltDIR_NODE)) + return; + + BOOST_FOREACH(const uint256& uNode, ownerDir->getFieldV256(sfIndexes).peekValue()) + { + func(getSLEi(uNode)); + } + + uint64 uNodeNext = ownerDir->getFieldU64(sfIndexNext); + if (!uNodeNext) + return; + + currentIndex = Ledger::getDirNodeIndex(rootIndex, uNodeNext); + } + +} + uint256 Ledger::getFirstLedgerIndex() { SHAMapItem::pointer node = mAccountStateMap->peekFirstItem(); diff --git a/src/cpp/ripple/Ledger.h b/src/cpp/ripple/Ledger.h index 1c7e09c08..b7e3cf524 100644 --- a/src/cpp/ripple/Ledger.h +++ b/src/cpp/ripple/Ledger.h @@ -189,6 +189,7 @@ public: SLE::pointer getAccountRoot(const uint160& accountID); SLE::pointer getAccountRoot(const RippleAddress& naAccountID); void updateSkipList(); + void visitAccountItems(const uint160& acctID, FUNCTION_TYPE); // database functions (low-level) static Ledger::pointer loadByIndex(uint32 ledgerIndex); From ce3a8d9d7685e925e241c488cc9a5735bc0e1c28 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 30 May 2013 13:20:34 -0700 Subject: [PATCH 4/4] Use the new visitor code to reimplement account_offers. --- src/cpp/ripple/RPCHandler.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index e0ec6417d..67bc87269 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1101,6 +1101,17 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL return jvResult; } +static void offerAdder(Json::Value& jvLines, SLE::ref offer) +{ + if (offer->getType() == ltOFFER) + { + Json::Value& obj = jvLines.append(Json::objectValue); + offer->getFieldAmount(sfTakerPays).setJson(obj["taker_pays"]); + offer->getFieldAmount(sfTakerGets).setJson(obj["taker_gets"]); + obj["seq"] = offer->getFieldU32(sfSequence); + } +} + // { // account: || // account_index: // optional, defaults to 0. @@ -1139,26 +1150,10 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest, int& cost, Scoped jvResult["account_index"] = iIndex; if (lpLedger->hasAccount(raAccount)) - { - Json::Value& jsonLines = (jvResult["offers"] = Json::arrayValue); - - AccountItems offers(raAccount.getAccountID(), lpLedger, AccountItem::pointer(new Offer())); - BOOST_FOREACH(AccountItem::ref item, offers.getItems()) - { - Offer* offer=(Offer*)item.get(); - - Json::Value& obj = jsonLines.append(Json::objectValue); - - offer->getTakerPays().setJson(obj["taker_pays"]); - offer->getTakerGets().setJson(obj["taker_gets"]); - obj["seq"] = offer->getSeq(); - - } - } + lpLedger->visitAccountItems(raAccount.getAccountID(), + BIND_TYPE(&offerAdder, boost::ref(jvResult["offers"] = Json::arrayValue), P_1)); else - { jvResult = rpcError(rpcACT_NOT_FOUND); - } return jvResult; }