Report the number of "backed up" node writes in get_counts.

This commit is contained in:
JoelKatz
2013-05-14 10:31:26 -07:00
parent 7855c4d642
commit 794469fddb
3 changed files with 16 additions and 1 deletions

View File

@@ -19,7 +19,7 @@ DECLARE_INSTANCE(HashedObject);
HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) :
mCache("HashedObjectStore", cacheSize, cacheAge), mNegativeCache("HashedObjectNegativeCache", 0, 120),
mWriteGeneration(0), mWritePending(false), mLevelDB(false)
mWriteGeneration(0), mWriteLoad(0), mWritePending(false), mLevelDB(false)
{
mWriteSet.reserve(128);
@@ -56,6 +56,12 @@ void HashedObjectStore::waitWrite()
mWriteCondition.wait(sl);
}
int HashedObjectStore::getWriteLoad()
{
boost::mutex::scoped_lock sl(mWriteMutex);
return std::max(mWriteLoad, static_cast<int>(mWriteSet.size()));
}
#ifdef USE_LEVELDB
bool HashedObjectStore::storeLevelDB(HashedObjectType type, uint32 index,
@@ -90,6 +96,7 @@ bool HashedObjectStore::storeLevelDB(HashedObjectType type, uint32 index,
void HashedObjectStore::bulkWriteLevelDB()
{
assert(mLevelDB);
int setSize = 0;
while (1)
{
std::vector< boost::shared_ptr<HashedObject> > set;
@@ -97,6 +104,7 @@ void HashedObjectStore::bulkWriteLevelDB()
{
boost::mutex::scoped_lock sl(mWriteMutex);
mWriteSet.swap(set);
assert(mWriteSet.empty());
++mWriteGeneration;
@@ -104,8 +112,11 @@ void HashedObjectStore::bulkWriteLevelDB()
if (set.empty())
{
mWritePending = false;
mWriteLoad = 0;
return;
}
mWriteLoad = std::max(setSize, static_cast<int>(mWriteSet.size()));
setSize = set.size();
}
{

View File

@@ -55,6 +55,7 @@ protected:
boost::mutex mWriteMutex;
boost::condition_variable mWriteCondition;
int mWriteGeneration;
int mWriteLoad;
std::vector< boost::shared_ptr<HashedObject> > mWriteSet;
bool mWritePending;
@@ -101,6 +102,7 @@ public:
void waitWrite();
void tune(int size, int age);
void sweep() { mCache.sweep(); mNegativeCache.sweep(); }
int getWriteLoad();
int import(const std::string& fileName);
};

View File

@@ -2317,6 +2317,8 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest, int& cost, ScopedLock
if (dbKB > 0)
ret["dbKBTransaction"] = dbKB;
ret["write_load"] = theApp->getHashedObjectStore().getWriteLoad();
std::string uptime;
int s = upTime();
textTime(uptime, s, "year", 365*24*60*60);