mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Enlarge the SQLite database cache intelligently.
This commit is contained in:
@@ -196,11 +196,18 @@ uint64 SqliteDatabase::getBigInt(int colIndex)
|
||||
return(sqlite3_column_int64(mCurrentStmt, colIndex));
|
||||
}
|
||||
|
||||
int SqliteDatabase::getKBUsed()
|
||||
int SqliteDatabase::getKBUsedAll()
|
||||
{
|
||||
return static_cast<int>(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<SqliteDatabase*>(s))->doHook(dbName, walSize);
|
||||
|
||||
@@ -58,7 +58,8 @@ public:
|
||||
void runWal();
|
||||
void doHook(const char *db, int walSize);
|
||||
|
||||
int getKBUsed();
|
||||
int getKBUsedDB();
|
||||
int getKBUsedAll();
|
||||
};
|
||||
|
||||
class SqliteStatement
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -64,7 +64,8 @@ enum SizedItemName
|
||||
siLedgerAge,
|
||||
siLedgerFetch,
|
||||
siLineCacheSize,
|
||||
siLineCacheAge
|
||||
siLineCacheAge,
|
||||
siDBCache
|
||||
};
|
||||
|
||||
struct SizedItem
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user