mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Load and latency monitoring class.
This will allow us to assess our load level.
This commit is contained in:
66
src/cpp/ripple/LoadMonitor.cpp
Normal file
66
src/cpp/ripple/LoadMonitor.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "LoadMonitor.h"
|
||||
|
||||
void LoadMonitor::LoadMonitor::update()
|
||||
{ // call with the mutex
|
||||
time_t now = time(NULL);
|
||||
|
||||
if (now == mLastUpdate) // current
|
||||
return;
|
||||
|
||||
if ((now < mLastUpdate) || (now > (mLastUpdate + 8)))
|
||||
{ // way out of date
|
||||
mCounts = 0;
|
||||
mLatencyEvents = 0;
|
||||
mLatencyMS = 0;
|
||||
mLastUpdate = now;
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{ // do exponential decay
|
||||
++mLastUpdate;
|
||||
mCounts -= (mCounts / 4);
|
||||
mLatencyEvents -= (mLatencyEvents / 4);
|
||||
mLatencyMS -= (mLatencyMS / 4);
|
||||
} while (mLastUpdate < now);
|
||||
}
|
||||
|
||||
void LoadMonitor::addCount(int counts)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
update();
|
||||
mCounts += counts;
|
||||
}
|
||||
|
||||
void LoadMonitor::addLatency(int latency)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
update();
|
||||
++mLatencyEvents;
|
||||
mLatencyMS += latency;
|
||||
}
|
||||
|
||||
void LoadMonitor::addCountAndLatency(int counts, int latency)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
update();
|
||||
mCounts += counts;
|
||||
++mLatencyEvents;
|
||||
mLatencyMS += latency;
|
||||
}
|
||||
|
||||
void LoadMonitor::getCountAndLatency(uint64& count, uint64& latency)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
update();
|
||||
|
||||
count = mCounts / 4;
|
||||
|
||||
if (mLatencyEvents == 0)
|
||||
latency = 0;
|
||||
else latency = mLatencyMS / (mLatencyEvents * 4);
|
||||
}
|
||||
Reference in New Issue
Block a user