diff --git a/src/cpp/database/SqliteDatabase.cpp b/src/cpp/database/SqliteDatabase.cpp index aa3195daf8..4bb0850bf7 100644 --- a/src/cpp/database/SqliteDatabase.cpp +++ b/src/cpp/database/SqliteDatabase.cpp @@ -196,11 +196,18 @@ uint64 SqliteDatabase::getBigInt(int colIndex) return(sqlite3_column_int64(mCurrentStmt, colIndex)); } -int SqliteDatabase::getKBUsed() +int SqliteDatabase::getKBUsedAll() { return static_cast(sqlite3_memory_used() / 1024); } +int SqliteDatabase::getKBUsedDB() +{ + int cur = 0, hiw = 0; + sqlite3_db_status(mConnection, SQLITE_DBSTATUS_CACHE_USED, &cur, &hiw, 0); + return cur / 1024; +} + static int SqliteWALHook(void *s, sqlite3* dbCon, const char *dbName, int walSize) { (reinterpret_cast(s))->doHook(dbName, walSize); diff --git a/src/cpp/database/SqliteDatabase.h b/src/cpp/database/SqliteDatabase.h index 2cd9896139..ed2d829457 100644 --- a/src/cpp/database/SqliteDatabase.h +++ b/src/cpp/database/SqliteDatabase.h @@ -58,7 +58,8 @@ public: void runWal(); void doHook(const char *db, int walSize); - int getKBUsed(); + int getKBUsedDB(); + int getKBUsedAll(); }; class SqliteStatement diff --git a/src/cpp/database/database.h b/src/cpp/database/database.h index 579ed2929d..dca77106e5 100644 --- a/src/cpp/database/database.h +++ b/src/cpp/database/database.h @@ -89,7 +89,8 @@ public: virtual bool setupCheckpointing(JobQueue*) { return false; } virtual SqliteDatabase* getSqliteDB() { return NULL; } - virtual int getKBUsed() { return -1; } + virtual int getKBUsedAll() { return -1; } + virtual int getKBUsedDB() { return -1; } }; #endif diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index a9ff4ce797..e60851520c 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -24,8 +24,11 @@ LogPartition TaggedCachePartition("TaggedCache"); LogPartition AutoSocketPartition("AutoSocket"); Application* theApp = NULL; +int DatabaseCon::sCount = 0; + DatabaseCon::DatabaseCon(const std::string& strName, const char *initStrings[], int initCount) { + ++sCount; boost::filesystem::path pPath = (theConfig.RUN_STANDALONE && (theConfig.START_UP != Config::LOAD)) ? "" // Use temporary files. : (theConfig.DATA_DIR / strName); // Use regular db files. @@ -172,6 +175,9 @@ void Application::setup() mLedgerMaster.tune(theConfig.getSize(siLedgerSize), theConfig.getSize(siLedgerAge)); mLedgerMaster.setMinValidations(theConfig.VALIDATION_QUORUM); + theApp->getHashNodeDB()->getDB()->executeSQL(boost::str(boost::format("PRAGMA cache_size=-%d;") % + (theConfig.getSize(siDBCache) * 1024))); + // // Allow peer connections. // diff --git a/src/cpp/ripple/Application.h b/src/cpp/ripple/Application.h index 48e58d97af..a467202665 100644 --- a/src/cpp/ripple/Application.h +++ b/src/cpp/ripple/Application.h @@ -36,12 +36,14 @@ class DatabaseCon protected: Database* mDatabase; boost::recursive_mutex mLock; + static int sCount; public: DatabaseCon(const std::string& name, const char *initString[], int countInit); ~DatabaseCon(); - Database* getDB() { return mDatabase; } - boost::recursive_mutex& getDBLock() { return mLock; } + Database* getDB() { return mDatabase; } + boost::recursive_mutex& getDBLock() { return mLock; } + static int getCount() { return sCount; } }; class Application diff --git a/src/cpp/ripple/Config.cpp b/src/cpp/ripple/Config.cpp index 8d7abeb317..f5cbd6d8e5 100644 --- a/src/cpp/ripple/Config.cpp +++ b/src/cpp/ripple/Config.cpp @@ -486,7 +486,7 @@ void Config::load() int Config::getSize(SizedItemName item) { - SizedItem sizeTable[] = { + SizedItem sizeTable[] = { // tiny small medium large huge { siSweepInterval, { 10, 30, 60, 90, 90 } }, { siLedgerFetch, { 2, 2, 3, 4, 5 } }, { siValidationsSize, { 256, 256, 512, 1024, 1024 } }, @@ -496,7 +496,8 @@ int Config::getSize(SizedItemName item) { siLedgerSize, { 32, 64, 128, 1024, 0 } }, { siLedgerAge, { 30, 60, 120, 300, 600 } }, { siLineCacheSize, { 8192, 32768, 131072, 1048576, 0 } }, - { siLineCacheAge, { 500, 600, 1800, 3600, 7200 } } + { siLineCacheAge, { 500, 600, 1800, 3600, 7200 } }, + { siDBCache, { 8, 12, 24, 64, 96 } }, }; for (int i = 0; i < (sizeof(sizeTable) / sizeof(SizedItem)); ++i) diff --git a/src/cpp/ripple/Config.h b/src/cpp/ripple/Config.h index 7d1a420c8b..6dd0fe3893 100644 --- a/src/cpp/ripple/Config.h +++ b/src/cpp/ripple/Config.h @@ -64,7 +64,8 @@ enum SizedItemName siLedgerAge, siLedgerFetch, siLineCacheSize, - siLineCacheAge + siLineCacheAge, + siDBCache }; struct SizedItem diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index d642e05e40..cc0a84f7ee 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -2021,9 +2021,19 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest, int& cost) BOOST_FOREACH(InstanceType::InstanceCount& it, count) ret[it.first] = it.second; - int dbKB = theApp->getLedgerDB()->getDB()->getKBUsed(); + int dbKB = theApp->getLedgerDB()->getDB()->getKBUsedAll(); if (dbKB > 0) - ret["dbKB"] = dbKB; + ret["dbKBTotal"] = dbKB; + + dbKB = theApp->getLedgerDB()->getDB()->getKBUsedDB(); + if (dbKB > 0) + ret["dbKBLedger"] = dbKB; + dbKB = theApp->getHashNodeDB()->getDB()->getKBUsedDB(); + if (dbKB > 0) + ret["dbKBHashNode"] = dbKB; + dbKB = theApp->getTxnDB()->getDB()->getKBUsedDB(); + if (dbKB > 0) + ret["dbKBTransaction"] = dbKB; std::string uptime; int s = upTime();