mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 23:15:52 +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));
|
return(sqlite3_column_int64(mCurrentStmt, colIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
int SqliteDatabase::getKBUsed()
|
int SqliteDatabase::getKBUsedAll()
|
||||||
{
|
{
|
||||||
return static_cast<int>(sqlite3_memory_used() / 1024);
|
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)
|
static int SqliteWALHook(void *s, sqlite3* dbCon, const char *dbName, int walSize)
|
||||||
{
|
{
|
||||||
(reinterpret_cast<SqliteDatabase*>(s))->doHook(dbName, walSize);
|
(reinterpret_cast<SqliteDatabase*>(s))->doHook(dbName, walSize);
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ public:
|
|||||||
void runWal();
|
void runWal();
|
||||||
void doHook(const char *db, int walSize);
|
void doHook(const char *db, int walSize);
|
||||||
|
|
||||||
int getKBUsed();
|
int getKBUsedDB();
|
||||||
|
int getKBUsedAll();
|
||||||
};
|
};
|
||||||
|
|
||||||
class SqliteStatement
|
class SqliteStatement
|
||||||
|
|||||||
@@ -89,7 +89,8 @@ public:
|
|||||||
|
|
||||||
virtual bool setupCheckpointing(JobQueue*) { return false; }
|
virtual bool setupCheckpointing(JobQueue*) { return false; }
|
||||||
virtual SqliteDatabase* getSqliteDB() { return NULL; }
|
virtual SqliteDatabase* getSqliteDB() { return NULL; }
|
||||||
virtual int getKBUsed() { return -1; }
|
virtual int getKBUsedAll() { return -1; }
|
||||||
|
virtual int getKBUsedDB() { return -1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,8 +24,11 @@ LogPartition TaggedCachePartition("TaggedCache");
|
|||||||
LogPartition AutoSocketPartition("AutoSocket");
|
LogPartition AutoSocketPartition("AutoSocket");
|
||||||
Application* theApp = NULL;
|
Application* theApp = NULL;
|
||||||
|
|
||||||
|
int DatabaseCon::sCount = 0;
|
||||||
|
|
||||||
DatabaseCon::DatabaseCon(const std::string& strName, const char *initStrings[], int initCount)
|
DatabaseCon::DatabaseCon(const std::string& strName, const char *initStrings[], int initCount)
|
||||||
{
|
{
|
||||||
|
++sCount;
|
||||||
boost::filesystem::path pPath = (theConfig.RUN_STANDALONE && (theConfig.START_UP != Config::LOAD))
|
boost::filesystem::path pPath = (theConfig.RUN_STANDALONE && (theConfig.START_UP != Config::LOAD))
|
||||||
? "" // Use temporary files.
|
? "" // Use temporary files.
|
||||||
: (theConfig.DATA_DIR / strName); // Use regular db 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.tune(theConfig.getSize(siLedgerSize), theConfig.getSize(siLedgerAge));
|
||||||
mLedgerMaster.setMinValidations(theConfig.VALIDATION_QUORUM);
|
mLedgerMaster.setMinValidations(theConfig.VALIDATION_QUORUM);
|
||||||
|
|
||||||
|
theApp->getHashNodeDB()->getDB()->executeSQL(boost::str(boost::format("PRAGMA cache_size=-%d;") %
|
||||||
|
(theConfig.getSize(siDBCache) * 1024)));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allow peer connections.
|
// Allow peer connections.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -36,12 +36,14 @@ class DatabaseCon
|
|||||||
protected:
|
protected:
|
||||||
Database* mDatabase;
|
Database* mDatabase;
|
||||||
boost::recursive_mutex mLock;
|
boost::recursive_mutex mLock;
|
||||||
|
static int sCount;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DatabaseCon(const std::string& name, const char *initString[], int countInit);
|
DatabaseCon(const std::string& name, const char *initString[], int countInit);
|
||||||
~DatabaseCon();
|
~DatabaseCon();
|
||||||
Database* getDB() { return mDatabase; }
|
Database* getDB() { return mDatabase; }
|
||||||
boost::recursive_mutex& getDBLock() { return mLock; }
|
boost::recursive_mutex& getDBLock() { return mLock; }
|
||||||
|
static int getCount() { return sCount; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Application
|
class Application
|
||||||
|
|||||||
@@ -486,7 +486,7 @@ void Config::load()
|
|||||||
|
|
||||||
int Config::getSize(SizedItemName item)
|
int Config::getSize(SizedItemName item)
|
||||||
{
|
{
|
||||||
SizedItem sizeTable[] = {
|
SizedItem sizeTable[] = { // tiny small medium large huge
|
||||||
{ siSweepInterval, { 10, 30, 60, 90, 90 } },
|
{ siSweepInterval, { 10, 30, 60, 90, 90 } },
|
||||||
{ siLedgerFetch, { 2, 2, 3, 4, 5 } },
|
{ siLedgerFetch, { 2, 2, 3, 4, 5 } },
|
||||||
{ siValidationsSize, { 256, 256, 512, 1024, 1024 } },
|
{ siValidationsSize, { 256, 256, 512, 1024, 1024 } },
|
||||||
@@ -496,7 +496,8 @@ int Config::getSize(SizedItemName item)
|
|||||||
{ siLedgerSize, { 32, 64, 128, 1024, 0 } },
|
{ siLedgerSize, { 32, 64, 128, 1024, 0 } },
|
||||||
{ siLedgerAge, { 30, 60, 120, 300, 600 } },
|
{ siLedgerAge, { 30, 60, 120, 300, 600 } },
|
||||||
{ siLineCacheSize, { 8192, 32768, 131072, 1048576, 0 } },
|
{ 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)
|
for (int i = 0; i < (sizeof(sizeTable) / sizeof(SizedItem)); ++i)
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ enum SizedItemName
|
|||||||
siLedgerAge,
|
siLedgerAge,
|
||||||
siLedgerFetch,
|
siLedgerFetch,
|
||||||
siLineCacheSize,
|
siLineCacheSize,
|
||||||
siLineCacheAge
|
siLineCacheAge,
|
||||||
|
siDBCache
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SizedItem
|
struct SizedItem
|
||||||
|
|||||||
@@ -2021,9 +2021,19 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest, int& cost)
|
|||||||
BOOST_FOREACH(InstanceType::InstanceCount& it, count)
|
BOOST_FOREACH(InstanceType::InstanceCount& it, count)
|
||||||
ret[it.first] = it.second;
|
ret[it.first] = it.second;
|
||||||
|
|
||||||
int dbKB = theApp->getLedgerDB()->getDB()->getKBUsed();
|
int dbKB = theApp->getLedgerDB()->getDB()->getKBUsedAll();
|
||||||
if (dbKB > 0)
|
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;
|
std::string uptime;
|
||||||
int s = upTime();
|
int s = upTime();
|
||||||
|
|||||||
Reference in New Issue
Block a user